-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy path.release-it.ts
More file actions
147 lines (133 loc) · 3.33 KB
/
.release-it.ts
File metadata and controls
147 lines (133 loc) · 3.33 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { execSync } from "node:child_process";
import type { Config } from "release-it";
interface ConventionalCommitLike {
type?: string;
notes?: unknown[];
}
function getCurrentBranch(): string {
try {
return execSync("git rev-parse --abbrev-ref HEAD", {
encoding: "utf8",
stdio: ["ignore", "pipe", "pipe"],
}).trim();
} catch (error: unknown) {
console.error("Failed to determine the current Git branch.");
console.error(error);
process.exit(1);
}
}
function isPreReleaseRun(argv: string[]): boolean {
return argv.some((argument) => {
return (
argument === "--preRelease" ||
argument.startsWith("--preRelease=") ||
argument === "--preReleaseId" ||
argument.startsWith("--preReleaseId=")
);
});
}
const currentBranch = getCurrentBranch();
const preReleaseRun = isPreReleaseRun(process.argv);
if (preReleaseRun && currentBranch !== "development") {
console.error(
`Pre-releases are only allowed on "development". Current branch: "${currentBranch}".`,
);
process.exit(1);
}
if (!preReleaseRun && currentBranch !== "main") {
console.error(
`Stable releases are only allowed on "main". Current branch: "${currentBranch}".`,
);
process.exit(1);
}
const config = {
npm: {
publish: false,
},
git: {
requireCleanWorkingDir: true,
requireBranch: currentBranch,
commit: true,
commitMessage: "chore(release): v${version}",
commitArgs: ["--no-verify"],
tag: true,
tagName: "v${version}",
push: true,
pushArgs: ["--follow-tags"],
},
github: {
release: false,
},
plugins: {
"@release-it/conventional-changelog": {
infile: "CHANGELOG.md",
preset: {
name: "conventionalcommits",
commitUrlFormat:
"https://github.com/gohugo-ananke/ananke/commit/{{hash}}",
compareUrlFormat:
"https://github.com/gohugo-ananke/ananke/compare/{{previousTag}}...{{currentTag}}",
types: [
{ type: "feat", section: "Features" },
{ type: "fix", section: "Bug Fixes" },
{ type: "build", section: "Build" },
{ type: "chore", section: "Chores" },
{ type: "ci", section: "CI" },
{ type: "docs", section: "Documentation" },
{ type: "perf", section: "Performance" },
{ type: "refactor", section: "Refactoring" },
{ type: "revert", section: "Reverts" },
{ type: "style", section: "Styles" },
{ type: "test", section: "Tests" },
{ type: "ai", section: "AI Instruction Files" },
],
},
whatBump(commits: ConventionalCommitLike[]) {
let level: 2 | 1 | 0 | null = null;
for (const commit of commits) {
const notes = Array.isArray(commit.notes) ? commit.notes : [];
const type = typeof commit.type === "string" ? commit.type : "";
if (notes.length > 0) {
return {
level: 0,
reason: "There are BREAKING CHANGES.",
};
}
if (type === "feat") {
level = 1;
continue;
}
if (
level === null &&
[
"fix",
"build",
"chore",
"ci",
"docs",
"perf",
"refactor",
"revert",
"style",
"test",
"ai",
].includes(type)
) {
level = 2;
}
}
if (level === null) {
return false;
}
return {
level,
reason:
level === 1
? "There are feature commits."
: "There are patch-level changes.",
};
},
},
},
} satisfies Config;
export default config;