name: CI & Release
on:
push:
branches: [ "main", "master" ]
pull_request:
branches: [ "main", "master" ]
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-D warnings"
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
version-bump-check:
name: Enforce Semantic Version Bump & CHANGELOG on PRs
runs-on: ubuntu-latest
permissions:
contents: read
if: github.event_name == 'pull_request'
steps:
- name: Checkout repository with full history
uses: actions/checkout@v7
with:
fetch-depth: 0
persist-credentials: false
- name: Verify Semantic Version Bump & CHANGELOG Entry
run: |
chmod +x ./scripts/check_version_bump.sh
./scripts/check_version_bump.sh
quality-gate:
name: Rust Quality Gate
runs-on: ubuntu-latest
steps:
- name: Checkout skybase
uses: actions/checkout@v7
with:
path: skybase
- name: Checkout sibling dependency (skyauth)
uses: actions/checkout@v7
with:
repository: mike10010100/skyauth
path: skyauth
- name: Install Rust Toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt, llvm-tools-preview
- name: Enable Rust Cache
uses: Swatinem/rust-cache@v2
with:
workspaces: |
skybase -> skybase/target
skyauth -> skyauth/target
- name: Install Cargo Deny & llvm-cov
uses: taiki-e/install-action@v2
with:
tool: cargo-deny,cargo-llvm-cov
- name: 1. Enforce Code Formatting
working-directory: skybase
run: cargo fmt --all -- --check
- name: 2. Enforce Strict Clippy Lints
working-directory: skybase
run: |
cargo clippy --all-targets --all-features -- -D warnings
cargo clippy --lib --no-default-features -- -D warnings
- name: 3. Run All Test Suites & Coverage Gate (≥ 85%)
working-directory: skybase
run: |
cargo llvm-cov --all-targets --all-features --fail-under-lines 85
cargo test --lib --no-default-features
- name: 4. Dependency Governance & Advisory Scan (cargo-deny)
working-directory: skybase
run: cargo deny check
publish:
name: Auto-Publish to Crates.io & Create GitHub Release
runs-on: ubuntu-latest
needs: [quality-gate]
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
permissions:
contents: write
checks: read
steps:
- name: Checkout skybase
uses: actions/checkout@v7
with:
path: skybase
persist-credentials: false
- name: Checkout sibling dependency (skyauth)
uses: actions/checkout@v7
with:
repository: mike10010100/skyauth
path: skyauth
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Extract Current Version & Name
id: pkg_info
working-directory: skybase
run: |
VERSION=$(grep -m1 '^[[:space:]]*version[[:space:]]*=' Cargo.toml | awk -F'"' '{print $2}')
NAME=$(grep -m1 '^[[:space:]]*name[[:space:]]*=' Cargo.toml | awk -F'"' '{print $2}')
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "name=${NAME}" >> $GITHUB_OUTPUT
echo "Detected package: ${NAME} v${VERSION}"
- name: Check if Version Already Published on Crates.io
id: check_published
run: |
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -H "User-Agent: ${{ steps.pkg_info.outputs.name }}-release-check" "https://crates.io/api/v1/crates/${{ steps.pkg_info.outputs.name }}/${{ steps.pkg_info.outputs.version }}" || echo "000")
if [ "$HTTP_STATUS" -eq 200 ]; then
echo "published=true" >> $GITHUB_OUTPUT
echo "Version ${{ steps.pkg_info.outputs.version }} is already published on crates.io."
else
echo "published=false" >> $GITHUB_OUTPUT
echo "Version ${{ steps.pkg_info.outputs.version }} is NOT published on crates.io yet."
fi
- name: Validate package before publish
if: steps.check_published.outputs.published == 'false'
working-directory: skybase
run: cargo publish --dry-run --allow-dirty
- name: Publish to Crates.io
if: steps.check_published.outputs.published == 'false'
working-directory: skybase
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
if [ -z "${CARGO_REGISTRY_TOKEN}" ]; then
echo "::error::CARGO_REGISTRY_TOKEN secret is not configured; cannot publish"
exit 1
fi
echo "Publishing ${{ steps.pkg_info.outputs.name }} v${{ steps.pkg_info.outputs.version }} to crates.io..."
cargo publish --allow-dirty --token "${CARGO_REGISTRY_TOKEN}"
- name: Create or Update GitHub Release Tag
if: steps.check_published.outputs.published == 'false'
working-directory: skybase
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_NAME: "v${{ steps.pkg_info.outputs.version }}"
run: |
if ! gh release view "${TAG_NAME}" >/dev/null 2>&1; then
echo "Creating GitHub Release ${TAG_NAME}..."
if [ -f CHANGELOG.md ]; then
gh release create "${TAG_NAME}" \
--target "${GITHUB_SHA}" \
--title "${TAG_NAME} - Production Release" \
--notes-file CHANGELOG.md
else
gh release create "${TAG_NAME}" \
--target "${GITHUB_SHA}" \
--title "${TAG_NAME} - Production Release" \
--generate-notes
fi
else
echo "GitHub Release ${TAG_NAME} already exists."
fi