-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy path.release-it.cjs
More file actions
127 lines (116 loc) · 3.65 KB
/
.release-it.cjs
File metadata and controls
127 lines (116 loc) · 3.65 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
require('dotenv').config();
const { execSync } = require('child_process');
const semver = require('semver');
// 智能获取上一个正式版本标签(排除预发布版本)
function getLastStableTag() {
try {
// 获取所有标签
const allTags = execSync('git tag -l', { encoding: 'utf8' })
.trim()
.split('\n')
.filter(Boolean);
// 过滤出在当前分支历史中的标签,并排除预发布版本
const stableTags = [];
for (const tag of allTags) {
try {
// 检查标签是否可以从 HEAD 访问到
execSync(`git merge-base --is-ancestor ${tag} HEAD`, { encoding: 'utf8' });
// 尝试解析版本号(移除可能的 'v' 前缀)
const versionString = tag.replace(/^v/, '');
const version = semver.valid(versionString);
// 只保留正式版本(排除带有预发布标识的版本)
if (version && !semver.prerelease(version)) {
stableTags.push({ tag, version });
}
} catch (e) {
// 标签不在当前分支历史中,跳过
}
}
if (stableTags.length === 0) {
console.log('No stable version tags found, using HEAD~30');
return 'HEAD~30';
}
// 按照 semver 排序,从高到低
const sortedTags = stableTags.sort((a, b) => {
return semver.rcompare(a.version, b.version);
});
const latestStableTag = sortedTags[0];
console.log(`Using last stable version tag: ${latestStableTag.tag} (version: ${latestStableTag.version})`);
// 显示将包含的提交数量
try {
const commitCount = execSync(`git rev-list --count ${latestStableTag.tag}..HEAD`, { encoding: 'utf8' }).trim();
console.log(`Will include ${commitCount} commits since ${latestStableTag.tag}`);
} catch (e) {
// 忽略错误,这只是信息性输出
}
return latestStableTag.tag;
} catch (error) {
console.warn('Warning: Could not determine last stable tag, using HEAD~30', error.message);
return 'HEAD~30';
}
}
// 在模块开始时获取一次,避免重复调用
const lastStableTag = getLastStableTag();
module.exports = {
interactive: true,
hooks: {
"before:init": ["node esbuild.config.mjs production"],
"after:bump": [
"node esbuild.config.mjs production",
"node ./scripts/zip.mjs",
// 使用自定义 changelog 生成器替代 conventional-changelog
"node ./scripts/custom-changelog.mjs ${version}",
"git add .",
],
"after:release":
"echo Successfully released Task Genius v${version} to ${repo.repository}.",
},
git: {
requireBranch: "master",
requireCleanWorkingDir: true,
pushArgs: "--follow-tags -o ci.skip",
commitMessage: "chore(release): bump version to ${version}",
tagName: "${version}",
tagAnnotation: "Release ${version}",
addUntrackedFiles: true,
},
plugins: {
"@release-it/conventional-changelog": {
preset: {
name: "conventionalcommits",
types: [
{type: "feat", section: "Features"},
{type: "fix", section: "Bug Fixes"},
{type: "perf", section: "Performance"},
{type: "refactor", section: "Refactors"},
{type: "docs", section: "Documentation"},
{type: "style", section: "Styles"},
{type: "test", section: "Tests"},
{type: "revert", section: "Reverts"}
]
},
// 禁用 conventional-changelog 的 changelog 生成,使用我们的自定义脚本
infile: false,
// 仍然使用 conventional commits 来推荐版本号
strictSemVer: false
},
"./scripts/ob-bumper.mjs": {
indent: 2,
copyTo: "./dist",
},
},
npm: {
publish: false,
},
github: {
release: true,
assets: [
"dist/main.js",
"dist/manifest.json",
"dist/styles.css",
"dist/task-genius-${version}.zip",
],
proxy: process.env.HTTPS_PROXY,
releaseName: "${version}",
},
};