From a8342296d6624fe6c445f1f6ab28f53c41c46161 Mon Sep 17 00:00:00 2001 From: Tom <25043847+Douile@users.noreply.github.com> Date: Wed, 12 Jul 2023 20:40:10 +0000 Subject: [PATCH] [CI] Improve checks (#71) * [CI] Improve checks - Adds .actrc so CI actions can be tested locally - Adds testing for variants of features so changes that break feature sets like disabling games can be caught - Adds more of the CI tests to pre-commit * [CI] Add more feature sets to test * [CI] Check github actions before comitting Requires act: https://github.com/nektos/act * [CI] Add caching between builds * [CI] Add caching everywhere * [CI] Add more feature tests * [CI] Add YAML schemas * [CI] Disable audit when running locally This is needed because the audit action requires a GITHUB_TOKEN which we don't have when running locally. * [CI] Move clippy to own job and use action that annotates PRs Using actions-rs/clippy-check means that PRs will problems will automatically have the relevant lines annotated * [CI] Don't unnecessarily cache targets for fmt --- .actrc | 5 ++ .github/workflows/audit.yml | 2 + .github/workflows/ci.yml | 93 +++++++++++++++++++++++++++++++------ .pre-commit-config.yaml | 24 ++++++++++ 4 files changed, 110 insertions(+), 14 deletions(-) create mode 100644 .actrc diff --git a/.actrc b/.actrc new file mode 100644 index 0000000..b455111 --- /dev/null +++ b/.actrc @@ -0,0 +1,5 @@ +# Configuration file for act (run github actions locally using docker) +# https://github.com/nektos/act + +# Swap docker image for the one containing the rust toolchain +-P ubuntu-latest=ghcr.io/catthehacker/ubuntu:rust-latest diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index 080bc74..d8df9a1 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -1,3 +1,4 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/softprops/github-actions-schemas/master/workflow.json name: Security audit on: push: @@ -12,3 +13,4 @@ jobs: - uses: rustsec/audit-check@v1.4.1 with: token: ${{ secrets.GITHUB_TOKEN }} + if: ${{ !env.ACT }} # skip during local actions testing diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b4b993..40f9c31 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,3 +1,4 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/softprops/github-actions-schemas/master/workflow.json name: CI on: @@ -10,24 +11,53 @@ env: CARGO_TERM_COLOR: always jobs: - build: + build_first: + name: "Build, check, and test with all features" runs-on: ubuntu-latest - steps: - uses: actions/checkout@v3 - - name: Run Build - run: cargo build --verbose - - name: Run Clippy - run: cargo clippy --verbose - - name: Run Tests - run: cargo test --verbose - - name: Install Formatting nightly - uses: actions-rs/toolchain@v1 + - uses: Swatinem/rust-cache@v2 with: - toolchain: nightly-2023-07-09 - components: rustfmt - - name: Run Formatting check - run: cargo +nightly-2023-07-09 fmt --check --verbose + shared-key: "cargo-deps" + cache-targets: false + - name: Run Build + run: cargo build --verbose --bins --lib --examples --all-features + - name: Run Tests + run: cargo test --verbose --bins --lib --examples --all-features + build: + runs-on: ubuntu-latest + needs: [ "build_first" ] + strategy: + fail-fast: false + matrix: + include: + - build_type: "" + build_name: "Default" + - build_type: "--no-default-features" + build_name: "No features" + - build_type: "--no-default-features --features games" + build_name: "Just games" + - build_type: "--no-default-features --features services" + build_name: "Just Services" + - build_type: "--no-default-features --features game_defs" + build_name: "Just Game definitions" + - build_type: "--no-default-features --features serde" + build_name: "Just serde" + name: "Build ${{ matrix.build_name }}" + steps: + - uses: actions/checkout@v3 + - uses: Swatinem/rust-cache@v2 + with: + shared-key: "cargo-deps" + cache-targets: false + - name: Run Build + run: cargo build --verbose --bins --lib ${{ matrix.build_type }} + build_msrv: + name: "Build using MSRV" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: Swatinem/rust-cache@v2 - name: Install MSRV uses: actions-rs/toolchain@v1 with: @@ -35,3 +65,38 @@ jobs: override: true - name: Run MSRV run: cargo build + formatting: + name: "Check code formatting" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: Swatinem/rust-cache@v2 + with: + cache-targets: false + - name: Install Formatting nightly + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly-2023-07-09 + components: rustfmt + override: true + - name: Run Formatting check + run: cargo fmt --check --verbose + clippy: + name: "Run clippy tests" + runs-on: ubuntu-latest + needs: [ "build_first" ] + steps: + - uses: actions/checkout@v3 + - uses: Swatinem/rust-cache@v2 + with: + shared-key: "cargo-deps" + cache-targets: false + - name: Run Clippy + uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --bins --lib --examples --all-features + if: ${{ !env.ACT }} # skip during local actions testing + - name: Run clippy (local) + run: cargo clippy --verbose --bins --lib --examples --all-features + if: ${{ env.ACT }} # only run during local actions testing diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fea56bd..36c1bb6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,9 +9,33 @@ repos: files: '[.]rs$' pass_filenames: false entry: rustup run --install nightly-2023-07-09 cargo-clippy -- -- -D warnings + - id: build-no-features + name: Check crate build with no features + language: system + files: '[.]rs$' + pass_filenames: false + entry: cargo build --no-default-features + - id: build-all-features + name: Check crate builds with all features + language: system + files: '[.]rs$' + pass_filenames: false + entry: cargo build --all-features --lib --bins --examples - id: format name: Check rustfmt language: system files: '[.]rs$' pass_filenames: false entry: rustup run --install nightly-2023-07-09 cargo-fmt --check + - id: msrv + name: Check MSRV compiles + language: system + files: '[.]rs$' + pass_filenames: false + entry: rustup run --install 1.60 cargo build + - id: actions + name: Check actions work + language: system + files: '^[.]github/workflows/' + pass_filenames: false + entry: act -q