name: commit-stage
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
RUST_VERSION: "1.92"
jobs:
conventional-commits:
name: commitizen
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: ${{ github.event_name == 'pull_request' && github.event.pull_request.commits || 10 }}
- name: Fetch base for PRs
if: github.event_name == 'pull_request'
run: git fetch origin ${{ github.base_ref }}
- name: Fetch for push to main
if: github.event_name == 'push'
run: git fetch origin ${{ github.event.before }}
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: pip-commitizen-${{ runner.os }}
- name: Install commitizen
run: pip install commitizen
- name: Determine Commit Range
id: commit_range
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "COMMIT_RANGE=origin/${{ github.base_ref }}..HEAD" >> $GITHUB_ENV
elif [ "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]; then
if git rev-parse --verify "${{ github.event.before }}" >/dev/null 2>&1; then
echo "COMMIT_RANGE=${{ github.event.before }}..HEAD" >> $GITHUB_ENV
else
echo "Commit ${{ github.event.before }} not found (likely after rebase). Skipping validation."
echo "SKIP_VALIDATION=true" >> $GITHUB_ENV
fi
else
echo "No commit range found. Skipping validation."
echo "SKIP_VALIDATION=true" >> $GITHUB_ENV
fi
- name: Check Conventional Commits
if: env.SKIP_VALIDATION != 'true'
env:
COMMIT_RANGE: ${{ env.COMMIT_RANGE }}
run: cz check --rev-range $COMMIT_RANGE
reuse:
name: reuse lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: REUSE Compliance Check
uses: fsfe/reuse-action@v5
fmt:
name: cargo fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}
components: rustfmt
- name: Run cargo fmt
run: cargo fmt --all -- --check
clippy:
name: cargo clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}
components: clippy
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
shared-key: clippy
- name: Run cargo clippy
run: cargo clippy --all-targets --all-features -- -D warnings
cargo-audit:
name: cargo audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}
- name: Install cargo-audit
uses: taiki-e/install-action@v2
with:
tool: cargo-audit
- name: Run cargo audit
run: cargo audit
test:
name: cargo test (${{ matrix.features }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
features:
- "default"
- "minimal"
- "v2"
- "v3"
- "limit-orders"
- "contracts"
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
shared-key: test
- name: Run tests (default features)
if: matrix.features == 'default'
run: cargo test --lib
- name: Run tests (specific features)
if: matrix.features != 'default'
run: cargo test --lib --no-default-features --features=${{ matrix.features }}