Skip to content

Commit 2ca2208

Browse files
Fix release scripts for release candidates (#55)
* Fix release scripts for release candidates * Refactor release script to use semver npm package
1 parent 6ab2373 commit 2ca2208

File tree

6 files changed

+116
-24
lines changed

6 files changed

+116
-24
lines changed

.github/workflows/publish-rc.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Release (RC)
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*-rc.*"
7+
8+
jobs:
9+
release-rc:
10+
name: Build + Publish RC
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
id-token: write # npm provenance
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v6
18+
19+
- name: Setup Node
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version-file: package.json
23+
registry-url: "https://registry.npmjs.org"
24+
25+
- name: Setup Bun
26+
uses: oven-sh/setup-bun@v2
27+
with:
28+
bun-version: latest
29+
30+
- name: Install dependencies
31+
run: bun install --frozen-lockfile
32+
33+
- name: Lint
34+
run: bun run lint
35+
36+
- name: Test
37+
run: bun run test
38+
39+
- name: Build release binaries
40+
run: bun run build:release
41+
42+
- name: Upload release assets
43+
uses: softprops/action-gh-release@v2
44+
with:
45+
files: |
46+
release/agent-slack-*
47+
release/checksums-sha256.txt
48+
generate_release_notes: true
49+
prerelease: true
50+
51+
- name: Build for npm
52+
run: bun run build:npm
53+
54+
- name: Publish to npm (rc tag)
55+
run: npm publish --provenance --access public --tag rc

.github/workflows/publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
tags:
66
- "v*"
7+
- "!v*-rc.*"
78

89
jobs:
910
release:

bun.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@
4848
},
4949
"devDependencies": {
5050
"@types/node": "^22",
51+
"@types/semver": "^7.7.1",
5152
"@types/turndown": "^5.0.6",
5253
"bun-types": "^1.3.9",
5354
"oxfmt": "^0.31.0",
5455
"oxlint": "^1.46.0",
56+
"semver": "^7.7.4",
5557
"simple-git-hooks": "^2.13.1",
5658
"typescript": "^5.8.2"
5759
},

scripts/bump.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import semver from "semver";
2+
import fs from "fs";
3+
const [, , versionArg] = process.argv;
4+
if (!versionArg) {
5+
console.error("version argument required");
6+
process.exit(1);
7+
}
8+
const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
9+
const currentVersion = pkg.version;
10+
if (["patch", "minor", "major"].includes(versionArg)) {
11+
console.log(semver.inc(currentVersion, versionArg));
12+
process.exit(0);
13+
}
14+
if (["patch-rc", "minor-rc", "major-rc"].includes(versionArg)) {
15+
const bumpType = versionArg.replace("-rc", "");
16+
const parsed = semver.parse(currentVersion);
17+
const isRc = parsed.prerelease.length > 0 && parsed.prerelease[0] === "rc";
18+
if (isRc) {
19+
let rcTargetType = "unknown";
20+
if (parsed.patch > 0) {
21+
rcTargetType = "patch";
22+
} else if (parsed.minor > 0) {
23+
rcTargetType = "minor";
24+
} else if (parsed.major > 0) {
25+
rcTargetType = "major";
26+
}
27+
if (rcTargetType === bumpType) {
28+
console.log(semver.inc(currentVersion, "prerelease", "rc"));
29+
process.exit(0);
30+
}
31+
}
32+
const baseVersion = `${parsed.major}.${parsed.minor}.${parsed.patch}`;
33+
console.log(semver.inc(baseVersion, `pre${bumpType}`, "rc"));
34+
process.exit(0);
35+
}
36+
const valid = semver.valid(versionArg);
37+
if (!valid) {
38+
console.error(`invalid version format: ${versionArg}`);
39+
process.exit(1);
40+
}
41+
console.log(valid);

scripts/release.sh

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ usage() {
3131
printf '%s\n' ""
3232
printf '%s\n' "Arguments:"
3333
printf '%s\n' " version Version number (e.g., 0.2.0) or bump type (patch, minor, major)"
34+
printf '%s\n' " Append -rc to any bump type for release candidate (e.g., patch-rc)"
3435
printf '%s\n' ""
3536
printf '%s\n' "Examples:"
36-
printf '%s\n' " $0 0.2.0 # Set version to 0.2.0"
37-
printf '%s\n' " $0 patch # Bump patch version (0.1.0 -> 0.1.1)"
38-
printf '%s\n' " $0 minor # Bump minor version (0.1.0 -> 0.2.0)"
39-
printf '%s\n' " $0 major # Bump major version (0.1.0 -> 1.0.0)"
37+
printf '%s\n' " $0 0.2.0 # Set version to 0.2.0"
38+
printf '%s\n' " $0 patch # Bump patch version (0.1.0 -> 0.1.1)"
39+
printf '%s\n' " $0 minor # Bump minor version (0.1.0 -> 0.2.0)"
40+
printf '%s\n' " $0 major # Bump major version (0.1.0 -> 1.0.0)"
41+
printf '%s\n' " $0 patch-rc # Bump patch RC (0.1.0 -> 0.1.1-rc.0, 0.1.1-rc.0 -> 0.1.1-rc.1)"
42+
printf '%s\n' " $0 minor-rc # Bump minor RC (0.1.0 -> 0.2.0-rc.0)"
43+
printf '%s\n' " $0 major-rc # Bump major RC (0.1.0 -> 1.0.0-rc.0)"
4044
exit 1
4145
}
4246

@@ -53,26 +57,9 @@ version_arg="$1"
5357
current_version=$(node -p "require('./package.json').version")
5458

5559
# Calculate new version based on argument
56-
case "$version_arg" in
57-
patch)
58-
new_version=$(printf '%s' "$current_version" | awk -F. '{printf "%d.%d.%d", $1, $2, $3+1}')
59-
;;
60-
minor)
61-
new_version=$(printf '%s' "$current_version" | awk -F. '{printf "%d.%d.0", $1, $2+1}')
62-
;;
63-
major)
64-
new_version=$(printf '%s' "$current_version" | awk -F. '{printf "%d.0.0", $1+1}')
65-
;;
66-
*)
67-
# Validate version format (semver: X.Y.Z)
68-
if ! printf '%s' "$version_arg" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
69-
print_error "invalid version format: $version_arg"
70-
printf '%s\n' "Version must be in format X.Y.Z (e.g., 0.2.0) or a bump type (patch, minor, major)"
71-
exit 1
72-
fi
73-
new_version="$version_arg"
74-
;;
75-
esac
60+
if ! new_version=$(node scripts/bump.js "$version_arg"); then
61+
exit 1
62+
fi
7663

7764
tag="v$new_version"
7865

0 commit comments

Comments
 (0)