@produck/agent-toolkit 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/bin/release.mjs +113 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,16 +50,29 @@ Interactive prompts let you choose:
|
|
|
50
50
|
|
|
51
51
|
- version level: patch/minor/major
|
|
52
52
|
- action: dry-run or publish
|
|
53
|
+
- vcs mode: commit+tag / commit only / no commit+no tag
|
|
53
54
|
|
|
54
55
|
Default choices:
|
|
55
56
|
|
|
56
57
|
- patch
|
|
57
58
|
- dry-run
|
|
59
|
+
- commit + tag
|
|
58
60
|
|
|
59
61
|
Interactive mode handles both:
|
|
60
62
|
|
|
61
63
|
- version bump level (patch/minor/major)
|
|
62
64
|
- action mode (dry-run or publish)
|
|
65
|
+
- auto commit and tag after dry-run
|
|
66
|
+
|
|
67
|
+
Non-interactive flags:
|
|
68
|
+
|
|
69
|
+
- `npm --prefix tools/agent-toolkit run release -- patch --publish`
|
|
70
|
+
- `npm --prefix tools/agent-toolkit run release -- patch --no-tag`
|
|
71
|
+
- `npm --prefix tools/agent-toolkit run release -- patch --no-commit --no-tag`
|
|
72
|
+
|
|
73
|
+
Note:
|
|
74
|
+
|
|
75
|
+
- Release requires a clean working tree in `tools/agent-toolkit` before start.
|
|
63
76
|
|
|
64
77
|
Low-level commands (optional):
|
|
65
78
|
|
package/bin/release.mjs
CHANGED
|
@@ -10,18 +10,22 @@ function usage() {
|
|
|
10
10
|
console.log([
|
|
11
11
|
'Usage:',
|
|
12
12
|
' node ./bin/release.mjs',
|
|
13
|
-
' node ./bin/release.mjs <patch|minor|major> [--publish]',
|
|
13
|
+
' node ./bin/release.mjs <patch|minor|major> [--publish] [--no-commit] [--no-tag]',
|
|
14
14
|
' node ./bin/release.mjs --interactive',
|
|
15
15
|
'',
|
|
16
16
|
'Behavior:',
|
|
17
17
|
' 1) bump version (no git tag)',
|
|
18
18
|
' 2) run verify',
|
|
19
19
|
' 3) run publish:dry-run',
|
|
20
|
-
' 4)
|
|
20
|
+
' 4) auto commit version change (default)',
|
|
21
|
+
' 5) auto create git tag (default)',
|
|
22
|
+
' 6) optionally publish latest when --publish is set',
|
|
21
23
|
'',
|
|
22
24
|
'Interactive mode defaults:',
|
|
23
25
|
' - release level: patch',
|
|
24
26
|
' - publish mode: dry-run',
|
|
27
|
+
' - auto commit: enabled',
|
|
28
|
+
' - auto tag: enabled',
|
|
25
29
|
].join('\n'));
|
|
26
30
|
}
|
|
27
31
|
|
|
@@ -43,6 +47,70 @@ function runNpm(args) {
|
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
|
|
50
|
+
function runGit(args) {
|
|
51
|
+
const result = spawnSync('git', args, {
|
|
52
|
+
stdio: 'inherit',
|
|
53
|
+
cwd: process.cwd(),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
if (result.error) {
|
|
57
|
+
console.error(`[release] failed to run git ${args.join(' ')}:`);
|
|
58
|
+
console.error(result.error.message);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (result.status !== 0) {
|
|
63
|
+
process.exit(result.status ?? 1);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function getDirtyFiles() {
|
|
68
|
+
const result = spawnSync('git', ['status', '--porcelain'], {
|
|
69
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
70
|
+
cwd: process.cwd(),
|
|
71
|
+
encoding: 'utf8',
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
if (result.error || result.status !== 0) {
|
|
75
|
+
console.error('[release] unable to check git status');
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return result.stdout
|
|
80
|
+
.split(/\r?\n/)
|
|
81
|
+
.map((line) => line.trim())
|
|
82
|
+
.filter((line) => line.length > 0);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function ensureReleaseWorkspaceClean() {
|
|
86
|
+
const dirty = getDirtyFiles();
|
|
87
|
+
if (dirty.length === 0) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
console.error('[release] working tree is not clean before release:');
|
|
92
|
+
for (const line of dirty) {
|
|
93
|
+
console.error(` ${line}`);
|
|
94
|
+
}
|
|
95
|
+
console.error('[release] commit/stash changes and retry');
|
|
96
|
+
process.exit(2);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function commitAndTag(version, shouldCommit, shouldTag) {
|
|
100
|
+
if (shouldCommit) {
|
|
101
|
+
const message = `[UPGRADE] <infra>: release @produck/agent-toolkit ${version}`;
|
|
102
|
+
console.log(`[release] commit version bump: ${message}`);
|
|
103
|
+
runGit(['add', 'package.json']);
|
|
104
|
+
runGit(['commit', '-m', message]);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (shouldTag) {
|
|
108
|
+
const tag = `agent-toolkit-v${version}`;
|
|
109
|
+
console.log(`[release] create tag: ${tag}`);
|
|
110
|
+
runGit(['tag', '-a', tag, '-m', `[UPGRADE] <infra>: tag ${tag}`]);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
46
114
|
function bumpPreview(version, level) {
|
|
47
115
|
const parts = version.split('.').map((v) => Number(v));
|
|
48
116
|
if (parts.length !== 3 || parts.some((v) => Number.isNaN(v))) {
|
|
@@ -102,19 +170,43 @@ async function askInteractive(currentVersion) {
|
|
|
102
170
|
process.exit(2);
|
|
103
171
|
}
|
|
104
172
|
|
|
105
|
-
|
|
173
|
+
console.log('[release] auto commit and tag settings:');
|
|
174
|
+
console.log(' 1) commit + tag (default)');
|
|
175
|
+
console.log(' 2) commit only');
|
|
176
|
+
console.log(' 3) no commit, no tag');
|
|
177
|
+
|
|
178
|
+
const vcsAnswer = (
|
|
179
|
+
await rl.question('Choose vcs mode [1/2/3] (default: 1): ')
|
|
180
|
+
).trim();
|
|
181
|
+
|
|
182
|
+
let shouldCommit = true;
|
|
183
|
+
let shouldTag = true;
|
|
184
|
+
if (vcsAnswer === '2') {
|
|
185
|
+
shouldCommit = true;
|
|
186
|
+
shouldTag = false;
|
|
187
|
+
} else if (vcsAnswer === '3') {
|
|
188
|
+
shouldCommit = false;
|
|
189
|
+
shouldTag = false;
|
|
190
|
+
} else if (vcsAnswer && vcsAnswer !== '1') {
|
|
191
|
+
console.error(`Invalid vcs choice: ${vcsAnswer}`);
|
|
192
|
+
process.exit(2);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return { level, shouldPublish, shouldCommit, shouldTag };
|
|
106
196
|
} finally {
|
|
107
197
|
rl.close();
|
|
108
198
|
}
|
|
109
199
|
}
|
|
110
200
|
|
|
111
|
-
function runRelease(level, shouldPublish) {
|
|
201
|
+
function runRelease(level, shouldPublish, shouldCommit, shouldTag) {
|
|
112
202
|
if (!LEVELS.has(level)) {
|
|
113
203
|
console.error(`Invalid release level: ${level}`);
|
|
114
204
|
usage();
|
|
115
205
|
process.exit(2);
|
|
116
206
|
}
|
|
117
207
|
|
|
208
|
+
ensureReleaseWorkspaceClean();
|
|
209
|
+
|
|
118
210
|
const pkgFile = path.resolve('package.json');
|
|
119
211
|
const before = JSON.parse(fs.readFileSync(pkgFile, 'utf8')).version;
|
|
120
212
|
|
|
@@ -130,6 +222,8 @@ function runRelease(level, shouldPublish) {
|
|
|
130
222
|
console.log('[release] publish dry-run');
|
|
131
223
|
runNpm(['run', 'publish:dry-run']);
|
|
132
224
|
|
|
225
|
+
commitAndTag(after, shouldCommit, shouldTag);
|
|
226
|
+
|
|
133
227
|
if (shouldPublish) {
|
|
134
228
|
console.log('[release] publish latest');
|
|
135
229
|
runNpm(['run', 'publish:latest']);
|
|
@@ -155,10 +249,23 @@ if (interactiveRequested) {
|
|
|
155
249
|
const pkgFile = path.resolve('package.json');
|
|
156
250
|
const currentVersion = JSON.parse(fs.readFileSync(pkgFile, 'utf8')).version;
|
|
157
251
|
const interactive = await askInteractive(currentVersion);
|
|
158
|
-
runRelease(
|
|
252
|
+
runRelease(
|
|
253
|
+
interactive.level,
|
|
254
|
+
interactive.shouldPublish,
|
|
255
|
+
interactive.shouldCommit,
|
|
256
|
+
interactive.shouldTag
|
|
257
|
+
);
|
|
159
258
|
process.exit(0);
|
|
160
259
|
}
|
|
161
260
|
|
|
162
261
|
const level = args[0];
|
|
163
262
|
const shouldPublish = args.includes('--publish');
|
|
164
|
-
|
|
263
|
+
const shouldCommit = !args.includes('--no-commit');
|
|
264
|
+
const shouldTag = !args.includes('--no-tag');
|
|
265
|
+
|
|
266
|
+
if (shouldTag && !shouldCommit) {
|
|
267
|
+
console.error('[release] --no-commit cannot be combined with tag enabled');
|
|
268
|
+
process.exit(2);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
runRelease(level, shouldPublish, shouldCommit, shouldTag);
|