Skip to content

Release

Release #36

Workflow file for this run

# Automates crate publishing
# - Specify crate and version from the menu.
# - Launch the job:
# + Updates Cargo.toml with the specified version
# + Commits and pushes the version bump
# + Publishes to crates.io
# + Adds and pushes a git tag "<crate>-v<version>"
name: Release
on:
workflow_dispatch:
inputs:
crate:
description: "Crate to publish"
required: true
type: choice
options:
- client
- logging
- runc
- runc-shim
- shim
- shim-protos
- snapshots
version:
description: "Version to publish (e.g. 0.8.1)"
required: true
type: string
dryrun:
description: "Dry run"
required: false
type: boolean
default: false
jobs:
publish:
name: "Publish ${{ inputs.crate }} v${{ inputs.version }}"
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
env:
CARGO_FILE: "crates/${{ inputs.crate }}/Cargo.toml"
steps:
- uses: actions/checkout@v6
- name: Validate version
env:
VERSION: ${{ inputs.version }}
run: |
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then
echo "::error::Invalid version: $VERSION (expected semver, e.g. 0.8.1 or 1.0.0-rc.1)"
exit 1
fi
- name: Update crate version
env:
VERSION: ${{ inputs.version }}
run: sed -i "s/^version = \".*\"/version = \"$VERSION\"/" $CARGO_FILE
- name: Commit version bump
env:
CRATE: ${{ inputs.crate }}
VERSION: ${{ inputs.version }}
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git add $CARGO_FILE
if git diff --cached --quiet; then
echo "Version already at v$VERSION, skipping commit"
else
git commit -m "Bump $CRATE to v$VERSION"
fi
- name: Install protobuf
if: ${{ contains(fromJSON('["client","snapshots"]'), inputs.crate) }}
run: |
sudo apt update
sudo apt install protobuf-compiler
- name: Publish on crates.io
run: cargo publish $DRYRUN --manifest-path $CARGO_FILE
env:
DRYRUN: ${{ inputs.dryrun && '--dry-run' || '' }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Push commit and tag
if: ${{ !inputs.dryrun }}
env:
TAG: ${{ inputs.crate }}-v${{ inputs.version }}
run: |
git tag $TAG
git push --atomic origin HEAD $TAG