diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..9792fe2 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,38 @@ +name: Publish to crates.io + +on: + release: + types: [published] + +jobs: + publish-crate: + runs-on: ubuntu-latest + environment: release + permissions: + contents: read + # Required for OIDC token exchange + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Crates.io authentication + uses: rust-lang/crates-io-auth-action@b7e9a28eded4986ec6b1fa40eeee8f8f165559ec # v1.0.3 + id: auth + + - name: Verify version matches tag + run: | + CARGO_VERSION=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)".*/\1/') + TAG_VERSION="${GITHUB_REF_NAME#v}" + echo "Cargo.toml version: $CARGO_VERSION" + echo "Git tag version: $TAG_VERSION" + if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then + echo "Error: Cargo.toml version ($CARGO_VERSION) does not match tag ($TAG_VERSION)" + exit 1 + fi + + - name: Publish to crates.io + run: cargo publish + env: + CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}