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