|
| 1 | +name: Code Quality |
| 2 | + |
| 3 | +# spell-checker:ignore Swatinem dtolnay sccache rustfmt |
| 4 | + |
| 5 | +on: |
| 6 | + pull_request: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + |
| 11 | +env: |
| 12 | + STYLE_FAIL_ON_FAULT: true |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | +concurrency: |
| 18 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 19 | + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} |
| 20 | + |
| 21 | +jobs: |
| 22 | + fmt: |
| 23 | + name: cargo fmt --all -- --check |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v6 |
| 27 | + - uses: dtolnay/rust-toolchain@nightly |
| 28 | + with: |
| 29 | + components: rustfmt |
| 30 | + - run: cargo fmt --all -- --check |
| 31 | + |
| 32 | + clippy: |
| 33 | + name: cargo clippy |
| 34 | + runs-on: ${{ matrix.job.os }} |
| 35 | + env: |
| 36 | + SCCACHE_GHA_ENABLED: "true" |
| 37 | + RUSTC_WRAPPER: "sccache" |
| 38 | + strategy: |
| 39 | + fail-fast: false |
| 40 | + matrix: |
| 41 | + job: |
| 42 | + - { os: ubuntu-latest } |
| 43 | + - { os: macos-latest } |
| 44 | + steps: |
| 45 | + - uses: actions/checkout@v6 |
| 46 | + - uses: dtolnay/rust-toolchain@nightly |
| 47 | + with: |
| 48 | + components: clippy |
| 49 | + - uses: Swatinem/rust-cache@v2 |
| 50 | + - name: Run sccache-cache |
| 51 | + uses: mozilla-actions/sccache-action@v0.0.10 |
| 52 | + - name: Initialize workflow variables |
| 53 | + id: vars |
| 54 | + shell: bash |
| 55 | + run: | |
| 56 | + ## VARs setup |
| 57 | + outputs() { step_id="${{ github.action }}"; for var in "$@" ; do echo steps.${step_id}.outputs.${var}="${!var}"; echo "${var}=${!var}" >> $GITHUB_OUTPUT; done; } |
| 58 | + # failure mode |
| 59 | + unset FAIL_ON_FAULT ; case '${{ env.STYLE_FAIL_ON_FAULT }}' in |
| 60 | + ''|0|f|false|n|no|off) FAULT_TYPE=warning ;; |
| 61 | + *) FAIL_ON_FAULT=true ; FAULT_TYPE=error ;; |
| 62 | + esac; |
| 63 | + outputs FAIL_ON_FAULT FAULT_TYPE |
| 64 | + - name: "`cargo clippy` lint testing" |
| 65 | + shell: bash |
| 66 | + run: | |
| 67 | + ## `cargo clippy` lint testing |
| 68 | + unset fault |
| 69 | + fault_type="${{ steps.vars.outputs.FAULT_TYPE }}" |
| 70 | + fault_prefix=$(echo "$fault_type" | tr '[:lower:]' '[:upper:]') |
| 71 | + S=$(cargo clippy --workspace -- -D warnings 2>&1) && printf "%s\n" "$S" || { printf "%s\n" "$S" ; printf "%s" "$S" | sed -E -n -e '/^error:/{' -e "N; s/^error:[[:space:]]+(.*)\\n[[:space:]]+-->[[:space:]]+(.*):([0-9]+):([0-9]+).*$/::${fault_type} file=\2,line=\3,col=\4::${fault_prefix}: \`cargo clippy\`: \1 (file:'\2', line:\3)/p;" -e '}' ; fault=true ; } |
| 72 | + if [ -n "${{ steps.vars.outputs.FAIL_ON_FAULT }}" ] && [ -n "$fault" ]; then exit 1 ; fi |
0 commit comments