From 8250a0e3b1b8cf2a41f5207cadf87cf841a0346a Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Mon, 21 Sep 2026 23:14:27 +0200 Subject: [PATCH] ci: publish the crate to crates.io on a v* tag Trusted publishing is GitHub-Actions-only, so authentication goes through a crates.io API token stored as the CARGO_REGISTRY_TOKEN secret, scoped to the pkh crate. The job gates on the build job and fails loudly when the tag does not match the version in Cargo.toml, since cargo publish ships the declared version regardless of the tag name. --- .github/workflows/ci.yml | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a74a9b8..6aa16dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,7 @@ name: CI on: push: branches: [ "main", "ci-test" ] + tags: [ "v*" ] pull_request: branches: [ "main" ] @@ -121,3 +122,41 @@ jobs: name: snap path: ./*.snap if-no-files-found: error + + publish: + # Publishes the crate to crates.io on a v* tag. Trusted publishing + # (OIDC) is GitHub-Actions-only, so authentication goes through a + # crates.io API token stored as the CARGO_REGISTRY_TOKEN secret, + # scoped to the pkh crate. + if: startsWith(github.ref, 'refs/tags/v') + needs: build + runs-on: ubuntu-latest + container: + image: ubuntu:26.04 + options: --privileged --cap-add SYS_ADMIN --security-opt apparmor:unconfined + steps: + - name: Set up container image + run: | + apt-get update + apt-get install -y nodejs sudo curl wget ca-certificates + - uses: actions/checkout@v6 + - uses: dtolnay/rust-toolchain@stable + - name: Install build dependencies + run: | + sudo apt-get update + sudo apt-get install -y pkg-config libssl-dev libgpg-error-dev libgpgme-dev + - name: Check the tag matches the crate version + # cargo publish ships whatever version Cargo.toml declares, + # regardless of the tag: a mismatch must fail loudly instead of + # publishing the wrong version under the release tag. + run: | + crate_version="$(awk -F'"' '/^version =/{print $2; exit}' Cargo.toml)" + tag_version="${GITHUB_REF_NAME#v}" + if [ "$crate_version" != "$tag_version" ]; then + echo "tag $GITHUB_REF_NAME does not match crate version $crate_version" >&2 + exit 1 + fi + - name: Publish + run: cargo publish + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}