From 6373a95405a6389992db427fee8c9808efca30c3 Mon Sep 17 00:00:00 2001 From: Gustavo Valverde Date: Tue, 25 Jan 2022 07:58:11 -0400 Subject: [PATCH] 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.) --- .github/workflows/ci.yml | 123 +++++++++------------------------ .github/workflows/coverage.yml | 13 ++-- .github/workflows/docs.yml | 6 +- .github/workflows/lint.yml | 60 ++++++++++++++++ .github/workflows/test.yml | 7 ++ 5 files changed, 111 insertions(+), 98 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 813d42a1..10746bcc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 - with: - persist-credentials: false + - uses: actions/checkout@v2 + with: + persist-credentials: false - - uses: actions-rs/toolchain@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 - 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 + - uses: EmbarkStudios/cargo-deny-action@v1 + with: + command: check ${{ matrix.checks }} + args: --all-features --workspace diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 92a9355b..086c0607 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -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: diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 1b986aa9..579fb32e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -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 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..b29260a8 --- /dev/null +++ b/.github/workflows/lint.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dea0cc0d..3a7df67c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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