This repository has been archived by the owner on May 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
87 lines (68 loc) · 2.63 KB
/
index.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const core = require("@actions/core");
const ops = require("./jsonOperations");
const ghUtilities = require("./utils");
const actions = require("./actions");
const actionType = core.getInput("action-type");
const token = core.getInput("github-token");
const sprint = core.getInput("sprint");
const releaseNotes = core.getInput("release-notes");
const prodBranch = core.getInput("prod-branch");
const repo = core.getInput("repo");
const gh = ghUtilities.getUtilities(repo, token);
const mergeBranch = async (choreBranchName) => {
const defaultBranchName = await gh.getDefaultBranch();
const sourceBranch =
actionType == actions.types.Release ? prodBranch : defaultBranchName;
const headBranch =
actionType == actions.types.Release ? defaultBranchName : prodBranch;
console.log(`Source brach ${sourceBranch} - New Branch ${choreBranchName}`);
const files = await gh.getFilesThatChanged(sourceBranch, headBranch);
console.log(`Files that changed ${files.length}`);
if (files.length == 0) {
throw new Error("No changes to be merged");
}
await gh.createNewBranch(sourceBranch, choreBranchName);
await gh.mergeBranches(choreBranchName, headBranch);
const packageJson = await gh.getContent(choreBranchName, "package.json");
const newJson = ops.updateVersion(packageJson.content, actionType);
console.log(`Bumping version`);
await gh.commitContent(
"package.json",
`Updating Package Version to ${newJson.version}`,
Buffer.from(JSON.stringify(newJson, undefined, 4)).toString("base64"),
packageJson.sha,
choreBranchName
);
console.log(`Creating PR`);
const pr = await gh.createPR(sourceBranch, choreBranchName);
const merge = await gh.mergePR(pr.number);
return { merge, newJson };
};
const pushReleaseVersion = async () => {
console.log("::group::Push Release Version");
const choreBranchName = `Chore/Sprint${sprint}`;
const { merge, newJson } = await mergeBranch(choreBranchName);
await gh.createTag(merge.sha, sprint, releaseNotes);
console.log("::endgroup::");
return newJson.version;
};
const pushMergeBackVersion = async () => {
console.log("::group::Merge Back Version");
const choreBranchName = `Chore/MergeBackSprint${sprint}`;
const { _, newJson } = await mergeBranch(choreBranchName);
console.log("::endgroup::");
return newJson.version;
};
const action =
actionType === actions.types.Release
? pushReleaseVersion
: pushMergeBackVersion;
action()
.then((version) => {
core.info(`Successfully Released Package Version: ${version}`);
core.setOutput("success", true);
})
.catch((err) => {
core.setFailed(err);
core.setOutput("success", false);
});