forked from cypress-io/cypress-example-todomvc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.js
53 lines (47 loc) · 1.66 KB
/
release.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const { exec, execSync } = require("child_process");
module.exports = async ({ github, context, core, tag }) => {
let newTagName = "";
console.log(tag);
const today = new Date().toISOString().split("T")[0];
execSync("git fetch --prune --tags");
exec("git tag --sort=committerdate | tail -1", async (error, stdout) => {
if (error) {
console.error(`exec error: ${JSON.stringify(error)}`);
return;
}
const latestVersion = stdout.trim();
const latestVersionItems = latestVersion.split("-");
const latestVersionDate = `${latestVersionItems[1]}-${latestVersionItems[2]}-${latestVersionItems[3]}`;
const latestVersionNum = parseInt(latestVersionItems[4]) + 1;
if (latestVersionDate === today) {
const newNum = parseInt(latestVersionItems[4]) + 1;
newTagName = `prod-${latestVersionDate}-${newNum}`;
} else {
newTagName = `prod-${today}-1`;
}
// creare ref
try {
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${newTagName}`,
sha: context.sha,
});
core.exportVariable("author", newTagName);
// // Create a release
// await github.rest.repos.createRelease({
// owner: context.repo.owner,
// repo: context.repo.repo,
// tag_name: newTagName,
// });
execSync(`git fetch && git checkout release`);
execSync(`git reset --hard ${newTagName}`);
execSync("git push -f");
} catch (error) {
execSync(`git push --delete origin ${newTagName}`);
console.error(error);
console.log(error);
process.exit(1);
}
});
};