-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrelease.config.mjs
More file actions
81 lines (69 loc) · 2.16 KB
/
release.config.mjs
File metadata and controls
81 lines (69 loc) · 2.16 KB
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
import { execSync } from "child_process";
const MAINTENANCE_BRANCH_PREFIX = "origin/mc/";
const TAG_REGEX = /^v?(\d+\.\d+\.\d+)(?:\+.+)?$/;
/**
* Gets the latest version based on the tags from a specific git branch.
* @param {string} branchName The name of the branch (e.g., 'origin/mc/1.21.7').
* @returns {string} The version string (e.g., '1.6.0').
*/
function getVersionFromBranch(branchName) {
const latestTag = execSync(`git describe --tags --abbrev=0 ${branchName}`, {
encoding: "utf-8",
}).trim();
const match = latestTag.match(TAG_REGEX);
if (!match) {
throw new Error(
`Version "${latestTag}" on branch ${branchName} does not match expected format.`
);
}
return match[1];
}
/**
* Creates a version range string from a given version.
* @param {string} version - The version string (e.g., '1.6.0').
* @returns {string} The version range string (e.g., '1.6.x').
*/
function makeVersionRange(version) {
const [major, minor] = version.split(".");
return `${major}.${minor}.x`;
}
const config = {
plugins: [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/exec",
{
prepareCmd: './release/prepare.sh "${nextRelease.version}"',
publishCmd: "./release/publish.sh \"$(cat << 'EOF'\n${nextRelease.notes}\nEOF\n)\"",
},
],
[
"@semantic-release/github",
{
assets: ["build/libs/*.jar"],
releaseNameTemplate: "${nextRelease.version} for Minecraft <%= process.env.MINECRAFT_VERSION %>",
},
],
],
branches: [{ name: "main" }],
};
const branches = execSync("git branch -r", { encoding: "utf-8" }).split("\n");
for (const branch of branches) {
const branchName = branch.trim();
if (!branchName.startsWith(MAINTENANCE_BRANCH_PREFIX)) {
continue;
}
const version = getVersionFromBranch(branchName);
const shortBranchName = branchName.replace("origin/", "");
config.branches.push({
name: shortBranchName,
range: makeVersionRange(version),
prerelease: false,
});
}
// console.log(
// "Generated semantic-release config:",
// JSON.stringify(config, null, 2)
// );
export default config;