Skip to content

Commit dbf15f5

Browse files
committed
publish to crates.io
Signed-off-by: Jorge Prendes <[email protected]>
1 parent f1a275e commit dbf15f5

File tree

4 files changed

+54
-41
lines changed

4 files changed

+54
-41
lines changed

.github/workflows/CargoPublish.yml

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
22

3-
name: Publish crates to intenral cargo registry
3+
name: Publish crates to crates.io
44

55
on:
66
workflow_dispatch:
7+
inputs:
8+
dry_run:
9+
description: "Run the release without actually releasing bits"
10+
type: boolean
11+
default: true
712
workflow_call:
13+
inputs:
14+
dry_run:
15+
description: "Run the release without actually releasing bits"
16+
type: boolean
17+
default: true
818

919
permissions:
1020
contents: read
@@ -14,8 +24,7 @@ jobs:
1424
publish-hyperlight-packages:
1525
runs-on: [self-hosted, Linux, X64, "1ES.Pool=hld-kvm-amd"]
1626

17-
# We should only publish from dev if minver contains `-preview`
18-
if: ${{ contains(github.ref, 'refs/heads/release/') }} || ${{ github.ref=='refs/heads/dev' }}
27+
if: ${{ startsWith(github.ref, 'refs/heads/release/v') || inputs.dry_run }}
1928

2029
steps:
2130
- uses: actions/checkout@v4
@@ -27,47 +36,31 @@ jobs:
2736
with:
2837
rust-toolchain: "1.81.0"
2938

30-
- name: Set up cargo workspaces version
39+
- name: Check crate versions
40+
shell: bash
3141
run: |
32-
cargo install cargo-workspaces
33-
cargo install minver_rs
34-
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
35-
git config --global user.Name "${{ github.actor }}"
36-
37-
- name: Set crate versions
38-
run: |
39-
git fetch --tags || true
40-
version=$(MINVER_TAG_PREFIX=v MINVER_AUTO_INCREMENT_LEVEL=Minor MINVER_PRERELEASE_IDENTIFIER=preview minver)
41-
echo "Setting version to $version"
42-
cargo ws version --force=hyperlight_* --no-git-commit --yes custom $version
43-
echo "HYPERLIGHT_VERSION=$version" >> "$GITHUB_ENV"
44-
45-
- name: Determine if we should publish crates
46-
run: |
47-
echo "github.ref=${{ github.ref }}"
48-
echo "HYPERLIGHT_VERSION=$HYPERLIGHT_VERSION"
49-
if [[ ${{ github.ref }} =~ 'refs/heads/release/' || ( ${{ github.ref }} == 'refs/heads/dev' && $HYPERLIGHT_VERSION =~ '-preview' ) ]]
50-
then
51-
echo "Setting SHOULD_PUBLISH in GITHUB_ENV"
52-
echo "SHOULD_PUBLISH=true" >> "$GITHUB_ENV"
42+
if ${{ inputs.dry_run }}; then
43+
VERSION=""
44+
else
45+
VERSION="${{ github.ref }}"
46+
VERSION="${VERSION#refs/heads/release/v}"
5347
fi
54-
# `allow-dirty` is needed in the publish below because we are using the `--no-git-commit`
55-
# option above to cover the case where no changes are made by cargo ws version because the version
56-
# is already correct
57-
- name: Publish hyperlight-flatbuffers
58-
if: ${{ env.SHOULD_PUBLISH == 'true' }}
59-
run: cargo publish --manifest-path ./src/hyperlight_common/Cargo.toml --registry hyperlight_packages --allow-dirty
48+
./dev/verify-version.sh "$VERSION" hyperlight-common hyperlight-guest hyperlight-host
49+
50+
- name: Publish hyperlight-common
51+
continue-on-error: ${{ inputs.dry_run }}
52+
run: cargo publish --manifest-path ./src/hyperlight_common/Cargo.toml ${{ inputs.dry_run && '--dry-run' || '' }}
6053

6154
- name: Publish hyperlight-guest
62-
if: ${{ env.SHOULD_PUBLISH == 'true' }}
63-
run: cargo publish --manifest-path ./src/hyperlight_guest/Cargo.toml --registry hyperlight_packages --allow-dirty
55+
continue-on-error: ${{ inputs.dry_run }}
56+
run: cargo publish --manifest-path ./src/hyperlight_guest/Cargo.toml ${{ inputs.dry_run && '--dry-run' || '' }}
6457

6558
- name: Publish hyperlight-host
66-
if: ${{ env.SHOULD_PUBLISH == 'true' }}
67-
run: cargo publish --manifest-path ./src/hyperlight_host/Cargo.toml --registry hyperlight_packages --allow-dirty
59+
continue-on-error: ${{ inputs.dry_run }}
60+
run: cargo publish --manifest-path ./src/hyperlight_host/Cargo.toml ${{ inputs.dry_run && '--dry-run' || '' }}
6861

69-
# `--no-verify` is needed because build.rs writes to "include/hyperlight_guest.h", but since we exclude that directory in Cargo.toml, it should be fine.
70-
# Cargo does not want you to modify files outside of OUT_DIR
71-
- name: Publish hyperlight-guest-capi
72-
if: ${{ env.SHOULD_PUBLISH == 'true' }}
73-
run: cd ./src/hyperlight_guest_capi && cargo publish --registry hyperlight_packages --no-verify --allow-dirty # cd is required because of https://github.com/rust-lang/cargo/issues/10302
62+
# TODO: Do we want to publish hyperlight-guest-capi to crates.io given that it's not for Rust consumption?
63+
# - name: Publish hyperlight-guest-capi
64+
# # `--no-verify` is needed because build.rs writes to "include/hyperlight_guest.h", but since we exclude that directory in Cargo.toml, it should be fine.
65+
# # Cargo does not want you to modify files outside of OUT_DIR
66+
# run: cd ./src/hyperlight_guest_capi && cargo publish --no-verify ${{ inputs.dry_run && '--dry-run' || '' }} # cd is required because of https://github.com/rust-lang/cargo/issues/10302

.github/workflows/CreateRelease.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ jobs:
8585
cargo-publish:
8686
needs: [publish]
8787
uses: ./.github/workflows/CargoPublish.yml
88+
with:
89+
dry_run: false
8890
secrets: inherit
8991
permissions:
9092
id-token: write

dev/verify-version.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
set -Eeuo pipefail
3+
cargo install -q jaq
4+
5+
EXPECTED="$1"
6+
EXPECTED="${EXPECTED#refs/heads/release/}"
7+
EXPECTED="${EXPECTED#v}"
8+
shift
9+
10+
for CRATE in "$@"; do
11+
VERSION=$(cargo metadata --format-version=1 2>/dev/null | jaq --raw-output '.packages[] | select(.name == "'$CRATE'").version')
12+
if [ "$VERSION" == "$EXPECTED" ] || [ "" == "$EXPECTED" ]; then
13+
echo -e " \u001b[1;32m✓\u001b[0m Crate \u001b[1m$CRATE\u001b[0m version is \u001b[1m$VERSION\u001b[0m"
14+
else
15+
echo -e " \u001b[1;31m✗\u001b[0m Crate \u001b[1m$CRATE\u001b[0m version is \u001b[1m$VERSION\u001b[0m, expected \u001b[1m$EXPECTED\u001b[0m"
16+
exit 1
17+
fi
18+
done

docs/how-to-make-releases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Releasing a new Hyperlight version to Cargo
22

3-
This document details the process of releasing a new version of Hyperlight to the [Azure-internal Cargo feeds](https://dev.azure.com/AzureContainerUpstream/hyperlight/_artifacts/feed/hyperlight_packages). It's intended to be used as a checklist for the developer doing the release. The checklist is represented in the below sections.
3+
This document details the process of releasing a new version of Hyperlight to [crates.io](https://crates.io). It's intended to be used as a checklist for the developer doing the release. The checklist is represented in the below sections.
44

55
## Update Cargo.toml Versions
66

0 commit comments

Comments
 (0)