|
| 1 | +# Publish eb_stack to crates.io with Trusted Publishing, then register the |
| 2 | +# MCP server. crates.io hands this workflow a token only once |
| 3 | +# stackhands/eb-stack is configured as a Trusted Publisher for eb_stack; |
| 4 | +# until then the publish step is skipped and the crate goes out from a |
| 5 | +# maintainer's machine (cargo publish --locked), as CONTRIBUTING.md says. |
| 6 | +name: publish |
| 7 | + |
| 8 | +on: |
| 9 | + push: |
| 10 | + tags: ["v*"] |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +jobs: |
| 17 | + crates: |
| 18 | + runs-on: ubuntu-24.04 |
| 19 | + permissions: |
| 20 | + contents: read |
| 21 | + id-token: write |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v7 |
| 24 | + - name: The tag is the crate version |
| 25 | + if: startsWith(github.ref, 'refs/tags/v') |
| 26 | + env: |
| 27 | + TAG: ${{ github.ref_name }} |
| 28 | + run: | |
| 29 | + set -eu |
| 30 | + crate=$(python3 -c 'import tomllib; print(tomllib.load(open("Cargo.toml", "rb"))["package"]["version"])') |
| 31 | + if [ "v$crate" != "$TAG" ]; then |
| 32 | + echo "Cargo.toml says $crate and the tag says $TAG" >&2 |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | + - name: Is this version on crates.io already |
| 36 | + id: present |
| 37 | + run: | |
| 38 | + set -eu |
| 39 | + version=$(python3 -c 'import tomllib; print(tomllib.load(open("Cargo.toml", "rb"))["package"]["version"])') |
| 40 | + if curl -fsS -A 'stackhands/eb-stack publish workflow' "https://crates.io/api/v1/crates/eb_stack/$version" > /dev/null; then |
| 41 | + echo "eb_stack $version is on crates.io already" |
| 42 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 43 | + fi |
| 44 | + - uses: dtolnay/rust-toolchain@stable |
| 45 | + if: steps.present.outputs.skip != 'true' |
| 46 | + - uses: rust-lang/crates-io-auth-action@v1.0.5 |
| 47 | + id: auth |
| 48 | + if: steps.present.outputs.skip != 'true' |
| 49 | + continue-on-error: true |
| 50 | + - name: No Trusted Publishing configuration |
| 51 | + if: steps.present.outputs.skip != 'true' && steps.auth.outcome != 'success' |
| 52 | + run: | |
| 53 | + echo "crates.io gave no token for this repository; publish by hand with cargo publish --locked" >&2 |
| 54 | + exit 1 |
| 55 | + - name: Publish eb_stack |
| 56 | + if: steps.present.outputs.skip != 'true' && steps.auth.outcome == 'success' |
| 57 | + env: |
| 58 | + CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} |
| 59 | + run: cargo publish --locked |
| 60 | + |
| 61 | + mcp-registry: |
| 62 | + needs: crates |
| 63 | + permissions: |
| 64 | + contents: read |
| 65 | + id-token: write |
| 66 | + uses: ./.github/workflows/mcp_registry.yml |
0 commit comments