generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy path.release-it.beta.cjs
More file actions
166 lines (152 loc) · 5.08 KB
/
.release-it.beta.cjs
File metadata and controls
166 lines (152 loc) · 5.08 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
require('dotenv').config();
const { execSync } = require('child_process');
const semver = require('semver');
// 智能获取上一个相关版本标签
function getLastRelevantTag() {
try {
// 获取所有标签(包括带 v 前缀和不带 v 前缀的)
const allTags = execSync('git tag -l', { encoding: 'utf8' })
.trim()
.split('\n')
.filter(Boolean);
// 过滤出在当前分支历史中的标签
const reachableTags = [];
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) {
reachableTags.push({ tag, version });
}
} catch (e) {
// 标签不在当前分支历史中,跳过
}
}
if (reachableTags.length === 0) {
console.log('No valid tags found in current branch history, using HEAD~30');
return 'HEAD~30';
}
// 按照 semver 排序,从高到低
const sortedTags = reachableTags.sort((a, b) => {
const versionCompare = semver.rcompare(a.version, b.version);
if (versionCompare !== 0) return versionCompare;
// 如果版本相同,优先选择带 'v' 前缀的标签(通常是更正式的)
const aHasV = a.tag.startsWith('v');
const bHasV = b.tag.startsWith('v');
if (aHasV && !bHasV) return -1;
if (!aHasV && bHasV) return 1;
// 如果都有或都没有 'v' 前缀,按标签名字母顺序
return b.tag.localeCompare(a.tag);
});
// 对于相同版本的多个标签,选择最近的一个(通过检查提交距离)
let latestTag = sortedTags[0];
if (sortedTags.length > 1) {
const sameVersionTags = sortedTags.filter(t => t.version === latestTag.version);
if (sameVersionTags.length > 1) {
// 选择距离 HEAD 最近的标签
let minDistance = Infinity;
for (const tag of sameVersionTags) {
try {
const distance = parseInt(execSync(`git rev-list --count ${tag.tag}..HEAD`, { encoding: 'utf8' }).trim());
if (distance < minDistance) {
minDistance = distance;
latestTag = tag;
}
} catch (e) {
// 忽略错误
}
}
}
}
console.log(`Using latest reachable tag: ${latestTag.tag} (version: ${latestTag.version})`);
// 显示提交数量信息
try {
const commitCount = execSync(`git rev-list --count ${latestTag.tag}..HEAD`, { encoding: 'utf8' }).trim();
console.log(`Will include ${commitCount} commits since ${latestTag.tag}`);
} catch (e) {
// 忽略错误,这只是信息性输出
}
return latestTag.tag;
} catch (error) {
console.warn('Warning: Could not determine last relevant tag, using HEAD~30', error.message);
return 'HEAD~30';
}
}
module.exports = {
interactive: true,
preRelease: 'beta',
hooks: {
"before:init": ["node esbuild.config.mjs production"],
"after:bump": [
"node esbuild.config.mjs production",
"node ./scripts/zip.mjs",
"git add .",
],
"after:release":
"echo 'Successfully released Task Genius v${version} (BETA) to ${repo.repository}.'",
},
git: {
requireBranch: ["master", "beta", "develop", "refactor/*"],
requireCleanWorkingDir: true,
pushArgs: "--follow-tags -o ci.skip",
commitMessage: "chore(release): bump version to ${version} [beta]",
tagName: "${version}",
tagAnnotation: "Beta 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: "chore", section: "Chores"},
{type: "docs", section: "Documentation"},
{type: "style", section: "Styles"},
{type: "test", section: "Tests"}
]
},
infile: "CHANGELOG-BETA.md",
header: "# Beta Changelog\n\nAll notable changes to beta releases will be documented in this file.\n\n",
// 限制 git log 的提交范围,避免 ENAMETOOLONG 错误
gitRawCommitsOpts: {
from: getLastRelevantTag(), // 智能获取上一个相关版本
}
},
"./scripts/ob-bumper.mjs": {
indent: 2,
copyTo: "./dist",
},
},
npm: {
publish: false,
tag: 'beta',
},
github: {
release: true,
preRelease: true,
draft: false,
assets: [
"dist/main.js",
"dist/manifest.json",
"dist/styles.css",
"dist/task-genius-${version}.zip",
],
proxy: process.env.HTTPS_PROXY,
releaseName: "${version} (Beta)",
releaseNotes: (context) => {
// 获取智能范围信息
const fromTag = getLastRelevantTag();
const rangeInfo = fromTag.startsWith('HEAD')
? `\n### Changes in this release (last ${fromTag.replace('HEAD~', '')} commits):\n`
: `\n### Changes since ${fromTag}:\n`;
return `## ⚠️ Beta Release\n\nThis is a beta release and may contain bugs or incomplete features. Use at your own risk.\n${rangeInfo}\n${context.changelog}`;
},
},
};