name: Release
on:
release:
types: [published]
permissions:
contents: read
concurrency:
group: release-${{ github.event.release.tag_name }}
cancel-in-progress: false
jobs:
validate:
runs-on: ubuntu-latest
timeout-minutes: 20
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
K8S_OPENAPI_ENABLED_VERSION: "1.36"
steps:
- name: Checkout release tag
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
ref: ${{ env.RELEASE_TAG }}
persist-credentials: false
- name: Validate tag and Cargo version
shell: bash
run: |
if ! [[ "$RELEASE_TAG" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
echo "::error::'$RELEASE_TAG' is not a release tag like v0.1.0"
exit 1
fi
cargo_version="$(python3 -c 'import tomllib; print(tomllib.load(open("Cargo.toml", "rb"))["package"]["version"])')"
if [[ "$cargo_version" != "${RELEASE_TAG#v}" ]]; then
echo "::error::Cargo.toml version '$cargo_version' does not match '$RELEASE_TAG'"
exit 1
fi
- name: Read Rust toolchain
id: rust
run: |
python3 -c 'import tomllib; print("version=" + tomllib.load(open("rust-toolchain.toml", "rb"))["toolchain"]["channel"])' >> "$GITHUB_OUTPUT"
- name: Install Rust
uses: dtolnay/rust-toolchain@6bed0761d98439e5a578e2877258200ad565ba87
with:
toolchain: ${{ steps.rust.outputs.version }}
components: rustfmt, clippy
- name: Check formatting
run: cargo fmt --all -- --check
- name: Clippy
run: cargo clippy --locked --all-targets -- -D warnings
- name: Test
run: cargo test --locked
- name: Verify crate package
run: cargo publish --locked --dry-run
crates-publish:
needs: validate
runs-on: ubuntu-latest
timeout-minutes: 20
environment: release
permissions:
contents: read
id-token: write
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
K8S_OPENAPI_ENABLED_VERSION: "1.36"
steps:
- name: Checkout release tag
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
ref: ${{ env.RELEASE_TAG }}
persist-credentials: false
- name: Read Rust toolchain
id: rust
run: |
python3 -c 'import tomllib; print("version=" + tomllib.load(open("rust-toolchain.toml", "rb"))["toolchain"]["channel"])' >> "$GITHUB_OUTPUT"
- name: Install Rust
uses: dtolnay/rust-toolchain@6bed0761d98439e5a578e2877258200ad565ba87
with:
toolchain: ${{ steps.rust.outputs.version }}
- name: Authenticate to crates.io
id: auth
uses: rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
run: cargo publish --locked