Skip to content

Commit 72f69df

Browse files
authored
Use the needs_publish (from hyperlight) in CrateRelease workflow (#172)
* Use the needs_publish from hyperlight Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> * fix dry run of cargo crates Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> --------- Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
1 parent 95ad272 commit 72f69df

6 files changed

Lines changed: 126 additions & 30 deletions

File tree

.github/workflows/CreateRelease.yml

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
secrets: inherit
1818
with:
1919
environment: release
20+
2021
benchmarks:
2122
uses: ./.github/workflows/dep_benchmarks.yml
2223
secrets: inherit
@@ -51,36 +52,13 @@ jobs:
5152
echo "Setting version to 'v$version'"
5253
echo "version=$version" >> $GITHUB_OUTPUT
5354
54-
publish-hyperlight-js-packages-and-create-release:
55+
create-gh-release:
5556
needs: [build, benchmarks, set-version]
5657
environment: release
57-
runs-on: [self-hosted, Linux, X64, "1ES.Pool=hld-kvm-amd", "JobId=publish-hyperlight-js-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}"]
58+
runs-on: ubuntu-latest
5859
if: ${{ contains(github.ref, 'refs/heads/release/') }}
5960

6061
steps:
61-
- uses: actions/checkout@v6
62-
with:
63-
fetch-depth: 0
64-
fetch-tags: true
65-
66-
# Ensures just is installed using setup wokflow to ensure just version consistency
67-
- name: Hyperlight setup
68-
uses: hyperlight-dev/ci-setup-workflow@v1.9.0
69-
with:
70-
rust-toolchain: "1.89"
71-
just-version: "1.51"
72-
73-
- name: Authenticate with crates.io
74-
uses: rust-lang/crates-io-auth-action@v1
75-
id: crates-io-auth
76-
77-
- name: Publish hyperlight-js
78-
run: |
79-
cargo publish -p hyperlight-js-runtime
80-
cargo publish -p hyperlight-js
81-
env:
82-
CARGO_REGISTRY_TOKEN: ${{ steps.crates-io-auth.outputs.token }}
83-
8462
- name: Download benchmarks (Windows)
8563
uses: actions/download-artifact@v8
8664
with:
@@ -116,8 +94,15 @@ jobs:
11694
GH_TOKEN: ${{ github.token }}
11795

11896
publish-npm-packages:
119-
needs: [set-version]
97+
needs: [build, benchmarks, set-version]
12098
uses: ./.github/workflows/npm-publish.yml
12199
with:
122100
version: ${{ needs.set-version.outputs.version }}
123101
dry-run: ${{ !contains(github.ref, 'refs/heads/release/') }}
102+
103+
publish-cargo-crates:
104+
needs: [build, benchmarks, set-version]
105+
uses: ./.github/workflows/cargo-publish.yml
106+
with:
107+
version: ${{ needs.set-version.outputs.version }}
108+
dry-run: ${{ !contains(github.ref, 'refs/heads/release/') }}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
# 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.
20+
# Calling this workflow from a different parent workflow will fail OIDC auth.
21+
# See: https://docs.npmjs.com/trusted-publishers#troubleshooting
22+
workflow_call:
23+
inputs:
24+
version:
25+
description: 'Version to publish'
26+
required: true
27+
type: string
28+
dry-run:
29+
description: 'Dry run (skip actual publish)'
30+
required: false
31+
type: boolean
32+
default: true
33+
34+
permissions:
35+
contents: read
36+
id-token: write
37+
38+
jobs:
39+
publish-hyperlight-packages:
40+
runs-on: ubuntu-latest
41+
42+
steps:
43+
- uses: actions/checkout@v6
44+
with:
45+
fetch-depth: 0
46+
fetch-tags: true
47+
48+
# Ensures just is installed using setup wokflow to ensure just version consistency
49+
- name: Hyperlight setup
50+
uses: hyperlight-dev/ci-setup-workflow@v1.9.0
51+
with:
52+
rust-toolchain: "1.90"
53+
just-version: "1.51"
54+
55+
- name: Install cargo-overlay-registry
56+
run: cargo install cargo-overlay-registry
57+
58+
- name: Determine which crates need publishing
59+
env:
60+
VERSION: ${{ inputs.version }}
61+
shell: bash
62+
run: |
63+
needs_publish() {
64+
local crate=$1
65+
local crate_env_var=$(echo "$crate" | tr '[:lower:]' '[:upper:]' | tr '-' '_')
66+
67+
if [ -z "$VERSION" ] || [ "$VERSION" == "v0.0.0" ] || [ "$VERSION" == "0.0.0" ]; then
68+
echo "No version set (dry run?), skipping crates.io existence checks."
69+
echo "PUBLISH_${crate_env_var}=true" >> "$GITHUB_ENV"
70+
return
71+
fi
72+
73+
if curl -s "https://crates.io/api/v1/crates/$crate/$VERSION" | jq -e .version > /dev/null; then
74+
echo "PUBLISH_${crate_env_var}=false" >> "$GITHUB_ENV"
75+
echo "✅ $crate@$VERSION already exists."
76+
else
77+
echo "PUBLISH_${crate_env_var}=true" >> "$GITHUB_ENV"
78+
echo "🚀 $crate@$VERSION will be published."
79+
fi
80+
}
81+
82+
needs_publish hyperlight-js-runtime
83+
needs_publish hyperlight-js
84+
85+
- name: Dry run publishing
86+
shell: bash
87+
run: |
88+
cargo-overlay-registry \
89+
-r local \
90+
-r local=./target/package/tmp-registry/ \
91+
-r crates.io \
92+
-- \
93+
cargo publish --workspace --dry-run \
94+
-p hyperlight-js \
95+
-p hyperlight-js-runtime
96+
97+
- name: Authenticate with crates.io
98+
uses: rust-lang/crates-io-auth-action@v1
99+
id: crates-io-auth
100+
101+
- name: Publish hyperlight-js-runtime
102+
run: cargo publish -p hyperlight-js-runtime
103+
env:
104+
CARGO_REGISTRY_TOKEN: ${{ steps.crates-io-auth.outputs.token }}
105+
if: ${{ env.PUBLISH_HYPERLIGHT_JS_RUNTIME != 'false' && !inputs['dry-run'] }}
106+
107+
- name: Publish hyperlight-js
108+
run: cargo publish -p hyperlight-js
109+
env:
110+
CARGO_REGISTRY_TOKEN: ${{ steps.crates-io-auth.outputs.token }}
111+
if: ${{ env.PUBLISH_HYPERLIGHT_JS != 'false' && !inputs['dry-run'] }}

.github/workflows/dep_benchmarks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656

5757
- uses: hyperlight-dev/ci-setup-workflow@v1.9.0
5858
with:
59-
rust-toolchain: "1.89"
59+
rust-toolchain: "1.90"
6060
just-version: "1.51"
6161

6262
- name: Install github-cli (Azure Linux)

.github/workflows/dep_build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161

6262
- uses: hyperlight-dev/ci-setup-workflow@v1.9.0
6363
with:
64-
rust-toolchain: "1.89"
64+
rust-toolchain: "1.90"
6565
just-version: "1.51"
6666

6767
- name: install nodejs

.github/workflows/npm-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
- name: Hyperlight setup
6767
uses: hyperlight-dev/ci-setup-workflow@v1.9.0
6868
with:
69-
rust-toolchain: "1.89"
69+
rust-toolchain: "1.90"
7070
just-version: "1.51"
7171

7272
- name: Setup Node.js

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[toolchain]
2-
channel = "1.89"
2+
channel = "1.90"

0 commit comments

Comments
 (0)