chore: update branch protection settings to match workflow job names … #68
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Test | |
on: | |
push: | |
branches: [ "main" ] | |
tags: [ "v*" ] | |
pull_request: | |
branches: [ "main" ] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
CARGO_TERM_COLOR: always | |
RUST_BACKTRACE: 1 | |
CARGO_NET_RETRY: 2 | |
RUSTFLAGS: "-D warnings -D clippy::redundant-pattern-matching -D clippy::needless-borrows-for-generic-args" | |
RUST_VERSION: "1.83.0" | |
permissions: | |
contents: read | |
jobs: | |
lint: | |
name: Lint | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
components: rustfmt, clippy | |
toolchain: ${{ env.RUST_VERSION }} | |
- name: Cache cargo registry | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
target | |
~/.rustup | |
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml', 'rust-toolchain.toml') }} | |
restore-keys: | | |
${{ runner.os }}-cargo- | |
- name: Check formatting | |
run: cargo fmt --all -- --check | |
- name: Run clippy | |
run: | | |
cargo clippy --all-targets --all-features -- \ | |
-D warnings \ | |
-D clippy::redundant-pattern-matching \ | |
-D clippy::needless-borrows-for-generic-args | |
- name: Install cargo-deny | |
run: cargo install --locked cargo-deny | |
- name: Run cargo-deny | |
run: cargo deny check | |
coverage: | |
name: Code Coverage | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
- name: Install cargo-tarpaulin | |
run: cargo install cargo-tarpaulin | |
- name: Generate coverage report | |
run: cargo tarpaulin --out Xml --output-dir coverage | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v5 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
files: coverage/cobertura.xml | |
fail_ci_if_error: true | |
build-and-test: | |
name: Build and Test ${{ matrix.target }} | |
runs-on: ${{ matrix.os }} | |
timeout-minutes: 30 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
# macOS builds | |
- os: macos-latest | |
target: x86_64-apple-darwin | |
binary_name: essex | |
use_cross: false | |
- os: macos-latest | |
target: aarch64-apple-darwin | |
binary_name: essex | |
use_cross: false | |
# Linux builds | |
- os: ubuntu-latest | |
target: x86_64-unknown-linux-gnu | |
binary_name: essex | |
use_cross: false | |
- os: ubuntu-latest | |
target: aarch64-unknown-linux-gnu | |
binary_name: essex | |
use_cross: true | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
target: ${{ matrix.target }} | |
toolchain: ${{ env.RUST_VERSION }} | |
- name: Cache cargo registry | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
target | |
~/.rustup | |
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml', 'rust-toolchain.toml') }} | |
restore-keys: | | |
${{ runner.os }}-${{ matrix.target }}-cargo- | |
- name: Cache cargo bin | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cargo/bin | |
key: ${{ runner.os }}-cargo-bin | |
- name: Configure Git | |
run: | | |
# Set global git config in home directory | |
git config --global user.email "ci@example.com" | |
git config --global user.name "CI User" | |
git config --global init.defaultBranch main | |
# Create a git config template for cross environment | |
mkdir -p /tmp/git-template | |
git config -f /tmp/git-template/config user.email "ci@example.com" | |
git config -f /tmp/git-template/config user.name "CI User" | |
# Set environment variable for tests to use the template | |
echo "GIT_CONFIG_GLOBAL=/tmp/git-template/config" >> $GITHUB_ENV | |
- name: Install cross (if needed) | |
if: matrix.use_cross | |
run: cargo install cross | |
- name: Build binary | |
run: | | |
if [ "${{ matrix.use_cross }}" = "true" ]; then | |
cross build --release --target ${{ matrix.target }} | |
else | |
cargo build --release --target ${{ matrix.target }} | |
fi | |
- name: Run tests | |
env: | |
RUST_BACKTRACE: 1 | |
run: | | |
if [ "${{ matrix.use_cross }}" = "true" ]; then | |
cross test --target ${{ matrix.target }} -- --nocapture | |
else | |
cargo test --target ${{ matrix.target }} -- --nocapture | |
fi | |
- name: Test install script | |
if: matrix.os != 'windows-latest' # Skip on Windows as it's not supported | |
run: | | |
chmod +x ./test_install.sh | |
./test_install.sh | |
- name: Package binary | |
shell: bash | |
run: | | |
cd target/${{ matrix.target }}/release | |
if [ "${{ matrix.os }}" = "windows-latest" ]; then | |
zip ../../../essex-${{ matrix.target }}.zip ${{ matrix.binary_name }}.exe | |
else | |
tar czf ../../../essex-${{ matrix.target }}.tar.gz ${{ matrix.binary_name }} | |
fi | |
cd - | |
# Generate checksum for the archive | |
if [ "${{ matrix.os }}" = "windows-latest" ]; then | |
shasum -a 256 essex-${{ matrix.target }}.zip > essex-${{ matrix.target }}.zip.sha256 | |
else | |
shasum -a 256 essex-${{ matrix.target }}.tar.gz > essex-${{ matrix.target }}.tar.gz.sha256 | |
fi | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: essex-${{ matrix.target }} | |
path: | | |
essex-${{ matrix.target }}.${{ matrix.os == 'windows-latest' && 'zip' || 'tar.gz' }} | |
essex-${{ matrix.target }}.${{ matrix.os == 'windows-latest' && 'zip' || 'tar.gz' }}.sha256 | |
retention-days: 5 | |
release: | |
name: Create Release | |
needs: [build-and-test, lint] | |
if: startsWith(github.ref, 'refs/tags/') | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Verify version matches | |
run: | | |
# Extract version from Cargo.toml | |
CARGO_VERSION=$(grep '^version = ' Cargo.toml | cut -d '"' -f2) | |
# Extract version from git tag | |
GIT_VERSION=${GITHUB_REF#refs/tags/v} | |
echo "Cargo.toml version: $CARGO_VERSION" | |
echo "Git tag version: $GIT_VERSION" | |
if [ "$CARGO_VERSION" != "$GIT_VERSION" ]; then | |
echo "Error: Version mismatch between Cargo.toml ($CARGO_VERSION) and git tag ($GIT_VERSION)" | |
exit 1 | |
fi | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: dist | |
merge-multiple: true | |
- name: Copy download script | |
run: cp download_cli.sh dist/ | |
- name: List artifacts | |
run: ls -la dist/ | |
- name: Create GitHub Release | |
uses: softprops/action-gh-release@v2.1.0 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
files: dist/* | |
generate_release_notes: true | |
draft: false | |
prerelease: false |