diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca01695..7fe01c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,12 +43,15 @@ jobs: - name: Cargo fmt run: cargo fmt --check - - name: Cargo clippy - run: cargo clippy --all-targets -- -D warnings + - name: Cargo build + run: cargo build --release - name: Cargo test run: cargo test + - name: Cargo clippy + run: cargo clippy --all-targets -- -D warnings + publish-check: name: Publish Check (dry-run) runs-on: ubuntu-latest @@ -64,6 +67,12 @@ jobs: path: ~/.cargo/registry key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + - name: Cache cargo index + uses: actions/cache@v4 + with: + path: ~/.cargo/git + key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} + - name: Cargo publish dry-run run: cargo publish --dry-run diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ebb7f74..b82fcb5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,6 +8,7 @@ on: - closed paths: - Cargo.toml + workflow_dispatch: permissions: contents: write @@ -154,9 +155,38 @@ jobs: - name: Approval granted run: echo "Release approved for publishing to crates.io" + ensure-owners: + name: Ensure crates.io owners + needs: create-tag + if: needs.create-tag.outputs.created == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ needs.create-tag.outputs.tag }} + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + + - name: Add crates.io owners (best-effort) + env: + TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + OWNERS: github:univerlab:owners + run: | + set -eu + if [ -z "$TOKEN" ]; then + echo "No cargo token found in CARGO_REGISTRY_TOKEN; skipping owners update" + exit 0 + fi + CRATE_NAME=$(grep '^name = ' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/' | tr -d '\r') + echo "crate=$CRATE_NAME" + for owner in $(echo "$OWNERS" | tr ',' ' '); do + echo "Adding owner: $owner" + cargo owner --token "$TOKEN" --add "$owner" || echo "cargo owner failed for $owner (continuing)" + done + publish: name: Publish to crates.io - needs: [create-tag, approve] + needs: [create-tag, approve, ensure-owners] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -166,5 +196,24 @@ jobs: - name: Install Rust toolchain uses: dtolnay/rust-toolchain@stable + - name: Check if stable release + id: version_check + run: | + VERSION=$(grep '^version = ' Cargo.toml | sed 's/.*"\(.*\)".*/\1/') + if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "is_stable=true" >> $GITHUB_OUTPUT + echo "Version $VERSION is stable — will publish" + else + echo "is_stable=false" >> $GITHUB_OUTPUT + echo "Version $VERSION is prerelease/dev — skipping publish" + fi + - name: Cargo publish - run: cargo publish --token ${{ secrets.CARGO_TOKEN }} + if: steps.version_check.outputs.is_stable == 'true' + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + run: cargo publish --allow-dirty + + - name: Skipped prerelease + if: steps.version_check.outputs.is_stable == 'false' + run: echo "⏭️ Skipped crates.io publish for prerelease version"