name: CI
on:
push:
branches: ["**"]
pull_request:
types: [opened, synchronize, reopened, closed]
workflow_dispatch:
jobs:
ci:
name: Lint, Build, Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo artifacts
uses: Swatinem/rust-cache@v2
- name: Check format
run: cargo fmt --all -- --check
- name: Lint
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Build
run: cargo build --locked
- name: Test
run: cargo test --locked --all-targets
release-build:
name: Release Build (release -> main merge)
runs-on: ubuntu-latest
needs: ci
if: >-
github.event_name == 'pull_request' &&
github.event.action == 'closed' &&
github.event.pull_request.merged == true &&
github.event.pull_request.base.ref == 'main' &&
(startsWith(github.event.pull_request.head.ref, 'release/') || github.event.pull_request.head.ref == 'release')
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo artifacts
uses: Swatinem/rust-cache@v2
- name: Build release profile
run: cargo build --release --locked
- name: Package CMDkit
run: cargo package --locked
- name: Package cmdkit-macros
run: cd cmdkit-macros && cargo package --locked
- name: Upload package artifact
uses: actions/upload-artifact@v4
with:
name: crate-package-core-${{ github.event.pull_request.merge_commit_sha }}
path: target/package/*.crate
- name: Upload macro package artifact
uses: actions/upload-artifact@v4
with:
name: crate-package-cmdkit-macros-${{ github.event.pull_request.merge_commit_sha }}
path: cmdkit-macros/target/package/*.crate
publish-crates:
name: Publish Crates.io (release -> main merge)
runs-on: ubuntu-latest
needs: [ci, release-build]
if: >-
github.event_name == 'pull_request' &&
github.event.action == 'closed' &&
github.event.pull_request.merged == true &&
github.event.pull_request.base.ref == 'main' &&
(startsWith(github.event.pull_request.head.ref, 'release/') || github.event.pull_request.head.ref == 'release')
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo artifacts
uses: Swatinem/rust-cache@v2
- name: Publish CMDkit
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --locked