name: 'PR Checks'
on:
pull_request:
branches: [ main, prerelease, releases/** ]
permissions:
contents: read
jobs:
commit-messages:
name: Validate Commit Messages
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate commit messages
run: |
# Get all commits in the PR (excluding merge commits)
COMMITS=$(git log --format=%H --no-merges ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }})
# Conventional commit pattern
PATTERN='^(feat|fix|docs|chore|test|refactor|perf|ci|build|style|revert)(\(.+\))?!?: .+'
FAILED=0
for COMMIT in $COMMITS; do
MESSAGE=$(git log --format=%s -n 1 $COMMIT)
if ! echo "$MESSAGE" | grep -qE "$PATTERN"; then
echo "❌ Invalid commit message: $MESSAGE"
echo " Commit: $COMMIT"
FAILED=1
else
echo "✅ Valid commit message: $MESSAGE"
fi
done
if [ $FAILED -eq 1 ]; then
echo ""
echo "Commit messages must follow Conventional Commits format:"
echo " <type>: <description>"
echo ""
echo "Valid types: feat, fix, docs, chore, test, refactor, perf, ci, build, style, revert"
echo "For breaking changes, add '!' after type: feat!: breaking change"
echo ""
echo "See CONTRIBUTING.md for more details."
exit 1
fi
test-linux:
name: Test Linux
needs: commit-messages
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
target: [x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu]
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Install cross-compilation toolchains
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
echo '[target.aarch64-unknown-linux-gnu]' >> ~/.cargo/config.toml
echo 'linker = "aarch64-linux-gnu-gcc"' >> ~/.cargo/config.toml
- name: Build
run: cargo build --workspace --target ${{ matrix.target }} --verbose --release
- name: Run tests
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: cargo test --workspace --verbose
test-windows:
name: Test Windows
needs: commit-messages
runs-on: windows-latest
permissions:
contents: read
strategy:
matrix:
target: [x86_64-pc-windows-msvc, aarch64-pc-windows-msvc]
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --workspace --target ${{ matrix.target }} --verbose --release
test-macos:
name: Test macOS
needs: commit-messages
runs-on: macos-latest
permissions:
contents: read
strategy:
matrix:
target: [x86_64-apple-darwin, aarch64-apple-darwin]
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --workspace --target ${{ matrix.target }} --verbose --release
fmt:
name: Format
needs: commit-messages
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Check formatting
run: cargo fmt --all -- --check
clippy:
name: Clippy
needs: commit-messages
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
- name: Run clippy
run: cargo clippy --workspace -- -D warnings
custom-lints:
name: Custom Lints (dylint)
needs: commit-messages
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
- name: Install Rust nightly
uses: dtolnay/rust-toolchain@nightly
with:
components: rustc-dev, llvm-tools
- uses: Swatinem/rust-cache@v2
with:
cache-directories: |
~/.dylint_drivers
- name: Install dylint
run: cargo install cargo-dylint dylint-link
- name: Run custom lints
run: cargo dylint --all --workspace
# Note: dylint automatically uses the nightly toolchain to build the lint library
# (specified in iam-policy-autopilot-lints/rust-toolchain) and stable to check the workspace