name: release
on:
push:
tags:
- "v*"
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Tests
env:
CARGO_INCREMENTAL: "0"
run: cargo test --all-features
parity:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Python dependencies
run: python3 -m pip install --upgrade pip && python3 -m pip install -r tests/parity/requirements.txt
- name: Parity tests
env:
CARGO_INCREMENTAL: "0"
run: |
bash tests/parity/run_parity.sh phase1
bash tests/parity/run_parity.sh phase2
bash tests/parity/run_parity.sh phase3
bash tests/parity/run_parity.sh phase4
bash tests/parity/run_parity.sh phase5
bash tests/parity/run_parity.sh phase6
package:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Package (dry run)
env:
CARGO_INCREMENTAL: "0"
run: cargo package
publish:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
needs: [test, parity, package]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Read crate version
id: crate_version
run: |
set -euo pipefail
version=$(cargo metadata --no-deps --format-version 1 | \
python3 -c "import json,sys; pkgs=json.load(sys.stdin)['packages']; print(next(p['version'] for p in pkgs if p['name']=='click-rs'))")
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Check if version exists on crates.io
id: version_check
run: |
set -euo pipefail
version="${{ steps.crate_version.outputs.version }}"
if curl -sfL "https://crates.io/api/v1/crates/click-rs/${version}"; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Skip publish (version exists)
if: steps.version_check.outputs.exists == 'true'
run: echo "crate version already published; skipping cargo publish"
- name: Authenticate with crates.io
id: auth
uses: rust-lang/crates-io-auth-action@v1
if: steps.version_check.outputs.exists != 'true'
- name: Publish to crates.io
env:
CARGO_INCREMENTAL: "0"
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
run: cargo publish -p click-rs --locked
if: steps.version_check.outputs.exists != 'true'
create-release:
runs-on: ubuntu-latest
permissions:
contents: write
needs: [test, parity, package, publish]
steps:
- uses: actions/checkout@v4
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true