200 lines
6.0 KiB
YAML
200 lines
6.0 KiB
YAML
name: Lint
|
|
|
|
# Ensures that only one workflow task will run at a time. Previous builds, if
|
|
# already in process, will get cancelled. Only the latest commit will be allowed
|
|
# to run, cancelling any workflows in between
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
|
cancel-in-progress: true
|
|
|
|
on:
|
|
# we build Rust caches on main, so they can be shared by all branches:
|
|
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache
|
|
push:
|
|
branches:
|
|
- main
|
|
pull_request:
|
|
|
|
env:
|
|
CARGO_INCREMENTAL: 0
|
|
RUST_LOG: info
|
|
RUST_BACKTRACE: full
|
|
RUST_LIB_BACKTRACE: full
|
|
COLORBT_SHOW_HIDDEN: '1'
|
|
|
|
jobs:
|
|
changed-files:
|
|
runs-on: ubuntu-latest
|
|
name: Checks changed-files
|
|
outputs:
|
|
rust: ${{ steps.changed-files-rust.outputs.any_changed == 'true' }}
|
|
workflows: ${{ steps.changed-files-workflows.outputs.any_changed == 'true' }}
|
|
steps:
|
|
- uses: actions/checkout@v3.3.0
|
|
with:
|
|
persist-credentials: false
|
|
fetch-depth: 0
|
|
|
|
- name: Rust files
|
|
id: changed-files-rust
|
|
uses: tj-actions/changed-files@v35.5.2
|
|
with:
|
|
files: |
|
|
**/*.rs
|
|
**/Cargo.toml
|
|
**/Cargo.lock
|
|
clippy.toml
|
|
.cargo/config.toml
|
|
.github/workflows/lint.yml
|
|
|
|
- name: Workflow files
|
|
id: changed-files-workflows
|
|
uses: tj-actions/changed-files@v35.5.2
|
|
with:
|
|
files: |
|
|
.github/workflows/*.yml
|
|
|
|
clippy:
|
|
name: Clippy
|
|
timeout-minutes: 45
|
|
runs-on: ubuntu-latest
|
|
needs: changed-files
|
|
if: ${{ needs.changed-files.outputs.rust == 'true' }}
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3.3.0
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Install last version of Protoc
|
|
uses: arduino/setup-protoc@v1.1.2
|
|
with:
|
|
# TODO: increase to latest version after https://github.com/arduino/setup-protoc/issues/33 is fixed
|
|
version: '3.20.1'
|
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Check workflow permissions
|
|
id: check_permissions
|
|
uses: scherermichael-oss/action-has-permission@1.0.6
|
|
with:
|
|
required-permission: write
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- uses: Swatinem/rust-cache@v1
|
|
with:
|
|
# TODO: change to shared-key when we switch to Swatinem/rust-cache@v2
|
|
sharedKey: "clippy-cargo-lock"
|
|
|
|
- name: Run clippy action to produce annotations
|
|
uses: actions-rs/clippy-check@v1.0.7
|
|
if: ${{ steps.check_permissions.outputs.has-permission }}
|
|
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
|
|
|
|
- uses: actions-rs/toolchain@v1.0.1
|
|
if: ${{ !steps.check_permissions.outputs.has-permission }}
|
|
with:
|
|
toolchain: stable
|
|
override: true
|
|
|
|
- name: Run clippy manually without annotations
|
|
if: ${{ !steps.check_permissions.outputs.has-permission }}
|
|
run: cargo clippy --all-features --all-targets -- -D warnings
|
|
|
|
fmt:
|
|
name: Rustfmt
|
|
timeout-minutes: 30
|
|
runs-on: ubuntu-latest
|
|
needs: changed-files
|
|
if: ${{ needs.changed-files.outputs.rust == 'true' }}
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3.3.0
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Install last version of Protoc
|
|
uses: arduino/setup-protoc@v1.1.2
|
|
with:
|
|
# TODO: increase to latest version after https://github.com/arduino/setup-protoc/issues/33 is fixed
|
|
version: '3.20.1'
|
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- uses: actions-rs/toolchain@v1.0.6
|
|
with:
|
|
toolchain: stable
|
|
components: rustfmt
|
|
override: true
|
|
|
|
# We don't cache `fmt` outputs because the job is quick,
|
|
# and we want to use the limited GitHub actions cache space for slower jobs.
|
|
#- uses: Swatinem/rust-cache@v1
|
|
|
|
- uses: actions-rs/cargo@v1.0.3
|
|
with:
|
|
command: fmt
|
|
args: --all -- --check
|
|
|
|
docs:
|
|
name: Rust doc
|
|
timeout-minutes: 30
|
|
runs-on: ubuntu-latest
|
|
needs: changed-files
|
|
if: ${{ needs.changed-files.outputs.rust == 'true' }}
|
|
# cargo doc doesn't support '-- -D warnings', so we have to add it here
|
|
# https://github.com/rust-lang/cargo/issues/8424#issuecomment-774662296
|
|
#
|
|
# These -A and -W settings must be the same as the rustdoc settings in:
|
|
# https://github.com/ZcashFoundation/zebra/blob/main/.cargo/config.toml#L53
|
|
env:
|
|
RUSTDOCFLAGS: -D warnings -A rustdoc::private_intra_doc_links
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3.3.0
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Install last version of Protoc
|
|
uses: arduino/setup-protoc@v1.1.2
|
|
with:
|
|
# TODO: increase to latest version after https://github.com/arduino/setup-protoc/issues/33 is fixed
|
|
version: '3.20.1'
|
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- uses: actions-rs/toolchain@v1.0.6
|
|
with:
|
|
toolchain: stable
|
|
profile: minimal
|
|
override: true
|
|
|
|
- uses: actions-rs/cargo@v1.0.3
|
|
with:
|
|
command: doc
|
|
args: --no-deps --document-private-items --all-features
|
|
|
|
actionlint:
|
|
runs-on: ubuntu-latest
|
|
continue-on-error: true
|
|
needs: changed-files
|
|
if: ${{ needs.changed-files.outputs.workflows == 'true' }}
|
|
steps:
|
|
- uses: actions/checkout@v3.3.0
|
|
- uses: reviewdog/action-actionlint@v1.36.0
|
|
with:
|
|
level: warning
|
|
fail_on_error: false
|
|
|
|
codespell:
|
|
runs-on: ubuntu-latest
|
|
needs: changed-files
|
|
steps:
|
|
- uses: actions/checkout@v3.3.0
|
|
- uses: plettich/action-codespell@master
|
|
with:
|
|
github_token: ${{ secrets.github_token }}
|
|
level: warning
|