Skip to content

Commit f3f298e

Browse files
authored
publish when tag is pushed (#174)
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
1 parent 72f69df commit f3f298e

6 files changed

Lines changed: 114 additions & 87 deletions

File tree

.github/workflows/CreateRelease.yml

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ on:
66
workflow_dispatch:
77
push:
88
branches: [main]
9+
tags:
10+
- "v*"
911

1012
permissions:
11-
id-token: write
13+
id-token: write # needed for trusted publishing (OIDC) to npm and crates.io
1214
contents: write # needed to create a release
1315

1416
jobs:
@@ -30,6 +32,7 @@ jobs:
3032
runs-on: ubuntu-latest
3133
outputs:
3234
version: ${{ steps.set-version.outputs.version }}
35+
dry_run: ${{ steps.set-version.outputs.dry_run }}
3336

3437
steps:
3538
- uses: actions/checkout@v6
@@ -42,67 +45,50 @@ jobs:
4245
shell: bash
4346
run: |
4447
git fetch --tags || true
45-
# Extract the version number from the branch name, which is expected to be in the format 'release/vX.Y.Z'
48+
# Extract the version number from the tag name, which is expected to be in the format 'vX.Y.Z'
4649
# if not, default to '0.0.0' to avoid errors in subsequent steps
47-
if [[ "${GITHUB_REF}" =~ refs/heads/release/v([0-9]+\.[0-9]+\.[0-9]+) ]]; then
50+
if [[ "${GITHUB_REF}" =~ refs/tags/v([0-9]+\.[0-9]+\.[0-9]+) ]]; then
4851
version="${BASH_REMATCH[1]}"
52+
dry_run=false
4953
else
5054
version="0.0.0"
55+
dry_run=true
5156
fi
5257
echo "Setting version to 'v$version'"
5358
echo "version=$version" >> $GITHUB_OUTPUT
59+
echo "dry_run=$dry_run" >> $GITHUB_OUTPUT
5460
55-
create-gh-release:
61+
create-release-branch:
5662
needs: [build, benchmarks, set-version]
57-
environment: release
5863
runs-on: ubuntu-latest
59-
if: ${{ contains(github.ref, 'refs/heads/release/') }}
64+
if: ${{ needs.set-version.outputs.dry_run == 'false' }}
6065

6166
steps:
62-
- name: Download benchmarks (Windows)
63-
uses: actions/download-artifact@v8
64-
with:
65-
name: benchmarks_Windows_whp
66-
path: benchmarks_Windows_whp
67-
68-
- name: Download benchmarks (Linux kvm)
69-
uses: actions/download-artifact@v8
70-
with:
71-
name: benchmarks_Linux_kvm
72-
path: benchmarks_Linux_kvm
67+
- uses: actions/checkout@v6
7368

74-
- name: Download benchmarks (Linux hyperv3)
75-
uses: actions/download-artifact@v8
76-
with:
77-
name: benchmarks_Linux_hyperv3
78-
path: benchmarks_Linux_hyperv3
79-
80-
- name: Archive benchmarks
69+
- name: Create Release Branch
70+
shell: bash
8171
run: |
82-
tar -zcvf benchmarks_Windows_whp.tar.gz benchmarks_Windows_whp
83-
tar -zcvf benchmarks_Linux_kvm.tar.gz benchmarks_Linux_kvm
84-
tar -zcvf benchmarks_Linux_hyperv3.tar.gz benchmarks_Linux_hyperv3
72+
git checkout -b release/v${{ needs.set-version.outputs.version }}
73+
git push --set-upstream origin release/v${{ needs.set-version.outputs.version }}
8574
86-
- name: Create GH Release
87-
run: |
88-
gh release create ${{ needs.set-version.outputs.version }} \
89-
--generate-notes \
90-
benchmarks_Windows_whp.tar.gz \
91-
benchmarks_Linux_kvm.tar.gz \
92-
benchmarks_Linux_hyperv3.tar.gz
93-
env:
94-
GH_TOKEN: ${{ github.token }}
75+
publish-gh-release:
76+
needs: [build, benchmarks, set-version]
77+
uses: ./.github/workflows/gh-publish.yml
78+
with:
79+
version: ${{ needs.set-version.outputs.version }}
80+
dry_run: ${{ needs.set-version.outputs.dry_run != 'false' }}
9581

9682
publish-npm-packages:
9783
needs: [build, benchmarks, set-version]
9884
uses: ./.github/workflows/npm-publish.yml
9985
with:
10086
version: ${{ needs.set-version.outputs.version }}
101-
dry-run: ${{ !contains(github.ref, 'refs/heads/release/') }}
87+
dry_run: ${{ needs.set-version.outputs.dry_run != 'false' }}
10288

10389
publish-cargo-crates:
10490
needs: [build, benchmarks, set-version]
10591
uses: ./.github/workflows/cargo-publish.yml
10692
with:
10793
version: ${{ needs.set-version.outputs.version }}
108-
dry-run: ${{ !contains(github.ref, 'refs/heads/release/') }}
94+
dry_run: ${{ needs.set-version.outputs.dry_run != 'false' }}

.github/workflows/CreateReleaseBranch.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/cargo-publish.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ on:
99
description: 'Version to publish (e.g., 0.2.0)'
1010
required: true
1111
type: string
12-
dry-run:
12+
dry_run:
1313
description: 'Dry run (skip actual publish)'
1414
required: false
1515
type: boolean
1616
default: false
17-
# IMPORTANT: Trusted publishing (OIDC) is configured on npmjs.com with
18-
# workflow filename 'CreateRelease.yml'. npm checks the *calling* workflow
19-
# for workflow_call, not the reusable workflow that runs npm publish.
17+
# IMPORTANT: Trusted publishing (OIDC) is configured on crates.io with
18+
# workflow filename 'CreateRelease.yml'. crates.io checks the *calling* workflow
19+
# for workflow_call, not the reusable workflow that runs cargo publish.
2020
# Calling this workflow from a different parent workflow will fail OIDC auth.
21-
# See: https://docs.npmjs.com/trusted-publishers#troubleshooting
21+
# See: https://crates.io/docs/trusted-publishing
2222
workflow_call:
2323
inputs:
2424
version:
2525
description: 'Version to publish'
2626
required: true
2727
type: string
28-
dry-run:
28+
dry_run:
2929
description: 'Dry run (skip actual publish)'
3030
required: false
3131
type: boolean
@@ -70,7 +70,7 @@ jobs:
7070
return
7171
fi
7272
73-
if curl -s "https://crates.io/api/v1/crates/$crate/$VERSION" | jq -e .version > /dev/null; then
73+
if cargo info --locked -q "$crate"@"$VERSION" > /dev/null; then
7474
echo "PUBLISH_${crate_env_var}=false" >> "$GITHUB_ENV"
7575
echo "✅ $crate@$VERSION already exists."
7676
else
@@ -102,10 +102,10 @@ jobs:
102102
run: cargo publish -p hyperlight-js-runtime
103103
env:
104104
CARGO_REGISTRY_TOKEN: ${{ steps.crates-io-auth.outputs.token }}
105-
if: ${{ env.PUBLISH_HYPERLIGHT_JS_RUNTIME != 'false' && !inputs['dry-run'] }}
105+
if: ${{ env.PUBLISH_HYPERLIGHT_JS_RUNTIME != 'false' && !inputs.dry_run }}
106106

107107
- name: Publish hyperlight-js
108108
run: cargo publish -p hyperlight-js
109109
env:
110110
CARGO_REGISTRY_TOKEN: ${{ steps.crates-io-auth.outputs.token }}
111-
if: ${{ env.PUBLISH_HYPERLIGHT_JS != 'false' && !inputs['dry-run'] }}
111+
if: ${{ env.PUBLISH_HYPERLIGHT_JS != 'false' && !inputs.dry_run }}

.github/workflows/gh-publish.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
3+
name: Publish npm packages
4+
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Version to publish (e.g., 0.2.0)'
10+
required: true
11+
type: string
12+
dry_run:
13+
description: 'Dry run (skip actual publish)'
14+
required: false
15+
type: boolean
16+
default: false
17+
workflow_call:
18+
inputs:
19+
version:
20+
description: 'Version to publish'
21+
required: true
22+
type: string
23+
dry_run:
24+
description: 'Dry run (skip actual publish)'
25+
required: false
26+
type: boolean
27+
default: true
28+
29+
permissions:
30+
contents: write
31+
32+
jobs:
33+
create-gh-release:
34+
environment: release
35+
runs-on: ubuntu-latest
36+
37+
steps:
38+
- name: Download benchmarks (Windows)
39+
uses: actions/download-artifact@v8
40+
with:
41+
name: benchmarks_Windows_whp
42+
path: benchmarks_Windows_whp
43+
44+
- name: Download benchmarks (Linux kvm)
45+
uses: actions/download-artifact@v8
46+
with:
47+
name: benchmarks_Linux_kvm
48+
path: benchmarks_Linux_kvm
49+
50+
- name: Download benchmarks (Linux hyperv3)
51+
uses: actions/download-artifact@v8
52+
with:
53+
name: benchmarks_Linux_hyperv3
54+
path: benchmarks_Linux_hyperv3
55+
56+
- name: Archive benchmarks
57+
run: |
58+
tar -zcvf benchmarks_Windows_whp.tar.gz benchmarks_Windows_whp
59+
tar -zcvf benchmarks_Linux_kvm.tar.gz benchmarks_Linux_kvm
60+
tar -zcvf benchmarks_Linux_hyperv3.tar.gz benchmarks_Linux_hyperv3
61+
62+
- name: Create GH Release
63+
if: ${{ inputs.dry_run == 'false' }}
64+
run: |
65+
gh release create ${{ inputs.version }} \
66+
--generate-notes \
67+
benchmarks_Windows_whp.tar.gz \
68+
benchmarks_Linux_kvm.tar.gz \
69+
benchmarks_Linux_hyperv3.tar.gz
70+
env:
71+
GH_TOKEN: ${{ github.token }}

.github/workflows/npm-publish.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
description: 'Version to publish (e.g., 0.2.0)'
1010
required: true
1111
type: string
12-
dry-run:
12+
dry_run:
1313
description: 'Dry run (skip actual publish)'
1414
required: false
1515
type: boolean
@@ -25,7 +25,7 @@ on:
2525
description: 'Version to publish'
2626
required: true
2727
type: string
28-
dry-run:
28+
dry_run:
2929
description: 'Dry run (skip actual publish)'
3030
required: false
3131
type: boolean
@@ -251,7 +251,7 @@ jobs:
251251
# You should almost never need to publish manually — if you do,
252252
# see docs/release.md for the full (deliberately painful) steps.
253253
- name: Validate NPM_TOKEN for manual dispatch
254-
if: ${{ github.event_name == 'workflow_dispatch' && !inputs['dry-run'] }}
254+
if: ${{ github.event_name == 'workflow_dispatch' && !inputs.dry_run }}
255255
run: |
256256
if [ -z "$NPM_TOKEN" ]; then
257257
echo "::error::NPM_TOKEN repo secret is required for manual workflow_dispatch publishing."
@@ -273,35 +273,35 @@ jobs:
273273
fi
274274
275275
- name: Publish Linux GNU package
276-
if: ${{ !inputs['dry-run'] }}
276+
if: ${{ !inputs.dry_run }}
277277
working-directory: ${{ env.WORKING_DIR }}/npm/linux-x64-gnu
278278
run: npm publish --access public --ignore-scripts ${{ steps.publish-flags.outputs.provenance }}
279279
env:
280280
NODE_AUTH_TOKEN: ${{ github.event_name == 'workflow_dispatch' && secrets.NPM_TOKEN || '' }}
281281

282282
- name: Publish Linux musl package
283-
if: ${{ !inputs['dry-run'] }}
283+
if: ${{ !inputs.dry_run }}
284284
working-directory: ${{ env.WORKING_DIR }}/npm/linux-x64-musl
285285
run: npm publish --access public --ignore-scripts ${{ steps.publish-flags.outputs.provenance }}
286286
env:
287287
NODE_AUTH_TOKEN: ${{ github.event_name == 'workflow_dispatch' && secrets.NPM_TOKEN || '' }}
288288

289289
- name: Publish Windows package
290-
if: ${{ !inputs['dry-run'] }}
290+
if: ${{ !inputs.dry_run }}
291291
working-directory: ${{ env.WORKING_DIR }}/npm/win32-x64-msvc
292292
run: npm publish --access public --ignore-scripts ${{ steps.publish-flags.outputs.provenance }}
293293
env:
294294
NODE_AUTH_TOKEN: ${{ github.event_name == 'workflow_dispatch' && secrets.NPM_TOKEN || '' }}
295295

296296
- name: Publish main package
297-
if: ${{ !inputs['dry-run'] }}
297+
if: ${{ !inputs.dry_run }}
298298
working-directory: ${{ env.WORKING_DIR }}
299299
run: npm publish --access public --ignore-scripts ${{ steps.publish-flags.outputs.provenance }}
300300
env:
301301
NODE_AUTH_TOKEN: ${{ github.event_name == 'workflow_dispatch' && secrets.NPM_TOKEN || '' }}
302302

303303
- name: Verify all packages published
304-
if: ${{ !inputs['dry-run'] }}
304+
if: ${{ !inputs.dry_run }}
305305
run: |
306306
echo "Waiting for registry propagation..."
307307
sleep 15
@@ -325,7 +325,7 @@ jobs:
325325
VERSION: ${{ inputs.version }}
326326

327327
- name: Dry run - show what would be published
328-
if: ${{ inputs['dry-run'] }}
328+
if: ${{ inputs.dry_run }}
329329
working-directory: ${{ env.WORKING_DIR }}
330330
run: |
331331
echo "=== DRY RUN - Would publish the following packages ==="

docs/release.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ If you need to publish npm packages manually via `workflow_dispatch`, you'll nee
110110
- Go to Actions → "Publish npm packages" → Run workflow
111111
- Select the correct branch
112112
- Enter the version (e.g. `0.2.1`)
113-
- Set `dry-run` to `false`
113+
- Set `dry_run` to `false`
114114

115115
5. **Clean up immediately after publishing**
116116
- Delete the `NPM_TOKEN` repo secret on GitHub → Settings → Secrets and variables → Actions

0 commit comments

Comments
 (0)