Skip to content

Commit d15a5a9

Browse files
committed
iw
1 parent a452153 commit d15a5a9

File tree

1 file changed

+23
-50
lines changed

1 file changed

+23
-50
lines changed

.github/workflows/incrementVersionAndCreatePR.cjs

+23-50
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,14 @@ const execAsync = util.promisify(exec);
55

66
module.exports = async ({ github, context, versionType }) => {
77
async function configureGit() {
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-
}
15-
8+
await execAsync('git config user.name "github-actions"');
9+
await execAsync('git config user.email "github-actions@github.com"');
1610
console.log("Configured git user");
1711
}
1812

1913
async function incrementVersion() {
2014
console.log(`Incrementing version with ${versionType}`);
21-
try {
22-
await execAsync(`npm version ${versionType}`);
23-
} catch (e) {
24-
console.log("Error in incrementing version");
25-
throw Error(e);
26-
}
15+
await execAsync(`npm version ${versionType}`);
2716
const packageJson = require("../../package.json");
2817
const version = packageJson.version;
2918
console.log(`Incremented version to v${version}(${versionType})`);
@@ -32,44 +21,29 @@ module.exports = async ({ github, context, versionType }) => {
3221
}
3322

3423
async function pushChangesAndTags(featureBranch) {
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-
}
24+
await execAsync(`git push origin HEAD:refs/heads/${featureBranch}`);
25+
await execAsync("git push origin --tags");
4226
}
4327

4428
async function getPull(source, target) {
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-
}
29+
const existingPr = await github.pulls.list({
30+
owner: context.repo.owner,
31+
repo: context.repo.repo,
32+
head: source,
33+
base: target,
34+
});
35+
return existingPr.data.length > 0;
5736
}
5837

5938
async function createPull(title, source, target) {
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-
}
39+
await github.pulls.create({
40+
title,
41+
body: `${title} PR.`,
42+
owner: context.repo.owner,
43+
repo: context.repo.repo,
44+
head: source,
45+
base: target,
46+
});
7347
}
7448

7549
try {
@@ -81,15 +55,14 @@ module.exports = async ({ github, context, versionType }) => {
8155
await pushChangesAndTags(featureBranch);
8256
const title = `Version Increment to v${version}(${versionType})`;
8357
await createPull(title, featureBranch, "master");
84-
8558
console.log(
8659
`Created pull request for version increment to v${version}(${versionType}).`
8760
);
8861
} else {
89-
throw new Error("Pull request already exists for this version increment");
62+
console.error("Pull request already exists for this version increment");
9063
}
9164
} catch (error) {
92-
console.error(error);
93-
throw new Error("Error in version increment and PR creation");
65+
console.error("Error encountered:", error);
66+
// Decide whether to re-throw the error or handle it differently here
9467
}
9568
};

0 commit comments

Comments
 (0)