Improve GitHub Actions checks based on files & folders (#3377)

* Segregate linting jobs from CI workflow

Lint on push to all branches, except for main, as this action will be required to merge.

Just run the lint action when a Rust file is changed, as it won't make sense to run it on other scenarios.

DRY with uneeded jobs

* Make actions dependable on changed files or folders

* Fix & add missing paths

* Revert changes removing cargo.lock and deny.toml checks

Also refactor this to use a more redable and change prone cargo-deny-action. And move this actions out of the clippy-deps job, as this are more related to CI than linting.

* Fix wrong indentation

* Add new configuration file from #3386

* Do not fail on licenses as this configuration is missing

* Do not add advisories features

Add advisories checks in a different PR

* Allow tests and coverage on PR series

If we only run CI on branches that are going to merge to main, then PR series become a lot harder to test. (Because each PR is based on the previous PR, not main.)
This commit is contained in:
Gustavo Valverde 2022-01-25 07:58:11 -04:00 committed by GitHub
parent 499ae89c80
commit 6373a95405
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 111 additions and 98 deletions

View File

@ -3,12 +3,16 @@ name: CI
on:
workflow_dispatch:
pull_request:
push:
branches:
- main
path:
- '**/*.rs'
- '**/*.txt'
- '**/Cargo.toml'
- '**/Cargo.lock'
- '**/deny.toml'
- 'docker/**'
- '.github/workflows/ci.yml'
jobs:
test:
name: Test (+${{ matrix.rust }}) on ${{ matrix.os }}
# The large timeout is to accommodate:
@ -246,6 +250,13 @@ jobs:
- uses: Swatinem/rust-cache@v1
# This check makes sure the crate dependency check is accurate
- name: Check Cargo.lock is up to date
uses: actions-rs/cargo@v1.0.3
with:
command: check
args: --locked --all-features --all-targets
- name: cargo fetch
uses: actions-rs/cargo@v1.0.3
with:
@ -265,94 +276,24 @@ jobs:
command: build
args: --verbose --release
clippy-deps:
name: Clippy (stable)
timeout-minutes: 30
cargo-deny:
name: Check deny.toml crate dependencies and validate licenses
runs-on: ubuntu-latest
env:
CARGO_INCREMENTAL: 0
RUST_BACKTRACE: full
strategy:
matrix:
checks:
- bans
- sources
# Prevent sudden announcement of a new advisory from failing ci:
continue-on-error: ${{ matrix.checks == 'advisories' }}
steps:
- uses: actions/checkout@v2.4.0
- uses: actions/checkout@v2
with:
persist-credentials: false
- uses: actions-rs/toolchain@v1
- uses: EmbarkStudios/cargo-deny-action@v1
with:
toolchain: stable
components: clippy
override: true
- uses: Swatinem/rust-cache@v1
- name: Show env vars
run: |
echo "Common env vars:"
echo "RUST_BACKTRACE=${{ env.RUST_BACKTRACE }}"
echo "Build env vars:"
echo "CARGO_INCREMENTAL=${{ env.CARGO_INCREMENTAL }}"
echo "CARGO_TARGET_DIR=${{ env.CARGO_TARGET_DIR }}"
- name: Run clippy
uses: actions-rs/clippy-check@v1.0.7
with:
# GitHub displays the clippy job and its results as separate entries
name: Clippy (stable) Results
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --all-targets -- -D warnings
# This check makes sure the crate dependency check is accurate
- name: Check Cargo.lock is up to date
uses: actions-rs/cargo@v1.0.3
with:
command: check
args: --locked --all-features --all-targets
# Edit zebra/deny.toml to allow duplicate dependencies
- name: Check for dependent crates with different versions
uses: EmbarkStudios/cargo-deny-action@v1.2.9
with:
command: check bans
command: check ${{ matrix.checks }}
args: --all-features --workspace
- name: Check crate sources
uses: EmbarkStudios/cargo-deny-action@v1.2.9
with:
command: check sources
args: --all-features --workspace
fmt:
name: Rustfmt
timeout-minutes: 30
runs-on: ubuntu-latest
env:
CARGO_INCREMENTAL: 0
RUST_BACKTRACE: full
steps:
- uses: actions/checkout@v2.4.0
with:
persist-credentials: false
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt
override: true
- uses: Swatinem/rust-cache@v1
- name: Show env vars
run: |
echo "Common env vars:"
echo "RUST_BACKTRACE=${{ env.RUST_BACKTRACE }}"
echo "Build env vars:"
echo "CARGO_INCREMENTAL=${{ env.CARGO_INCREMENTAL }}"
echo "CARGO_TARGET_DIR=${{ env.CARGO_TARGET_DIR }}"
- name: Check rustfmt
uses: actions-rs/cargo@v1.0.3
with:
command: fmt
args: --all -- --check

View File

@ -3,14 +3,15 @@ name: Coverage
on:
workflow_dispatch:
pull_request:
branches:
- main
push:
branches:
- main
path:
- '**/*.rs'
- '**/*.txt'
- '**/Cargo.toml'
- '**/Cargo.lock'
- 'codecov.yml'
- '.github/workflows/coverage.yml'
jobs:
coverage:
name: Coverage (+nightly)
# The large timeout is to accommodate:

View File

@ -5,9 +5,13 @@ on:
push:
branches:
- main
path:
- 'book/**'
- '**/firebase.json'
- 'katex-header.html'
- '.github/workflows/docs.yml'
jobs:
build:
name: Build and Deploy Docs (+beta)
timeout-minutes: 30

60
.github/workflows/lint.yml vendored Normal file
View File

@ -0,0 +1,60 @@
name: Lint Rust files
on:
push:
branches:
- "**"
- "!main"
path:
- '**/*.rs'
- '**/Cargo.toml'
- '**/Cargo.lock'
- 'clippy.toml'
- '.cargo/config.toml'
- '.github/workflows/lint.yml'
env:
CARGO_INCREMENTAL: 0
RUST_BACKTRACE: full
jobs:
clippy:
name: Clippy
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
persist-credentials: false
- name: Run clippy
uses: actions-rs/clippy-check@v1.0.7
with:
# GitHub displays the clippy job and its results as separate entries
name: Clippy (stable) Results
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --all-targets -- -D warnings
fmt:
name: Rustfmt
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
persist-credentials: false
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt
override: true
- uses: Swatinem/rust-cache@v1 # TODO: No cache is being found
- uses: actions-rs/cargo@v1.0.3
with:
command: fmt
args: --all -- --check

View File

@ -5,6 +5,13 @@ on:
push:
branches:
- main
path:
- '**/*.rs'
- '**/*.txt'
- '**/Cargo.toml'
- '**/Cargo.lock'
- 'docker/**'
- '.github/workflows/test.yml'
env:
PROJECT_ID: zealous-zebra