Skip to content

Commit 2703104

Browse files
feat: Build for release
1 parent 0ed3c30 commit 2703104

File tree

4 files changed

+37
-27
lines changed

4 files changed

+37
-27
lines changed

build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"tagName":"test/v1.2.3.4","branch":"gh-actions","tags":["test/v1.2.3.4","test/v1","test/v1.2"],"updated_at":"2019-09-19T04:44:39.762Z"}
1+
{"tagName":"test/v1.2.3.5","branch":"gh-actions","tags":["test/v1.2.3.5","test/v1","test/v1.2"],"updated_at":"2019-09-19T05:06:48.837Z"}

lib/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ function run() {
3636
signale_1.default.complete('This is not target event.');
3737
return;
3838
}
39+
const directories = misc_1.getReplaceDirectory();
40+
Object.keys(directories).forEach(directory => signale_1.default.info('%s: %s', directories[directory], directory));
3941
yield command_1.deploy(new github_1.GitHub(core_1.getInput('GITHUB_TOKEN', { required: true })), github_1.context);
4042
}
4143
catch (error) {

lib/utils/command.js

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,9 @@ const signale = new signale_1.Signale({
3838
},
3939
},
4040
});
41-
const getParams = () => {
42-
const workDir = path_1.default.resolve(misc_1.getWorkspace(), '.work');
43-
const buildDir = path_1.default.resolve(workDir, 'build');
44-
const pushDir = path_1.default.resolve(workDir, 'push');
45-
const branchName = misc_1.getBranchName();
46-
return { workDir, buildDir, pushDir, branchName };
47-
};
4841
exports.replaceDirectory = (message) => {
49-
const { workDir, buildDir, pushDir } = getParams();
50-
return message.replace(buildDir, '<Build Directory>').replace(pushDir, '<Push Directory>').replace(workDir, '<Working Directory>');
42+
const directories = misc_1.getReplaceDirectory();
43+
return Object.keys(directories).reduce((value, directory) => value.replace(directory, directories[directory]), message);
5144
};
5245
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5346
const output = (type, message, ...args) => {
@@ -60,9 +53,9 @@ const note = (message, ...args) => output('process', `[${message}]`, ...args);
6053
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6154
const displayCommand = (message, ...args) => output('command', ` > ${message}`, ...args);
6255
// eslint-disable-next-line @typescript-eslint/no-explicit-any
63-
const displayStdout = (message) => message.replace(/\r?\n$/, '').split(/\r?\n/).forEach(line => output('command', ` >> ${line}`));
56+
const displayStdout = (message) => message.replace(/\r?\n$/, '').split(/\r?\n/).forEach(line => output('command', ` >> ${line}`));
6457
// eslint-disable-next-line @typescript-eslint/no-explicit-any
65-
const displayStderr = (message) => message.replace(/\r?\n$/, '').split(/\r?\n/).forEach(line => output('warn', ` >> ${line}`));
58+
const displayStderr = (message) => message.replace(/\r?\n$/, '').split(/\r?\n/).forEach(line => output('warn', ` >> ${line}`));
6659
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6760
const startProcess = (message, ...args) => {
6861
signale.log();
@@ -116,7 +109,7 @@ exports.execAsync = (args) => new Promise((resolve, reject) => {
116109
});
117110
const cloneForBuild = (context) => __awaiter(void 0, void 0, void 0, function* () {
118111
startProcess('Cloning the working commit from the remote repo for build');
119-
const { buildDir } = getParams();
112+
const { buildDir } = misc_1.getParams();
120113
const url = misc_1.getGitUrl(context);
121114
const depth = misc_1.getFetchDepth();
122115
yield exports.execAsync({ command: `git -C ${buildDir} clone --depth=${depth} ${url} .`, quiet: true, altCommand: `git clone --depth=${depth}` });
@@ -131,7 +124,7 @@ const runBuild = (buildDir) => __awaiter(void 0, void 0, void 0, function* () {
131124
});
132125
exports.prepareFiles = (context) => __awaiter(void 0, void 0, void 0, function* () {
133126
startProcess('Preparing files for release');
134-
const { buildDir } = getParams();
127+
const { buildDir } = misc_1.getParams();
135128
fs_1.default.mkdirSync(buildDir, { recursive: true });
136129
yield cloneForBuild(context);
137130
yield runBuild(buildDir);
@@ -141,7 +134,7 @@ exports.createBuildInfoFile = (context) => __awaiter(void 0, void 0, void 0, fun
141134
if (!filename) {
142135
return;
143136
}
144-
const { buildDir, branchName } = getParams();
137+
const { buildDir, branchName } = misc_1.getParams();
145138
const tagName = misc_1.getTagName(context);
146139
startProcess('Creating build info file');
147140
const filepath = path_1.default.resolve(buildDir, filename);
@@ -157,24 +150,24 @@ exports.createBuildInfoFile = (context) => __awaiter(void 0, void 0, void 0, fun
157150
}));
158151
});
159152
exports.getCurrentBranchName = () => __awaiter(void 0, void 0, void 0, function* () {
160-
const { pushDir } = getParams();
153+
const { pushDir } = misc_1.getParams();
161154
if (!fs_1.default.existsSync(path_1.default.resolve(pushDir, '.git'))) {
162155
return '';
163156
}
164157
return (yield exports.execAsync({ command: `git -C ${pushDir} branch -a | grep -E '^\\*' | cut -b 3-` })).trim();
165158
});
166159
const gitInit = () => __awaiter(void 0, void 0, void 0, function* () {
167-
const { pushDir } = getParams();
160+
const { pushDir } = misc_1.getParams();
168161
startProcess('Initializing local git repo');
169162
yield exports.execAsync({ command: `git -C ${pushDir} init .` });
170163
});
171164
const gitCheckout = () => __awaiter(void 0, void 0, void 0, function* () {
172-
const { pushDir, branchName } = getParams();
165+
const { pushDir, branchName } = misc_1.getParams();
173166
startProcess('Checking out orphan branch %s', branchName);
174167
yield exports.execAsync({ command: `git -C ${pushDir} checkout --orphan "${branchName}"` });
175168
});
176169
exports.cloneForBranch = (context) => __awaiter(void 0, void 0, void 0, function* () {
177-
const { pushDir, branchName } = getParams();
170+
const { pushDir, branchName } = misc_1.getParams();
178171
startProcess('Cloning the branch %s from the remote repo', branchName);
179172
const url = misc_1.getGitUrl(context);
180173
const depth = misc_1.getFetchDepth();
@@ -186,7 +179,7 @@ exports.cloneForBranch = (context) => __awaiter(void 0, void 0, void 0, function
186179
});
187180
});
188181
exports.checkBranch = (clonedBranch) => __awaiter(void 0, void 0, void 0, function* () {
189-
const { pushDir, branchName } = getParams();
182+
const { pushDir, branchName } = misc_1.getParams();
190183
if (branchName !== clonedBranch) {
191184
info('remote branch %s not found.', branchName);
192185
info('now branch: %s', clonedBranch);
@@ -197,23 +190,23 @@ exports.checkBranch = (clonedBranch) => __awaiter(void 0, void 0, void 0, functi
197190
}
198191
});
199192
exports.config = () => __awaiter(void 0, void 0, void 0, function* () {
200-
const { pushDir } = getParams();
193+
const { pushDir } = misc_1.getParams();
201194
const name = misc_1.getCommitName();
202195
const email = misc_1.getCommitEmail();
203196
startProcess('Configuring git committer to be %s <%s>', name, email);
204197
yield exports.execAsync({ command: `git -C ${pushDir} config user.name "${name}"` });
205198
yield exports.execAsync({ command: `git -C ${pushDir} config user.email "${email}"` });
206199
});
207200
const checkDiff = () => __awaiter(void 0, void 0, void 0, function* () {
208-
const { pushDir } = getParams();
201+
const { pushDir } = misc_1.getParams();
209202
return !!(yield exports.execAsync({
210203
command: `git -C ${pushDir} status --short -uno`,
211204
quiet: false,
212205
suppressOutput: true,
213206
})).split(/\r\n|\n/).filter(line => line.match(/^[MDA]\s+/)).length;
214207
});
215208
exports.commit = () => __awaiter(void 0, void 0, void 0, function* () {
216-
const { pushDir } = getParams();
209+
const { pushDir } = misc_1.getParams();
217210
const message = misc_1.getCommitMessage();
218211
yield exports.execAsync({ command: `git -C ${pushDir} add --all --force` });
219212
if (!(yield checkDiff())) {
@@ -225,7 +218,7 @@ exports.commit = () => __awaiter(void 0, void 0, void 0, function* () {
225218
return true;
226219
});
227220
exports.push = (context) => __awaiter(void 0, void 0, void 0, function* () {
228-
const { pushDir, branchName } = getParams();
221+
const { pushDir, branchName } = misc_1.getParams();
229222
const tagName = misc_1.getTagName(context);
230223
startProcess('Pushing to %s@%s (tag: %s)', misc_1.getRepository(context), branchName, tagName);
231224
const url = misc_1.getGitUrl(context);
@@ -280,12 +273,12 @@ exports.updateRelease = (release, octokit, context) => __awaiter(void 0, void 0,
280273
});
281274
});
282275
exports.copyFiles = () => __awaiter(void 0, void 0, void 0, function* () {
283-
const { buildDir, pushDir } = getParams();
276+
const { buildDir, pushDir } = misc_1.getParams();
284277
startProcess('Copying %s contents to %s', buildDir, pushDir);
285278
yield exports.execAsync({ command: `rsync -rl --exclude .git --delete "${buildDir}/" ${pushDir}` });
286279
});
287280
exports.prepareCommit = (context) => __awaiter(void 0, void 0, void 0, function* () {
288-
const { workDir, pushDir } = getParams();
281+
const { workDir, pushDir } = misc_1.getParams();
289282
yield exports.execAsync({ command: `rm -rdf ${workDir}` });
290283
fs_1.default.mkdirSync(pushDir, { recursive: true });
291284
yield exports.cloneForBranch(context);
@@ -304,7 +297,7 @@ const executeCommit = (release, octokit, context) => __awaiter(void 0, void 0, v
304297
return true;
305298
});
306299
exports.deploy = (octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
307-
const { branchName } = getParams();
300+
const { branchName } = misc_1.getParams();
308301
startProcess('Deploying branch %s to %s', branchName, misc_1.getRepository(context));
309302
const release = yield findRelease(octokit, context);
310303
yield exports.prepareCommit(context);

lib/utils/misc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,18 @@ exports.getCreateTags = (tagName) => {
136136
};
137137
exports.getWorkspace = () => process.env.GITHUB_WORKSPACE || '';
138138
exports.getTagName = (context) => exports.isRelease(context) ? context.payload.release.tag_name : context.ref.replace(/^refs\/tags\//, '');
139+
exports.getParams = () => {
140+
const workDir = path_1.default.resolve(exports.getWorkspace(), '.work');
141+
const buildDir = path_1.default.resolve(workDir, 'build');
142+
const pushDir = path_1.default.resolve(workDir, 'push');
143+
const branchName = exports.getBranchName();
144+
return { workDir, buildDir, pushDir, branchName };
145+
};
146+
exports.getReplaceDirectory = () => {
147+
const { workDir, buildDir, pushDir } = exports.getParams();
148+
return {
149+
[buildDir]: '<Build Directory>',
150+
[pushDir]: '<Push Directory>',
151+
[workDir]: '<Working Directory>',
152+
};
153+
};

0 commit comments

Comments
 (0)