From 34d61bc544bc228af7cc65edda95971318e60703 Mon Sep 17 00:00:00 2001 From: Manuel Raimann Date: Fri, 30 Jan 2026 18:20:00 +0100 Subject: [PATCH] feat: add CI step to publish to crates.io --- .github/workflows/ci.yml | 46 +++++++++++++++++++++++++++++++++++ .github/workflows/publish.yml | 35 -------------------------- 2 files changed, 46 insertions(+), 35 deletions(-) delete mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc6df40..4627eed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -199,3 +199,49 @@ jobs: tool: typos-cli - name: Typos Check run: typos src/ + + publish: + name: Publish to crates.io + runs-on: ubuntu-latest + if: github.event_name == 'push' + needs: + - fmt + - clippy + - test + - docs + - feature-check + - coverage + - msrv + - deny + - semver + - minimal-versions + - cross-platform + - typos + steps: + - uses: actions/checkout@v6 + - name: Install Rust + run: | + rustup override set stable + rustup update stable + - uses: Swatinem/rust-cache@v2 + + - name: Check if version already published + id: check + run: | + CARGO_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version') + echo "version=$CARGO_VERSION" >> "$GITHUB_OUTPUT" + + HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://crates.io/api/v1/crates/optimizer/$CARGO_VERSION") + if [ "$HTTP_STATUS" = "200" ]; then + echo "Version $CARGO_VERSION already exists on crates.io, skipping publish" + echo "skip=true" >> "$GITHUB_OUTPUT" + else + echo "Version $CARGO_VERSION not found on crates.io, will publish" + echo "skip=false" >> "$GITHUB_OUTPUT" + fi + + - name: Publish + if: steps.check.outputs.skip == 'false' && github.ref == 'refs/heads/master' + run: cargo publish + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 3eff01f..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Publish - -on: - push: - tags: - - "v*" - -env: - CARGO_TERM_COLOR: always - -jobs: - publish: - name: Publish to crates.io - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - name: Install Rust - run: | - rustup override set stable - rustup update stable - - uses: Swatinem/rust-cache@v2 - - - name: Verify version matches tag - run: | - CARGO_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version') - TAG_VERSION="${GITHUB_REF_NAME#v}" - if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then - echo "Error: Cargo.toml version ($CARGO_VERSION) doesn't match tag ($TAG_VERSION)" - exit 1 - fi - - - name: Publish - run: cargo publish - env: - CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}