Skip to content

Commit b189a00

Browse files
feat: build for release
1 parent e5f2784 commit b189a00

File tree

10 files changed

+167
-121
lines changed

10 files changed

+167
-121
lines changed

build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"owner":"technote-space","repo":"release-github-actions","sha":"728a0936eef7b9c0c4edbfc4ec5014d3ad71348e","ref":"refs/tags/test/v6.2.4.367302177","tagName":"test/v6.2.4.367302177","branch":"gh-actions","tags":["test/v6.2.4.367302177","test/v6.2.4","test/v6.2","test/v6"],"updated_at":"2020-11-17T03:04:21.737Z"}
1+
{"owner":"technote-space","repo":"release-github-actions","sha":"fb16d65336423970c04b45070af8be85e3dc5e8a","ref":"refs/tags/test/v6.2.4.375570512","tagName":"test/v6.2.4.375570512","branch":"gh-actions","tags":["test/v6.2.4.375570512","test/v6.2.4","test/v6.2","test/v6"],"updated_at":"2020-11-21T03:03:57.995Z"}

lib/utils/command.js

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,21 @@ const path_1 = require("path");
1515
const github_action_helper_1 = require("@technote-space/github-action-helper");
1616
const github_action_log_helper_1 = require("@technote-space/github-action-log-helper");
1717
const misc_1 = require("./misc");
18-
exports.replaceDirectory = (context) => (message) => {
18+
const replaceDirectory = (context) => (message) => {
1919
const directories = misc_1.getReplaceDirectory(context);
2020
return Object.keys(directories).reduce((value, directory) => github_action_helper_1.Utils.replaceAll(github_action_helper_1.Utils.replaceAll(value, ` -C ${directory}`, ''), directory, directories[directory]), message);
2121
};
22-
exports.prepareFiles = (logger, helper, context) => __awaiter(void 0, void 0, void 0, function* () {
22+
exports.replaceDirectory = replaceDirectory;
23+
const prepareFiles = (logger, helper, context) => __awaiter(void 0, void 0, void 0, function* () {
2324
const { buildDir, pushDir } = misc_1.getParams(context);
2425
fs_1.mkdirSync(buildDir, { recursive: true });
2526
logger.startProcess('Cloning the remote repo for build...');
2627
yield helper.checkout(buildDir, context);
2728
logger.startProcess('Running build for release...');
2829
yield helper.runCommand(buildDir, misc_1.getBuildCommands(buildDir, pushDir));
2930
});
30-
exports.createBuildInfoFile = (logger, context) => __awaiter(void 0, void 0, void 0, function* () {
31+
exports.prepareFiles = prepareFiles;
32+
const createBuildInfoFile = (logger, context) => __awaiter(void 0, void 0, void 0, function* () {
3133
const filename = misc_1.getOutputBuildInfoFilename();
3234
if (!filename) {
3335
return;
@@ -50,14 +52,16 @@ exports.createBuildInfoFile = (logger, context) => __awaiter(void 0, void 0, voi
5052
'updated_at': (new Date).toISOString(),
5153
}));
5254
});
53-
exports.clone = (logger, helper, context) => __awaiter(void 0, void 0, void 0, function* () {
55+
exports.createBuildInfoFile = createBuildInfoFile;
56+
const clone = (logger, helper, context) => __awaiter(void 0, void 0, void 0, function* () {
5457
const { pushDir, branchName } = misc_1.getParams(context);
5558
logger.startProcess('Fetching...');
5659
yield helper.fetchOrigin(pushDir, context, ['--no-tags'], [github_action_helper_1.Utils.getRefspec(branchName)]);
5760
logger.startProcess('Switching branch to [%s]...', branchName);
5861
yield helper.switchBranch(pushDir, branchName);
5962
});
60-
exports.checkBranch = (clonedBranch, logger, helper, context) => __awaiter(void 0, void 0, void 0, function* () {
63+
exports.clone = clone;
64+
const checkBranch = (clonedBranch, logger, helper, context) => __awaiter(void 0, void 0, void 0, function* () {
6165
const { pushDir, branchName } = misc_1.getParams(context);
6266
if (branchName !== clonedBranch) {
6367
logger.info('remote branch %s not found.', branchName);
@@ -66,22 +70,26 @@ exports.checkBranch = (clonedBranch, logger, helper, context) => __awaiter(void
6670
yield helper.gitInit(pushDir, branchName);
6771
}
6872
});
69-
exports.config = (logger, helper, context) => __awaiter(void 0, void 0, void 0, function* () {
73+
exports.checkBranch = checkBranch;
74+
const config = (logger, helper, context) => __awaiter(void 0, void 0, void 0, function* () {
7075
const { pushDir } = misc_1.getParams(context);
7176
const name = misc_1.getCommitName();
7277
const email = misc_1.getCommitEmail();
7378
logger.startProcess('Configuring git committer to be %s <%s>...', name, email);
7479
yield helper.config(pushDir, name, email);
7580
});
76-
exports.commit = (helper, context) => __awaiter(void 0, void 0, void 0, function* () { return helper.commit(misc_1.getParams(context).pushDir, misc_1.getCommitMessage(), { allowEmpty: true }); });
77-
exports.getDeleteTestTag = (tagName, prefix, helper, context) => __awaiter(void 0, void 0, void 0, function* () {
81+
exports.config = config;
82+
const commit = (helper, context) => __awaiter(void 0, void 0, void 0, function* () { return helper.commit(misc_1.getParams(context).pushDir, misc_1.getCommitMessage(), { allowEmpty: true }); });
83+
exports.commit = commit;
84+
const getDeleteTestTag = (tagName, prefix, helper, context) => __awaiter(void 0, void 0, void 0, function* () {
7885
return (yield helper.getTags(misc_1.getParams(context).pushDir, { quiet: true }))
7986
.filter(tag => github_action_helper_1.Utils.getPrefixRegExp(prefix).test(tag))
8087
.map(tag => tag.replace(github_action_helper_1.Utils.getPrefixRegExp(prefix), ''))
8188
.filter(tag => github_action_helper_1.Utils.versionCompare(tag, tagName, false) < 0) // eslint-disable-line no-magic-numbers
8289
.map(tag => `${prefix}${tag}`);
8390
});
84-
exports.deleteTestTags = (helper, context) => __awaiter(void 0, void 0, void 0, function* () {
91+
exports.getDeleteTestTag = getDeleteTestTag;
92+
const deleteTestTags = (helper, context) => __awaiter(void 0, void 0, void 0, function* () {
8593
const { pushDir, tagName } = misc_1.getParams(context);
8694
if (!misc_1.isTestTag(tagName) && misc_1.isEnabledCleanTestTag()) {
8795
const prefixForTestTag = misc_1.getTestTagPrefix();
@@ -94,7 +102,8 @@ exports.deleteTestTags = (helper, context) => __awaiter(void 0, void 0, void 0,
94102
}
95103
}
96104
});
97-
exports.push = (logger, helper, context) => __awaiter(void 0, void 0, void 0, function* () {
105+
exports.deleteTestTags = deleteTestTags;
106+
const push = (logger, helper, context) => __awaiter(void 0, void 0, void 0, function* () {
98107
const { pushDir, branchName, tagName, branchNames } = misc_1.getParams(context);
99108
logger.startProcess('Pushing to %s@%s (tag: %s)...', github_action_helper_1.ContextHelper.getRepository(context), branchName, tagName);
100109
const prefixForOriginalTag = misc_1.getOriginalTagPrefix();
@@ -115,6 +124,7 @@ exports.push = (logger, helper, context) => __awaiter(void 0, void 0, void 0, fu
115124
yield helper.forcePush(pushDir, branch, context);
116125
}), Promise.resolve());
117126
});
127+
exports.push = push;
118128
const findRelease = (octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
119129
const { tagName } = misc_1.getParams(context);
120130
const releases = yield octokit.repos.listReleases({
@@ -123,7 +133,7 @@ const findRelease = (octokit, context) => __awaiter(void 0, void 0, void 0, func
123133
});
124134
return releases.data.find(release => release.tag_name === tagName);
125135
});
126-
exports.updateRelease = (release, logger, octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
136+
const updateRelease = (release, logger, octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
127137
if (!release || release.draft) {
128138
return;
129139
}
@@ -135,29 +145,32 @@ exports.updateRelease = (release, logger, octokit, context) => __awaiter(void 0,
135145
draft: false,
136146
});
137147
});
138-
exports.copyFiles = (logger, command, context) => __awaiter(void 0, void 0, void 0, function* () {
148+
exports.updateRelease = updateRelease;
149+
const copyFiles = (logger, command, context) => __awaiter(void 0, void 0, void 0, function* () {
139150
const { buildDir, pushDir } = misc_1.getParams(context);
140151
logger.startProcess('Copying %s contents to %s...', buildDir, pushDir);
141152
yield command.execAsync({
142153
command: 'rsync',
143154
args: ['-rl', '--exclude', '.git', '--delete', `${buildDir}/`, pushDir],
144155
});
145156
});
146-
exports.prepareCommit = (logger, command, helper, context) => __awaiter(void 0, void 0, void 0, function* () {
157+
exports.copyFiles = copyFiles;
158+
const prepareCommit = (logger, command, helper, context) => __awaiter(void 0, void 0, void 0, function* () {
147159
yield exports.clone(logger, helper, context);
148160
yield exports.checkBranch(yield helper.getCurrentBranchName(misc_1.getParams(context).pushDir), logger, helper, context);
149161
yield exports.prepareFiles(logger, helper, context);
150162
yield exports.createBuildInfoFile(logger, context);
151163
yield exports.copyFiles(logger, command, context);
152164
});
165+
exports.prepareCommit = prepareCommit;
153166
const executeCommit = (release, logger, helper, octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
154167
yield exports.config(logger, helper, context);
155168
yield exports.commit(helper, context);
156169
yield exports.push(logger, helper, context);
157170
yield exports.updateRelease(release, logger, octokit, context);
158171
return true;
159172
});
160-
exports.deploy = (octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
173+
const deploy = (octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
161174
const logger = new github_action_log_helper_1.Logger(exports.replaceDirectory(context));
162175
const command = new github_action_helper_1.Command(logger);
163176
const { branchName } = misc_1.getParams(context);
@@ -167,3 +180,4 @@ exports.deploy = (octokit, context) => __awaiter(void 0, void 0, void 0, functio
167180
yield exports.prepareCommit(logger, command, helper, context);
168181
yield executeCommit(release, logger, helper, octokit, context);
169182
});
183+
exports.deploy = deploy;

lib/utils/misc.js

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ const constant_1 = require("../constant");
1313
const getCleanTargets = () => github_action_helper_1.Utils.getArrayInput('CLEAN_TARGETS')
1414
.map(target => target.replace(/[\x00-\x1f\x80-\x9f]/, '').trim()) // eslint-disable-line no-control-regex
1515
.filter(target => target && !target.startsWith('/') && !target.includes('..'));
16-
exports.getSearchBuildCommandTargets = () => github_action_helper_1.Utils.getArrayInput('BUILD_COMMAND_TARGET', true);
17-
exports.detectBuildCommands = (dir, runCommand, commands) => {
16+
const getSearchBuildCommandTargets = () => github_action_helper_1.Utils.getArrayInput('BUILD_COMMAND_TARGET', true);
17+
exports.getSearchBuildCommandTargets = getSearchBuildCommandTargets;
18+
const detectBuildCommands = (dir, runCommand, commands) => {
1819
const packageFile = path_1.resolve(dir, 'package.json');
1920
if (!fs_1.existsSync(packageFile)) {
2021
return [];
@@ -33,7 +34,8 @@ exports.detectBuildCommands = (dir, runCommand, commands) => {
3334
// eslint-disable-next-line no-magic-numbers
3435
return github_action_helper_1.Utils.getBoolValue(core_1.getInput('ALLOW_MULTIPLE_BUILD_COMMANDS')) ? targets : targets.slice(0, 1);
3536
};
36-
exports.getBackupCommands = (buildDir, pushDir) => [
37+
exports.detectBuildCommands = detectBuildCommands;
38+
const getBackupCommands = (buildDir, pushDir) => [
3739
{
3840
command: 'mv',
3941
args: ['-f', path_1.resolve(buildDir, 'action.yaml'), path_1.resolve(pushDir, 'action.yml')],
@@ -47,15 +49,17 @@ exports.getBackupCommands = (buildDir, pushDir) => [
4749
quiet: true,
4850
},
4951
];
50-
exports.getRestoreBackupCommands = (buildDir, pushDir) => [
52+
exports.getBackupCommands = getBackupCommands;
53+
const getRestoreBackupCommands = (buildDir, pushDir) => [
5154
{
5255
command: 'mv',
5356
args: ['-f', path_1.resolve(pushDir, 'action.yml'), path_1.resolve(buildDir, 'action.yml')],
5457
suppressError: true,
5558
quiet: true,
5659
},
5760
];
58-
exports.getClearFilesCommands = (targets) => {
61+
exports.getRestoreBackupCommands = getRestoreBackupCommands;
62+
const getClearFilesCommands = (targets) => {
5963
const commands = [];
6064
const searchValues = '?<>:|"\'@#$%^& ;';
6165
const replaceValue = '$1\\$2';
@@ -74,7 +78,8 @@ exports.getClearFilesCommands = (targets) => {
7478
}
7579
return commands;
7680
};
77-
exports.getBuildCommands = (buildDir, pushDir) => {
81+
exports.getClearFilesCommands = getClearFilesCommands;
82+
const getBuildCommands = (buildDir, pushDir) => {
7883
const commands = github_action_helper_1.Utils.getArrayInput('BUILD_COMMAND', false, '&&').map(command => command.replace(/\s{2,}/g, ' '));
7984
const pkgManager = github_action_helper_1.Utils.useNpm(buildDir, core_1.getInput('PACKAGE_MANAGER')) ? 'npm' : 'yarn';
8085
const runSubCommand = pkgManager === 'npm' ? ' run ' : ' ';
@@ -100,41 +105,60 @@ exports.getBuildCommands = (buildDir, pushDir) => {
100105
...exports.getRestoreBackupCommands(buildDir, pushDir),
101106
];
102107
};
103-
exports.getCommitMessage = () => core_1.getInput('COMMIT_MESSAGE', { required: true });
104-
exports.getCommitName = () => core_1.getInput('COMMIT_NAME', { required: true });
105-
exports.getCommitEmail = () => core_1.getInput('COMMIT_EMAIL', { required: true });
106-
exports.getBranchNames = () => github_action_helper_1.Utils.getArrayInput('BRANCH_NAME', true);
107-
exports.getFetchDepth = () => {
108+
exports.getBuildCommands = getBuildCommands;
109+
const getCommitMessage = () => core_1.getInput('COMMIT_MESSAGE', { required: true });
110+
exports.getCommitMessage = getCommitMessage;
111+
const getCommitName = () => core_1.getInput('COMMIT_NAME', { required: true });
112+
exports.getCommitName = getCommitName;
113+
const getCommitEmail = () => core_1.getInput('COMMIT_EMAIL', { required: true });
114+
exports.getCommitEmail = getCommitEmail;
115+
const getBranchNames = () => github_action_helper_1.Utils.getArrayInput('BRANCH_NAME', true);
116+
exports.getBranchNames = getBranchNames;
117+
const getFetchDepth = () => {
108118
const depth = core_1.getInput('FETCH_DEPTH');
109119
if (depth && /^\d+$/.test(depth)) {
110120
return parseInt(depth, 10);
111121
}
112122
return constant_1.DEFAULT_FETCH_DEPTH;
113123
};
114-
exports.getTestTagPrefix = () => core_1.getInput('TEST_TAG_PREFIX');
124+
exports.getFetchDepth = getFetchDepth;
125+
const getTestTagPrefix = () => core_1.getInput('TEST_TAG_PREFIX');
126+
exports.getTestTagPrefix = getTestTagPrefix;
115127
const getTestTagPrefixRegExp = () => github_action_helper_1.Utils.getPrefixRegExp(exports.getTestTagPrefix());
116-
exports.isTestTag = (tagName) => !!exports.getTestTagPrefix() && getTestTagPrefixRegExp().test(tagName);
117-
exports.getTestTag = (tagName) => tagName.replace(getTestTagPrefixRegExp(), '');
118-
exports.getOriginalTagPrefix = () => core_1.getInput('ORIGINAL_TAG_PREFIX');
119-
exports.isCreateMajorVersionTag = () => github_action_helper_1.Utils.getBoolValue(core_1.getInput('CREATE_MAJOR_VERSION_TAG'));
120-
exports.isCreateMinorVersionTag = () => github_action_helper_1.Utils.getBoolValue(core_1.getInput('CREATE_MINOR_VERSION_TAG'));
121-
exports.isCreatePatchVersionTag = () => github_action_helper_1.Utils.getBoolValue(core_1.getInput('CREATE_PATCH_VERSION_TAG'));
122-
exports.isEnabledCleanTestTag = () => github_action_helper_1.Utils.getBoolValue(core_1.getInput('CLEAN_TEST_TAG'));
123-
exports.getOutputBuildInfoFilename = () => {
128+
const isTestTag = (tagName) => !!exports.getTestTagPrefix() && getTestTagPrefixRegExp().test(tagName);
129+
exports.isTestTag = isTestTag;
130+
const getTestTag = (tagName) => tagName.replace(getTestTagPrefixRegExp(), '');
131+
exports.getTestTag = getTestTag;
132+
const getOriginalTagPrefix = () => core_1.getInput('ORIGINAL_TAG_PREFIX');
133+
exports.getOriginalTagPrefix = getOriginalTagPrefix;
134+
const isCreateMajorVersionTag = () => github_action_helper_1.Utils.getBoolValue(core_1.getInput('CREATE_MAJOR_VERSION_TAG'));
135+
exports.isCreateMajorVersionTag = isCreateMajorVersionTag;
136+
const isCreateMinorVersionTag = () => github_action_helper_1.Utils.getBoolValue(core_1.getInput('CREATE_MINOR_VERSION_TAG'));
137+
exports.isCreateMinorVersionTag = isCreateMinorVersionTag;
138+
const isCreatePatchVersionTag = () => github_action_helper_1.Utils.getBoolValue(core_1.getInput('CREATE_PATCH_VERSION_TAG'));
139+
exports.isCreatePatchVersionTag = isCreatePatchVersionTag;
140+
const isEnabledCleanTestTag = () => github_action_helper_1.Utils.getBoolValue(core_1.getInput('CLEAN_TEST_TAG'));
141+
exports.isEnabledCleanTestTag = isEnabledCleanTestTag;
142+
const getOutputBuildInfoFilename = () => {
124143
const filename = core_1.getInput('OUTPUT_BUILD_INFO_FILENAME');
125144
if (filename.startsWith('/') || filename.includes('..')) {
126145
return '';
127146
}
128147
return filename;
129148
};
149+
exports.getOutputBuildInfoFilename = getOutputBuildInfoFilename;
130150
// eslint-disable-next-line no-magic-numbers
131-
exports.getMajorTag = (tagName) => 'v' + github_action_helper_1.Utils.normalizeVersion(tagName, { slice: 1 });
151+
const getMajorTag = (tagName) => 'v' + github_action_helper_1.Utils.normalizeVersion(tagName, { slice: 1 });
152+
exports.getMajorTag = getMajorTag;
132153
// eslint-disable-next-line no-magic-numbers
133-
exports.getMinorTag = (tagName) => 'v' + github_action_helper_1.Utils.normalizeVersion(tagName, { slice: 2 });
154+
const getMinorTag = (tagName) => 'v' + github_action_helper_1.Utils.normalizeVersion(tagName, { slice: 2 });
155+
exports.getMinorTag = getMinorTag;
134156
// eslint-disable-next-line no-magic-numbers
135-
exports.getPatchTag = (tagName) => 'v' + github_action_helper_1.Utils.normalizeVersion(tagName, { slice: 3 });
136-
exports.isValidTagName = (tagName) => github_action_helper_1.Utils.isValidSemanticVersioning(tagName) || (exports.isTestTag(tagName) && github_action_helper_1.Utils.isValidSemanticVersioning(exports.getTestTag(tagName)));
137-
exports.getCreateTags = (tagName) => {
157+
const getPatchTag = (tagName) => 'v' + github_action_helper_1.Utils.normalizeVersion(tagName, { slice: 3 });
158+
exports.getPatchTag = getPatchTag;
159+
const isValidTagName = (tagName) => github_action_helper_1.Utils.isValidSemanticVersioning(tagName) || (exports.isTestTag(tagName) && github_action_helper_1.Utils.isValidSemanticVersioning(exports.getTestTag(tagName)));
160+
exports.isValidTagName = isValidTagName;
161+
const getCreateTags = (tagName) => {
138162
const settings = [
139163
{ condition: exports.isCreateMajorVersionTag, createTag: exports.getMajorTag },
140164
{ condition: exports.isCreateMinorVersionTag, createTag: exports.getMinorTag },
@@ -143,6 +167,7 @@ exports.getCreateTags = (tagName) => {
143167
const createTag = exports.isTestTag(tagName) ? (create) => exports.getTestTagPrefix() + create(exports.getTestTag(tagName)) : (create) => create(tagName);
144168
return github_action_helper_1.Utils.uniqueArray(settings.filter(setting => setting.condition()).map(setting => createTag(setting.createTag)).concat(tagName)).sort().reverse();
145169
};
170+
exports.getCreateTags = getCreateTags;
146171
const params = (context) => {
147172
const workDir = path_1.resolve(github_action_helper_1.Utils.getWorkspace(), '.work');
148173
const buildDir = path_1.resolve(workDir, 'build');
@@ -161,12 +186,14 @@ const params = (context) => {
161186
return { workDir, buildDir, pushDir, branchName, branchNames: branchNames.slice(1), tagName };
162187
};
163188
exports.getParams = memize_1.default(params);
164-
exports.getReplaceDirectory = (context) => {
189+
const getReplaceDirectory = (context) => {
165190
const { workDir, buildDir, pushDir } = exports.getParams(context);
166191
return {
167192
[buildDir]: '<Build Directory>',
168193
[pushDir]: '<Push Directory>',
169194
[workDir]: '<Working Directory>',
170195
};
171196
};
172-
exports.isValidContext = (context) => exports.isValidTagName(exports.getParams(context).tagName);
197+
exports.getReplaceDirectory = getReplaceDirectory;
198+
const isValidContext = (context) => exports.isValidTagName(exports.getParams(context).tagName);
199+
exports.isValidContext = isValidContext;

0 commit comments

Comments
 (0)