feat: add CI step to publish to crates.io

This commit is contained in:
Manuel Raimann
2026-01-30 18:20:00 +01:00
parent 8f339a2341
commit 34d61bc544
2 changed files with 46 additions and 35 deletions
+46
View File
@@ -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 }}
-35
View File
@@ -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 }}