Skip to content

Commit 124f626

Browse files
Boshenclaude
andauthored
ci: switch release to a version-bump PR + push trigger flow (#1575)
We will restrict npm publish to main through github environment. Prelease is removed, please use pkr.pr.new instead. --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ccffc9b commit 124f626

3 files changed

Lines changed: 116 additions & 60 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Prepare Release
2+
3+
permissions: {}
4+
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Version to release (without v prefix, e.g. 0.1.0 or 0.1.0-alpha.0)'
10+
required: true
11+
type: string
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref_name }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
prepare:
19+
if: github.repository == 'voidzero-dev/vite-plus'
20+
name: Prepare Release
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
steps:
25+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
26+
with:
27+
fetch-depth: 0
28+
persist-credentials: false
29+
- uses: ./.github/actions/clone
30+
31+
- uses: oxc-project/setup-rust@68c3199c5339f965e6e163924c3c450773eba42b # main (pending v1.0.17 — Swatinem/rust-cache v2.9.1 for node24)
32+
with:
33+
save-cache: false
34+
cache-key: lint
35+
36+
- uses: oxc-project/setup-node@ab97f03642370d79a7e96dd286bd02a1be40e0ba # v1.3.0
37+
38+
- name: Bump versions
39+
env:
40+
VERSION: ${{ inputs.version }}
41+
run: |
42+
set -euo pipefail
43+
update_json() {
44+
local file=$1
45+
sed -i -E "s/^(\s*\"version\":\s*)\"[^\"]+\"/\1\"$VERSION\"/" "$file"
46+
grep -qF "\"version\": \"$VERSION\"" "$file" || { echo "::error::Failed to update $file"; exit 1; }
47+
echo "Updated $file"
48+
}
49+
update_toml() {
50+
local file=$1
51+
sed -i -E "s/^version\s*=\s*\"[^\"]+\"/version = \"$VERSION\"/" "$file"
52+
grep -qF "version = \"$VERSION\"" "$file" || { echo "::error::Failed to update $file"; exit 1; }
53+
echo "Updated $file"
54+
}
55+
update_json packages/cli/package.json
56+
update_json packages/core/package.json
57+
update_json packages/test/package.json
58+
update_toml packages/cli/binding/Cargo.toml
59+
update_toml crates/vite_global_cli/Cargo.toml
60+
61+
- name: Refresh Cargo.lock
62+
run: cargo check
63+
64+
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
65+
id: app-token
66+
with:
67+
client-id: ${{ secrets.APP_ID }}
68+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
69+
70+
- uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
71+
with:
72+
token: ${{ steps.app-token.outputs.token }}
73+
commit-message: 'release: v${{ inputs.version }}'
74+
title: 'release: v${{ inputs.version }}'
75+
branch: release/v${{ inputs.version }}
76+
base: main
77+
sign-commits: true
78+
body: |
79+
Release vite-plus v${{ inputs.version }}.
80+
81+
Merging this PR will trigger the release workflow.
82+
assignees: fengmk2

.github/workflows/release.yml

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,72 @@
11
name: Release
22

33
on:
4-
workflow_dispatch:
5-
inputs:
6-
npm_tag:
7-
description: 'npm tag for publish'
8-
required: true
9-
default: 'latest'
10-
type: choice
11-
options:
12-
- latest
13-
- alpha
14-
version:
15-
description: 'Override version (leave empty to auto-compute). Use when retrying a failed publish.'
16-
required: false
17-
default: ''
18-
type: string
4+
push:
5+
branches: [main]
6+
paths:
7+
- 'packages/cli/package.json'
198

209
permissions: {}
2110

2211
env:
2312
RELEASE_BUILD: 'true'
2413
DEBUG: 'napi:*'
25-
NPM_TAG: ${{ inputs.npm_tag }}
2614

2715
jobs:
28-
prepare:
16+
check:
17+
if: github.repository == 'voidzero-dev/vite-plus'
18+
name: Check version
2919
runs-on: ubuntu-latest
3020
permissions:
3121
contents: read
3222
outputs:
23+
version_changed: ${{ steps.version.outputs.changed }}
3324
version: ${{ steps.version.outputs.version }}
3425
steps:
35-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
36-
with:
37-
fetch-depth: 0
38-
fetch-tags: true
39-
persist-credentials: false
40-
- uses: ./.github/actions/set-snapshot-version
41-
if: ${{ inputs.version == '' }}
42-
id: computed
43-
with:
44-
npm_tag: ${{ inputs.npm_tag }}
26+
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2
4527

46-
- name: Set final version
28+
- uses: oxc-project/setup-node@ab97f03642370d79a7e96dd286bd02a1be40e0ba # v1.3.0
29+
30+
- name: Check version changes
31+
uses: EndBug/version-check@095362f3cd50f690c8fa0e6afeea81834bd8d320 # v3.0.0
4732
id: version
48-
env:
49-
INPUT_VERSION: ${{ inputs.version }}
50-
COMPUTED_VERSION: ${{ steps.computed.outputs.version }}
51-
run: echo "version=${INPUT_VERSION:-$COMPUTED_VERSION}" >> "$GITHUB_OUTPUT"
33+
with:
34+
static-checking: localIsNew
35+
file-url: https://unpkg.com/vite-plus@latest/package.json
36+
file-name: packages/cli/package.json
5237

5338
build-rust:
5439
name: Build bindings and binaries
55-
needs: prepare
40+
needs: check
41+
if: needs.check.outputs.version_changed == 'true'
5642
permissions:
5743
contents: read
5844
uses: ./.github/workflows/reusable-release-build.yml
5945
with:
60-
version: ${{ needs.prepare.outputs.version }}
46+
version: ${{ needs.check.outputs.version }}
6147
cache-key: release
6248

6349
request-approval:
6450
runs-on: ubuntu-latest
65-
needs: [prepare, build-rust]
51+
needs: [check, build-rust]
52+
if: needs.check.outputs.version_changed == 'true'
6653
steps:
6754
- uses: tsickert/discord-webhook@b217a69502f52803de774ded2b1ab7c282e99645 # v7.0.0
6855
with:
6956
webhook-url: ${{ secrets.DISCORD_RELEASES_WEBHOOK_URL }}
70-
content: 'Requesting approval: ${{ github.server_url }}/${{ github.repository }}/actions/workflows/release.yml'
57+
content: 'Requesting approval for vite-plus v${{ needs.check.outputs.version }}: ${{ github.server_url }}/${{ github.repository }}/actions/workflows/release.yml'
7158

7259
Release:
7360
runs-on: ubuntu-latest
7461
environment: release
75-
needs: [prepare, build-rust, request-approval]
62+
needs: [check, build-rust, request-approval]
63+
if: needs.check.outputs.version_changed == 'true'
7664
permissions:
7765
contents: write
7866
packages: write
7967
id-token: write # Required for OIDC
8068
env:
81-
VERSION: ${{ needs.prepare.outputs.version }}
69+
VERSION: ${{ needs.check.outputs.version }}
8270
steps:
8371
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2
8472
- uses: ./.github/actions/clone
@@ -168,22 +156,17 @@ jobs:
168156

169157
- name: Publish
170158
run: |
171-
pnpm publish --filter=./packages/core --tag "${NPM_TAG}" --access public --no-git-checks
172-
pnpm publish --filter=./packages/test --tag "${NPM_TAG}" --access public --no-git-checks
173-
pnpm publish --filter=./packages/cli --tag "${NPM_TAG}" --access public --no-git-checks
159+
pnpm publish --filter=./packages/core --tag latest --access public --no-git-checks
160+
pnpm publish --filter=./packages/test --tag latest --access public --no-git-checks
161+
pnpm publish --filter=./packages/cli --tag latest --access public --no-git-checks
174162
175163
- name: Create release body
176164
env:
177165
REPOSITORY: ${{ github.repository }}
178166
COMMIT_SHA: ${{ github.sha }}
179167
run: |
180-
if [[ "${NPM_TAG}" == "latest" ]]; then
181-
INSTALL_BASH="curl -fsSL https://vite.plus | bash"
182-
INSTALL_PS1="irm https://vite.plus/ps1 | iex"
183-
else
184-
INSTALL_BASH="curl -fsSL https://vite.plus | VP_VERSION=${VERSION} bash"
185-
INSTALL_PS1="\\\$env:VP_VERSION=\\\"${VERSION}\\\"; irm https://vite.plus/ps1 | iex"
186-
fi
168+
INSTALL_BASH="curl -fsSL https://vite.plus | bash"
169+
INSTALL_PS1="irm https://vite.plus/ps1 | iex"
187170
cat > ./RELEASE_BODY.md <<EOF
188171
## vite-plus v${VERSION}
189172
@@ -216,8 +199,8 @@ jobs:
216199
with:
217200
body_path: ./RELEASE_BODY.md
218201
draft: true
219-
make_latest: ${{ inputs.npm_tag == 'latest' }}
220-
prerelease: ${{ inputs.npm_tag == 'alpha' }}
202+
make_latest: true
203+
prerelease: false
221204
name: vite-plus v${{ env.VERSION }}
222205
tag_name: v${{ env.VERSION }}
223206
target_commitish: ${{ github.sha }}
@@ -230,7 +213,6 @@ jobs:
230213
run: gh release edit "v${VERSION}" --draft=false --repo "${{ github.repository }}"
231214

232215
- name: Send Discord notification
233-
if: ${{ inputs.npm_tag == 'latest' }}
234216
uses: tsickert/discord-webhook@b217a69502f52803de774ded2b1ab7c282e99645 # v7.0.0
235217
with:
236218
webhook-url: ${{ secrets.DISCORD_RELEASES_WEBHOOK_URL }}

packages/cli/publish-native-addons.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,7 @@ if (existsSync(rustCliArtifactsDir)) {
5353
}
5454
}
5555

56-
// Stamp VERSION into the publishable package.json files. napi prePublish and
57-
// the cli-binary packages below both read packages/cli/package.json#version.
58-
for (const p of ['core', 'test', 'cli']) {
59-
const pkgPath = join(repoRoot, 'packages', p, 'package.json');
60-
const content = readFileSync(pkgPath, 'utf-8');
61-
writeFileSync(pkgPath, content.replace('"version": "0.0.0"', `"version": "${VERSION}"`));
62-
}
63-
64-
// Build test package against the just-stamped versions.
56+
// Build test package — versions are already bumped on main by prepare_release.yml.
6557
execSync('pnpm --filter=@voidzero-dev/vite-plus-test build', {
6658
cwd: repoRoot,
6759
stdio: 'inherit',

0 commit comments

Comments
 (0)