Skip to content

Commit

Permalink
publish to crates.io
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Prendes <[email protected]>
  • Loading branch information
jprendes committed Nov 5, 2024
1 parent f1a275e commit 59c3ab2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 41 deletions.
70 changes: 30 additions & 40 deletions .github/workflows/CargoPublish.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json

name: Publish crates to intenral cargo registry
name: Publish crates to crates.io

on:
workflow_dispatch:
inputs:
dry_run:
description: "Run the release without actually releasing bits"
type: boolean
default: true
workflow_call:
inputs:
dry_run:
description: "Run the release without actually releasing bits"
type: boolean
default: true

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

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

steps:
- uses: actions/checkout@v4
Expand All @@ -27,47 +36,28 @@ jobs:
with:
rust-toolchain: "1.81.0"

- name: Set up cargo workspaces version
- name: Check crate versions
# Don't check versions if we are running with dry-run, this allows testing from non-release branches
if: ${{ !inputs.dry_run }}
shell: bash
run: |
cargo install cargo-workspaces
cargo install minver_rs
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.Name "${{ github.actor }}"
set -Eeuo pipefail
VERSION="${{ github.ref }}"
VERSION="${VERSION#refs/heads/release/v}"
./dev/verify-version.sh $VERSION hyperlight-common hyperlight-guest hyperlight-host
echo "HYPERLIGHT_VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Set crate versions
run: |
git fetch --tags || true
version=$(MINVER_TAG_PREFIX=v MINVER_AUTO_INCREMENT_LEVEL=Minor MINVER_PRERELEASE_IDENTIFIER=preview minver)
echo "Setting version to $version"
cargo ws version --force=hyperlight_* --no-git-commit --yes custom $version
echo "HYPERLIGHT_VERSION=$version" >> "$GITHUB_ENV"
- name: Determine if we should publish crates
run: |
echo "github.ref=${{ github.ref }}"
echo "HYPERLIGHT_VERSION=$HYPERLIGHT_VERSION"
if [[ ${{ github.ref }} =~ 'refs/heads/release/' || ( ${{ github.ref }} == 'refs/heads/dev' && $HYPERLIGHT_VERSION =~ '-preview' ) ]]
then
echo "Setting SHOULD_PUBLISH in GITHUB_ENV"
echo "SHOULD_PUBLISH=true" >> "$GITHUB_ENV"
fi
# `allow-dirty` is needed in the publish below because we are using the `--no-git-commit`
# option above to cover the case where no changes are made by cargo ws version because the version
# is already correct
- name: Publish hyperlight-flatbuffers
if: ${{ env.SHOULD_PUBLISH == 'true' }}
run: cargo publish --manifest-path ./src/hyperlight_common/Cargo.toml --registry hyperlight_packages --allow-dirty
- name: Publish hyperlight-common
run: echo cargo publish --manifest-path ./src/hyperlight_common/Cargo.toml ${{ inputs.dry_run && '--dry-run' || '' }}

- name: Publish hyperlight-guest
if: ${{ env.SHOULD_PUBLISH == 'true' }}
run: cargo publish --manifest-path ./src/hyperlight_guest/Cargo.toml --registry hyperlight_packages --allow-dirty
run: echo cargo publish --manifest-path ./src/hyperlight_guest/Cargo.toml ${{ inputs.dry_run && '--dry-run' || '' }}

- name: Publish hyperlight-host
if: ${{ env.SHOULD_PUBLISH == 'true' }}
run: cargo publish --manifest-path ./src/hyperlight_host/Cargo.toml --registry hyperlight_packages --allow-dirty
run: echo cargo publish --manifest-path ./src/hyperlight_host/Cargo.toml ${{ inputs.dry_run && '--dry-run' || '' }}

# `--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.
# Cargo does not want you to modify files outside of OUT_DIR
- name: Publish hyperlight-guest-capi
if: ${{ env.SHOULD_PUBLISH == 'true' }}
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
# TODO: Do we want to publish hyperlight-guest-capi to crates.io given that it's not for Rust consumption?
# - name: Publish hyperlight-guest-capi
# # `--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.
# # Cargo does not want you to modify files outside of OUT_DIR
# 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
18 changes: 18 additions & 0 deletions dev/verify-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -Eeuo pipefail
cargo install -q jaq

EXPECTED="$1"
EXPECTED="${EXPECTED#refs/heads/release/}"
EXPECTED="${EXPECTED#v}"
shift

for CRATE in "$@"; do
VERSION=$(cargo metadata --format-version=1 2>/dev/null | jaq --raw-output '.packages[] | select(.name == "'$CRATE'").version')
if [ "$VERSION" == "$EXPECTED" ]; then
echo -e " \u001b[1;32m✓\u001b[0m Crate \u001b[1m$CRATE\u001b[0m version is \u001b[1m$VERSION\u001b[0m"
else
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"
exit 1
fi
done
2 changes: 1 addition & 1 deletion docs/how-to-make-releases.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Releasing a new Hyperlight version to Cargo

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.
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.

## Update Cargo.toml Versions

Expand Down

0 comments on commit 59c3ab2

Please sign in to comment.