Skip to content

Commit 1e354d4

Browse files
committed
Build: attempting to add PR comments for prerelease versions
1 parent c70bb59 commit 1e354d4

File tree

1 file changed

+75
-22
lines changed

1 file changed

+75
-22
lines changed

release.config.js

Lines changed: 75 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,59 @@
1+
const { execSync } = require("child_process");
12
const defaultReleaseRules = require("@semantic-release/commit-analyzer/lib/default-release-rules");
23

3-
module.exports = {
4-
branches: ["main"],
5-
repositoryUrl: "[email protected]:WTW-IM/scriptloader-component.git",
4+
const branchName = execSync("git rev-parse --abbrev-ref HEAD")
5+
.toString()
6+
.replace("\n", "");
7+
8+
const getPrereleaseId = () => {
9+
const currentShaChars = execSync("git rev-parse HEAD").toString();
10+
const currentSha = currentShaChars.substr(0, 6);
11+
12+
const tagsOutput = execSync("git ls-remote --tags").toString().split("\n");
13+
const tags = tagsOutput
14+
.map((tagString) => {
15+
const execResult = /\/tags\/(?<tag>.*)$/.exec(tagString);
16+
if (!execResult) return null;
17+
18+
return execResult.groups.tag;
19+
})
20+
.filter((tag) => tag && tag.includes(branchName))
21+
.map((tag) => tag.substr(tag.indexOf(branchName)));
22+
23+
let shaVersion = 0;
24+
let prereleaseName = `${branchName}-${currentSha}`;
25+
26+
while (tags.includes(`${prereleaseName}.1`)) {
27+
shaVersion += 1;
28+
prereleaseName = `${prereleaseName}-${shaVersion}`;
29+
}
30+
prereleaseName = prereleaseName.replace(`${branchName}-`, "");
31+
const prereleaseId = `\${name}-${prereleaseName}`;
32+
return prereleaseId;
33+
};
34+
35+
const preId = getPrereleaseId();
36+
37+
const basePlugins = [
38+
[
39+
"@semantic-release/commit-analyzer",
40+
{
41+
releaseRules: [
42+
...defaultReleaseRules,
43+
{ tag: "Refactor", release: "patch" },
44+
{ tag: "Patch", release: "patch" },
45+
],
46+
},
47+
],
48+
"@semantic-release/commit-analyzer",
49+
"@semantic-release/release-notes-generator",
50+
"@semantic-release/changelog",
51+
"@semantic-release/npm",
52+
];
53+
54+
const mainConfig = {
655
plugins: [
7-
[
8-
"@semantic-release/commit-analyzer",
9-
{
10-
preset: "eslint",
11-
releaseRules: [
12-
...defaultReleaseRules,
13-
{ tag: "Refactor", release: "patch" },
14-
{ tag: "Patch", release: "patch" },
15-
],
16-
},
17-
],
18-
[
19-
"@semantic-release/release-notes-generator",
20-
{
21-
preset: "eslint",
22-
},
23-
],
24-
"@semantic-release/changelog",
25-
"@semantic-release/npm",
56+
...basePlugins,
2657
[
2758
"@semantic-release/github",
2859
{
@@ -38,3 +69,25 @@ module.exports = {
3869
],
3970
],
4071
};
72+
73+
const branchConfig = {
74+
plugins: [
75+
...basePlugins,
76+
[
77+
"@semantic-release/github",
78+
{
79+
successComment:
80+
"This PR is part of this prerelease version for testing: ${nextRelease.version}",
81+
},
82+
],
83+
],
84+
};
85+
86+
const config = branchName === "main" ? mainConfig : branchConfig;
87+
88+
module.exports = {
89+
branches: ["main", { name: branchName, channel: preId, prerelease: preId }],
90+
preset: "eslint",
91+
repositoryUrl: "[email protected]:WTW-IM/scriptloader-component.git",
92+
...config,
93+
};

0 commit comments

Comments
 (0)