Skip to content

Commit a452153

Browse files
committed
final
1 parent 0d70c77 commit a452153

File tree

2 files changed

+41
-29
lines changed

2 files changed

+41
-29
lines changed

.github/workflows/increment-version.yaml

-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ jobs:
2020
with:
2121
fetch-depth: 0
2222

23-
- name: Setup Node.js
24-
uses: actions/setup-node@v4
25-
with:
26-
node-version: "20.10.0"
27-
2823
- uses: actions/github-script@v4
2924
name: "Increment Version and Raise Pull Request"
3025
with:

.github/workflows/incrementVersionAndCreatePR.cjs

+41-24
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ const execAsync = util.promisify(exec);
55

66
module.exports = async ({ github, context, versionType }) => {
77
async function configureGit() {
8-
await execAsync('git config user.name "github-actions"');
9-
await execAsync('git config user.email "github-actions@github.com"');
8+
try {
9+
await execAsync('git config user.name "github-actions"');
10+
await execAsync('git config user.email "github-actions@github.com"');
11+
} catch (e) {
12+
console.log("Error in configuring git user");
13+
throw Error(e);
14+
}
1015

1116
console.log("Configured git user");
1217
}
@@ -16,43 +21,55 @@ module.exports = async ({ github, context, versionType }) => {
1621
try {
1722
await execAsync(`npm version ${versionType}`);
1823
} catch (e) {
19-
console.error(e);
20-
// console.log("Error in incrementing version", e);
24+
console.log("Error in incrementing version");
2125
throw Error(e);
2226
}
23-
console.log("Version incremented");
2427
const packageJson = require("../../package.json");
25-
console.log("packageJson");
2628
const version = packageJson.version;
2729
console.log(`Incremented version to v${version}(${versionType})`);
2830
const featureBranch = `chore-increment-verion-${version}-${versionType}-${context.runNumber}`;
2931
return { featureBranch, version };
3032
}
3133

3234
async function pushChangesAndTags(featureBranch) {
33-
await execAsync(`git push origin HEAD:refs/heads/${featureBranch}`);
34-
await execAsync("git push origin --tags");
35+
try {
36+
await execAsync(`git push origin HEAD:refs/heads/${featureBranch}`);
37+
await execAsync("git push origin --tags");
38+
} catch (e) {
39+
console.log("Error in pushing changes and tags");
40+
throw Error(e);
41+
}
3542
}
3643

3744
async function getPull(source, target) {
38-
const existingPr = await github.pulls.list({
39-
owner: context.repo.owner,
40-
repo: context.repo.repo,
41-
head: source,
42-
base: target,
43-
});
44-
return existingPr.data.length > 0;
45+
try {
46+
const existingPr = await github.pulls.list({
47+
owner: context.repo.owner,
48+
repo: context.repo.repo,
49+
head: source,
50+
base: target,
51+
});
52+
return existingPr.data.length > 0;
53+
} catch (e) {
54+
console.log("Error in getting pull request");
55+
throw Error(e);
56+
}
4557
}
4658

4759
async function createPull(title, source, target) {
48-
await github.pulls.create({
49-
title,
50-
body: `${title} PR.`,
51-
owner: context.repo.owner,
52-
repo: context.repo.repo,
53-
head: source,
54-
base: target,
55-
});
60+
try {
61+
await github.pulls.create({
62+
title,
63+
body: `${title} PR.`,
64+
owner: context.repo.owner,
65+
repo: context.repo.repo,
66+
head: source,
67+
base: target,
68+
});
69+
} catch (e) {
70+
console.log("Error in creating pull request");
71+
throw Error(e);
72+
}
5673
}
5774

5875
try {
@@ -69,7 +86,7 @@ module.exports = async ({ github, context, versionType }) => {
6986
`Created pull request for version increment to v${version}(${versionType}).`
7087
);
7188
} else {
72-
console.log("Pull request already exists for this version increment");
89+
throw new Error("Pull request already exists for this version increment");
7390
}
7491
} catch (error) {
7592
console.error(error);

0 commit comments

Comments
 (0)