name: Publish
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
permissions:
contents: read
actions: read
jobs:
check-ci-status:
name: Check CI Status
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get commit SHA for tag
id: get-commit-sha
run: |
echo "SHA=$(git rev-parse ${{ github.ref_name }})" >> $GITHUB_OUTPUT
- name: Check CI workflow status
id: check-workflow
run: |
# Wait for CI to potentially finish (up to 30 minutes, checking once per minute)
for i in {1..30}; do
WORKFLOW_RUNS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/actions/workflows/ci.yaml/runs?event=push&head_sha=${{ steps.get-commit-sha.outputs.SHA }}")
# Extract the status and conclusion
STATUS=$(echo "$WORKFLOW_RUNS" | jq -r '.workflow_runs[0].status')
CONCLUSION=$(echo "$WORKFLOW_RUNS" | jq -r '.workflow_runs[0].conclusion')
echo "CI workflow status: $STATUS, conclusion: $CONCLUSION"
if [ "$STATUS" = "completed" ]; then
if [ "$CONCLUSION" = "success" ]; then
echo "CI workflow completed successfully!"
exit 0
else
echo "CI workflow failed with conclusion: $CONCLUSION"
exit 1
fi
fi
echo "CI workflow still running, checking again in 1 minute... (attempt $i of 30)"
sleep 60
done
echo "Timed out waiting for CI workflow to complete after 30 minutes"
exit 1
verify:
name: Verify
needs: check-ci-status
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Populate target directory from cache
uses: Leafwing-Studios/cargo-cache@v2
with:
sweep-cache: true
- name: Check version matches tag
run: |
VERSION=$(grep -m 1 '^version' Cargo.toml | sed -e 's/.*= "//' -e 's/".*//')
TAG=${GITHUB_REF#refs/tags/v}
if [ "$VERSION" != "$TAG" ]; then
echo "Version in Cargo.toml ($VERSION) does not match tag version ($TAG)"
exit 1
fi
publish:
name: Publish
needs: verify
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Populate target directory from cache
uses: Leafwing-Studios/cargo-cache@v2
with:
sweep-cache: true
- name: Publish to crates.io
run: cargo publish --all-features
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}