@setoelkahfi / sigit / commits / 1a31d48

release crate

Seto Elkahfi committed May 29, 2026 at 17:45 UTC 1a31d48c12dbfccf1ea887fc0e5edd50e87c6a67
1 file changed +70
.github/workflows/release-crates.yml
+70
new file mode 100644 index 0000000..335cc12 --- /dev/null +++ b/.github/workflows/release-crates.yml @@ -0,0 +1,70 @@ +name: Crates.io Release + +on: + push: + tags: + - "v*.*.*" + workflow_dispatch: + inputs: + tag: + description: "Release tag (e.g. v1.0.2)" + required: true + +permissions: + contents: read + +env: + CARGO_TERM_COLOR: always + +jobs: + publish: + name: Publish to crates.io + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + ref: ${{ github.event.inputs.tag || github.ref }} + + - name: Read Rust toolchain + shell: bash + run: | + rust_toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n 1)" + if [ -z "$rust_toolchain" ]; then + echo "Failed to read Rust toolchain from rust-toolchain.toml" >&2 + exit 1 + fi + echo "RUST_TOOLCHAIN=${rust_toolchain}" >> "$GITHUB_ENV" + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9 + with: + toolchain: ${{ env.RUST_TOOLCHAIN }} + + - name: Setup Rust cache + uses: Swatinem/rust-cache@v2 + with: + key: crates-publish + + - name: Check whether version already exists on crates.io + id: crates-check + shell: bash + run: | + VERSION=$(cargo metadata --no-deps --format-version 1 | \ + python3 -c "import sys,json; pkgs=json.load(sys.stdin)['packages']; \ + print(next(p['version'] for p in pkgs if p['name']=='sigit'))") + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" + + if curl -fsS "https://crates.io/api/v1/crates/sigit/${VERSION}" >/dev/null 2>&1; then + echo "sigit ${VERSION} already exists on crates.io, skipping publish" + echo "exists=true" >> "$GITHUB_OUTPUT" + else + echo "exists=false" >> "$GITHUB_OUTPUT" + fi + + - name: Publish to crates.io + if: steps.crates-check.outputs.exists != 'true' + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + run: cargo publish --locked