[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
This commit is contained in:
Tom 2023-07-12 20:40:10 +00:00 committed by GitHub
parent fb9d15f0cc
commit a8342296d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 110 additions and 14 deletions

5
.actrc Normal file
View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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