Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI refactor #399

Merged
merged 7 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 74 additions & 44 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,32 @@ jobs:
id: get_msrv
run: rg '^\s*rust-version\s*=\s*"(\d+(\.\d+){0,2})"' --replace 'msrv=$1' Cargo.toml >> "$GITHUB_OUTPUT"

check-fmt:
name: Check code formatting
runs-on: ubuntu-latest
needs: get-msrv
strategy:
fail-fast: false
matrix:
rust:
- ${{ needs.get-msrv.outputs.msrv }}
- stable
- nightly
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
components: rustfmt

- name: Check formatting
run: cargo fmt --all -- --check

test:
name: test
name: Test on each target
needs: get-msrv
env:
# Emit backtraces on panics.
Expand All @@ -32,11 +56,32 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
build:
- android-aarch64
- linux-x64-gnu
- linux-x64-musl
- macos-x64
- windows-x64-msvc
rust:
- ${{ needs.get-msrv.outputs.msrv }}
- stable
- nightly
include:
- os: ubuntu-latest # default
- cargo: cargo # default; overwrite with `cross` if necessary
- build: android-aarch64
target: aarch64-linux-android
cargo: cross
- build: linux-x64-gnu
target: x86_64-unknown-linux-gnu
- build: linux-x64-musl
target: x86_64-unknown-linux-musl
- build: macos-x64
os: macos-latest
target: x86_64-apple-darwin
- build: windows-x64-msvc
os: windows-latest
target: x86_64-pc-windows-msvc
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -45,50 +90,48 @@ jobs:
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
components: rustfmt, clippy
targets: ${{ matrix.target }}
components: clippy

- name: Install Cross on Ubuntu
if: matrix.os == 'ubuntu-latest'
- name: Install musl-tools
if: matrix.build == 'linux-x64-musl'
run: sudo apt-get install -y --no-install-recommends musl-tools

- name: Install cross
if: matrix.cargo == 'cross'
# The latest realese of `cross` is not able to build/link for `aarch64-linux-android`
# See: https://github.com/cross-rs/cross/issues/1222
# This is fixed on `main` but not yet released. To avoid a breakage somewhen in the future
# pin the cross revision used to the latest HEAD at 04/2024.
# Remove the git source and revision once cross 0.3 is released.
run: cargo install --git https://github.com/cross-rs/cross.git --rev 085092c cross

- name: Check formatting
run: cargo fmt --all -- --check
# Go back to taiki-e/install-action once cross 0.3 is released.
uses: taiki-e/cache-cargo-install-action@v1
with:
tool: cross
git: https://github.com/cross-rs/cross.git
rev: 085092c

- name: Build
run: cargo build --verbose

- name: Build target aarch64-linux-android
if: matrix.os == 'ubuntu-latest'
run: cross build --target aarch64-linux-android --verbose
id: build
run: ${{ matrix.cargo }} build --verbose --target ${{ matrix.target }}

# This is useful for debugging problems when the expected build artifacts
# (like shell completions and man pages) aren't generated.
- name: Show build.rs stderr
shell: bash
run: |
# it's probably okay to assume no spaces?
STDERR_FILES=$(find "./target/debug" -name stderr | grep bandwhich)
STDERR_FILES=$(find "./target/debug" -name stderr | grep bandwhich || true)
for FILE in $STDERR_FILES; do
echo "::group::$FILE"
cat "$FILE"
echo "::endgroup::"
done

- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings

- name: Install cargo-insta
uses: taiki-e/install-action@v2
with:
tool: cargo-insta
run: ${{ matrix.cargo }} clippy --all-targets --all-features --target ${{ matrix.target }} -- -D warnings

- name: Install npcap on Windows
# PRs from other repositories cannot not be trusted with repository secrets
# PRs from other repositories cannot be trusted with repository secrets
if: matrix.os == 'windows-latest' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
env:
NPCAP_OEM_URL: ${{ secrets.NPCAP_OEM_URL }}
Expand All @@ -98,15 +141,15 @@ jobs:
# see https://stackoverflow.com/a/1674950/5637701
& "$env:TEMP/npcap-oem.exe" /S

- name: Run tests using cargo-insta
- name: Run tests
id: run_tests
# npcap is needed to run tests on Windows, so unfortunately we cannot run tests
# on PRs from other repositories
if: matrix.os != 'windows-latest' || github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
env:
# make insta generate new snapshots in CI
INSTA_UPDATE: new
run: cargo insta test --color=never
run: ${{ matrix.cargo }} test --all-targets --all-features --target ${{ matrix.target }}

- name: Upload snapshots of failed tests
if: ${{ failure() && steps.run_tests.outcome == 'failure' }}
Expand All @@ -115,25 +158,12 @@ jobs:
name: ${{ matrix.os }}-${{ matrix.rust }}-failed_snapshots
path: '**/*.snap.new'

- name: Upload android binary
if: ${{ matrix.os == 'ubuntu-latest' && ( success() || steps.build.outcome == 'success' ) }}
uses: actions/upload-artifact@v3
with:
name: aarch64-linux-android-${{ matrix.rust }}
path: target/aarch64-linux-android/debug/bandwhich

- name: Upload unix binary
if: ${{ matrix.os != 'windows-latest' && ( success() || steps.build.outcome == 'success' ) }}
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os }}-${{ matrix.rust }}
path: target/debug/bandwhich

- name: Upload windows binary
if: ${{ matrix.os == 'windows-latest' && ( success() || steps.build.outcome == 'success' ) }}
- name: Upload binaries
if: ${{ success() || steps.build.outcome == 'success' }}
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os }}-${{ matrix.rust }}
name: ${{ matrix.target }}-${{ matrix.rust }}
path: |
target/debug/bandwhich.exe
target/debug/bandwhich.pdb
target/${{ matrix.target }}/debug/bandwhich
target/${{ matrix.target }}/debug/bandwhich.exe
target/${{ matrix.target }}/debug/bandwhich.pdb
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
* CI: strip release binaries for all targets #358 - @cyqsimon
* Bump MSRV to 1.74 (required by clap 4.5; see #373)
* CI: Configure dependabot grouping #395 - @cyqsimon
* CI refactor #399 - @cyqsimon

## [0.22.2] - 2024-01-28

Expand Down
Loading