|
| 1 | +on: |
| 2 | + workflow_call: |
| 3 | + inputs: |
| 4 | + type: |
| 5 | + description: "the expected lint entrypoint (derived from language by default)" |
| 6 | + default: "" |
| 7 | + required: false |
| 8 | + type: string |
| 9 | + language: |
| 10 | + description: "the language to configure" |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + directory: |
| 14 | + description: "the directory to run the lint in" |
| 15 | + required: false |
| 16 | + type: string |
| 17 | + default: "." |
| 18 | + continue-on-error: |
| 19 | + description: "don't mark the job as failed if a lint fails" |
| 20 | + default: false |
| 21 | + required: false |
| 22 | + type: boolean |
| 23 | + python-version: |
| 24 | + description: "the version of Python to configure, if any (can be SemVer-formatted)" |
| 25 | + default: "" |
| 26 | + required: false |
| 27 | + type: string |
| 28 | + go-version: |
| 29 | + description: "the Go version" |
| 30 | + default: "" |
| 31 | + required: false |
| 32 | + type: string |
| 33 | + golangci-lint-version: |
| 34 | + description: "the golangci-lint version for Go linting" |
| 35 | + default: "v1.50.1" |
| 36 | + required: false |
| 37 | + type: string |
| 38 | + cargo-sort: |
| 39 | + description: "run cargo-sort as part of Rust linting" |
| 40 | + default: false |
| 41 | + required: false |
| 42 | + type: boolean |
| 43 | + org-repo-ref: |
| 44 | + description: "the ref: branch or commit to use of the org repo" |
| 45 | + default: "main" |
| 46 | + required: false |
| 47 | + type: string |
| 48 | + |
| 49 | +env: |
| 50 | + # Rust: GitHub Actions supports color codes, so always enable them. |
| 51 | + CARGO_TERM_COLOR: always |
| 52 | + |
| 53 | + # Python: Tell ruff that we're in GitHub Actions, so that it emits annotations. |
| 54 | + RUFF_FORMAT: github |
| 55 | + |
| 56 | + # Python: Make-based linting workflows use `INSTALL_EXTRA` to optimize |
| 57 | + # the subset of development dependencies installed. |
| 58 | + INSTALL_EXTRA: lint |
| 59 | + |
| 60 | + ORG_REPO: trailofbits/.github |
| 61 | + ORG_REPO_REF: ${{ inputs.org-repo-ref }} |
| 62 | + |
| 63 | +jobs: |
| 64 | + lint: |
| 65 | + runs-on: ubuntu-latest |
| 66 | + steps: |
| 67 | + - uses: actions/checkout@v3 |
| 68 | + |
| 69 | + # Python |
| 70 | + - name: configure python, if required |
| 71 | + if: inputs.language == 'python' |
| 72 | + uses: actions/setup-python@v4 |
| 73 | + with: |
| 74 | + python-version: "${{ inputs.python-version }}" |
| 75 | + python-version-file: "${{ inputs.directory }}/.python-version" |
| 76 | + cache: pip |
| 77 | + cache-dependency-path: | |
| 78 | + **/pyproject.toml |
| 79 | + **/requirements*.txt |
| 80 | +
|
| 81 | + # Rust |
| 82 | + - name: configure rust and clippy, if required |
| 83 | + if: inputs.language == 'rust' |
| 84 | + continue-on-error: ${{ inputs.continue-on-error }} |
| 85 | + working-directory: "${{ inputs.directory }}" |
| 86 | + run: | |
| 87 | + # we always run the latest stable Rust and Clippy for Rust linting. |
| 88 | + rustup update |
| 89 | + rustup component add clippy |
| 90 | +
|
| 91 | + - name: run rustfmt (rust) |
| 92 | + if: inputs.language == 'rust' && inputs.type == '' |
| 93 | + continue-on-error: ${{ inputs.continue-on-error }} |
| 94 | + working-directory: "${{ inputs.directory }}" |
| 95 | + run: cargo fmt --check |
| 96 | + |
| 97 | + - name: run clippy (rust) |
| 98 | + # NOTE: This is a fork of the original `actions-rs/clippy-check`, |
| 99 | + # which is no longer maintained; the commit is pinned since no release |
| 100 | + # has been made and its long term maintenance status/ownership is unclear. |
| 101 | + if: inputs.language == 'rust' && inputs.type == '' |
| 102 | + continue-on-error: ${{ inputs.continue-on-error }} |
| 103 | + uses: actions-rs-plus/clippy-check@5eb300cdebee2681ff8513b9348b0ca793d8a293 |
| 104 | + with: |
| 105 | + args: --all-features -- -D warnings |
| 106 | + working-directory: "${{ inputs.directory }}" |
| 107 | + |
| 108 | + - name: run cargo sort (rust) |
| 109 | + if: inputs.language == 'rust' && inputs.type == '' |
| 110 | + continue-on-error: ${{ inputs.continue-on-error }} |
| 111 | + working-directory: "${{ inputs.directory }}" |
| 112 | + run: | |
| 113 | + cargo install cargo-sort |
| 114 | + cargo sort -c |
| 115 | +
|
| 116 | + # Go |
| 117 | + - name: configure go, if required |
| 118 | + if: inputs.language == 'go' |
| 119 | + continue-on-error: ${{ inputs.continue-on-error }} |
| 120 | + uses: actions/setup-go@v3 |
| 121 | + with: |
| 122 | + go-version-file: "${{ inputs.directory }}/go.mod" |
| 123 | + go-version: "${{ inputs.go-version }}" |
| 124 | + |
| 125 | + - name: run golangci-lint (go) |
| 126 | + if: inputs.language == 'go' && inputs.type == '' |
| 127 | + continue-on-error: ${{ inputs.continue-on-error }} |
| 128 | + uses: golangci/golangci-lint-action@0ad9a0988b3973e851ab0a07adf248ec2e100376 # @v3.3.1 |
| 129 | + with: |
| 130 | + version: "${{ inputs.golangci-lint-version }}" |
| 131 | + working-directory: "${{ inputs.directory }}" |
| 132 | + |
| 133 | + # Markdown |
| 134 | + - name: download markdownlint config |
| 135 | + if: inputs.language == 'markdown' |
| 136 | + run: | |
| 137 | + curl \ |
| 138 | + https://raw.githubusercontent.com/${{ env.ORG_REPO }}/${{ env.ORG_REPO_REF }}/configs/default.markdownlint.jsonc \ |
| 139 | + > /tmp/default.markdownlint.jsonc |
| 140 | +
|
| 141 | + - name: run markdownlint-cli2 |
| 142 | + if: inputs.language == 'markdown' |
| 143 | + continue-on-error: ${{ inputs.continue-on-error }} |
| 144 | + uses: DavidAnson/markdownlint-cli2-action@v9 |
| 145 | + with: |
| 146 | + command: config |
| 147 | + globs: | |
| 148 | + /tmp/default.markdownlint.jsonc |
| 149 | + **/*.md |
| 150 | +
|
| 151 | + # Make |
| 152 | + - name: run lint (make) |
| 153 | + if: (inputs.language == 'python' && inputs.type == '') || inputs.type == 'make' |
| 154 | + continue-on-error: ${{ inputs.continue-on-error }} |
| 155 | + run: make lint |
| 156 | + working-directory: "${{ inputs.directory }}" |
| 157 | + |
| 158 | + # Just |
| 159 | + - name: configure just, if required |
| 160 | + if: inputs.type == 'just' |
| 161 | + run: cargo install just |
| 162 | + |
| 163 | + - name: run lint (just) |
| 164 | + if: inputs.type == 'just' |
| 165 | + continue-on-error: ${{ inputs.continue-on-error }} |
| 166 | + run: just lint |
| 167 | + working-directory: "${{ inputs.directory }}" |
0 commit comments