Publish #31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| # Publish bashkit (core library) to crates.io | |
| publish-bashkit: | |
| name: Publish bashkit | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Verify version matches tag | |
| run: | | |
| # Get tag from release event or skip check for workflow_dispatch | |
| TAG_VERSION="${{ github.event.release.tag_name }}" | |
| if [ -n "$TAG_VERSION" ]; then | |
| TAG_VERSION="${TAG_VERSION#v}" # Remove 'v' prefix | |
| CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/') | |
| if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then | |
| echo "Error: Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)" | |
| exit 1 | |
| fi | |
| echo "Version verified: $TAG_VERSION" | |
| else | |
| echo "Manual dispatch - skipping tag verification" | |
| fi | |
| - name: Strip git-only dependencies for publishing | |
| # monty is a git dep (not yet on crates.io) — remove before publish. | |
| # Must strip from ALL workspace crates because cargo resolves the | |
| # whole workspace when publishing a single crate. | |
| run: | | |
| # --- bashkit core: remove monty dep and python feature --- | |
| TOML=crates/bashkit/Cargo.toml | |
| sed -i '/^monty = .*/d' "$TOML" | |
| sed -i '/^python = \["dep:monty"\]/d' "$TOML" | |
| sed -i '/^\[\[example\]\]/{N;N;/python_scripts/d}' "$TOML" | |
| # --- bashkit-cli: remove python feature --- | |
| CLI_TOML=crates/bashkit-cli/Cargo.toml | |
| sed -i '/^python = \["bashkit\/python"\]/d' "$CLI_TOML" | |
| sed -i 's/default = \["python"\]/default = []/' "$CLI_TOML" | |
| # --- bashkit-js: remove python from features list --- | |
| JS_TOML=crates/bashkit-js/Cargo.toml | |
| sed -i 's/, "python"//; s/"python", //' "$JS_TOML" | |
| # --- bashkit-python: remove python from features list --- | |
| PY_TOML=crates/bashkit-python/Cargo.toml | |
| sed -i 's/, "python"//; s/"python", //' "$PY_TOML" | |
| echo "=== Verify no python feature references remain ===" | |
| grep -rn '"python"' crates/*/Cargo.toml || echo "Clean — no python feature refs" | |
| - name: Publish bashkit to crates.io | |
| run: cargo publish -p bashkit --allow-dirty | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| # Publish bashkit-cli (depends on bashkit) | |
| publish-bashkit-cli: | |
| name: Publish bashkit-cli | |
| runs-on: ubuntu-latest | |
| needs: publish-bashkit | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Wait for crates.io index update | |
| run: sleep 30 | |
| - name: Strip python feature from bashkit-cli | |
| # python feature is stripped from bashkit during publish (monty is git-only) | |
| run: | | |
| TOML=crates/bashkit-cli/Cargo.toml | |
| # Remove python feature and default that references it | |
| sed -i '/^python = \["bashkit\/python"\]/d' "$TOML" | |
| sed -i 's/default = \["python"\]/default = []/' "$TOML" | |
| echo "--- bashkit-cli Cargo.toml after stripping ---" | |
| cat "$TOML" | |
| - name: Publish bashkit-cli to crates.io | |
| run: cargo publish -p bashkit-cli --allow-dirty | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| # ============================================================================ | |
| # Verify all packages were published successfully | |
| # ============================================================================ | |
| verify-publish: | |
| name: Verify published versions | |
| runs-on: ubuntu-latest | |
| needs: [publish-bashkit, publish-bashkit-cli] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Wait for crates.io propagation | |
| run: sleep 60 | |
| - name: Verify crates.io versions | |
| run: | | |
| EXPECTED=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/') | |
| echo "Expected version: $EXPECTED" | |
| PASS=true | |
| for CRATE in bashkit bashkit-cli; do | |
| ACTUAL=$(curl -s "https://crates.io/api/v1/crates/$CRATE" | python3 -c "import sys,json; print(json.load(sys.stdin)['crate']['max_version'])") | |
| if [ "$ACTUAL" = "$EXPECTED" ]; then | |
| echo "✓ $CRATE@$ACTUAL on crates.io" | |
| else | |
| echo "✗ $CRATE: expected $EXPECTED, got $ACTUAL" | |
| PASS=false | |
| fi | |
| done | |
| if [ "$PASS" = "false" ]; then | |
| echo "::error::Some crates.io packages were not published correctly" | |
| exit 1 | |
| fi |