|
| 1 | +name: Publish Rust client to crates.io |
| 2 | + |
| 3 | +# Language-specific publish workflow for the Rust client. It is triggered manually only |
| 4 | +# (workflow_dispatch) so a maintainer deliberately decides when a release is cut. Publishing |
| 5 | +# to the crates.io registry is the language-specific distribution standard for Rust. |
| 6 | +on: |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + dry_run: |
| 10 | + description: 'Run `cargo publish --dry-run` only (no actual release).' |
| 11 | + type: boolean |
| 12 | + default: false |
| 13 | + |
| 14 | +# Never allow two publish runs to race; a half-finished publish to a registry is hard to undo. |
| 15 | +concurrency: |
| 16 | + group: rust-publish |
| 17 | + cancel-in-progress: false |
| 18 | + |
| 19 | +jobs: |
| 20 | + publish: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Install Rust toolchain |
| 27 | + uses: dtolnay/rust-toolchain@stable |
| 28 | + with: |
| 29 | + components: rustfmt, clippy |
| 30 | + |
| 31 | + - name: Cache cargo registry and build |
| 32 | + uses: actions/cache@v4 |
| 33 | + with: |
| 34 | + path: | |
| 35 | + ~/.cargo/registry |
| 36 | + ~/.cargo/git |
| 37 | + target |
| 38 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }} |
| 39 | + |
| 40 | + # Gate the release on the same quality bar as CI so a broken build can never be published. |
| 41 | + - name: Check formatting |
| 42 | + run: cargo fmt --all -- --check |
| 43 | + |
| 44 | + - name: Clippy (deny warnings) |
| 45 | + run: cargo clippy --all-targets -- -D warnings |
| 46 | + |
| 47 | + - name: Build |
| 48 | + run: cargo build --verbose |
| 49 | + |
| 50 | + # Fail early with a clear message if the registry token is not configured, instead of |
| 51 | + # letting `cargo publish` fail later with a less obvious authentication error. |
| 52 | + - name: Require CARGO_REGISTRY_TOKEN secret |
| 53 | + env: |
| 54 | + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
| 55 | + run: | |
| 56 | + if [ -z "${CARGO_REGISTRY_TOKEN}" ]; then |
| 57 | + echo "::error::CARGO_REGISTRY_TOKEN secret is empty or missing; cannot publish to crates.io." |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | +
|
| 61 | + # Always verify packaging works (this also runs as part of `cargo publish`, but doing it |
| 62 | + # explicitly surfaces packaging problems before any registry interaction). |
| 63 | + - name: Verify package (dry run) |
| 64 | + env: |
| 65 | + # The crates.io registry token is stored as a repository secret. |
| 66 | + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
| 67 | + run: cargo publish --dry-run --verbose |
| 68 | + |
| 69 | + - name: Publish to crates.io |
| 70 | + # Skip the actual publish when the run was dispatched as a dry run. |
| 71 | + if: ${{ github.event.inputs.dry_run != 'true' }} |
| 72 | + env: |
| 73 | + # The crates.io registry token is stored as a repository secret. |
| 74 | + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
| 75 | + run: cargo publish --verbose |
0 commit comments