|
| 1 | +# This job runs golangci-lint |
| 2 | +# Note that technically, `make lint-go-all` would run the linter for all targets, and could be called once, on a single instance. |
| 3 | +# The point of running it on a matrix instead, each GOOS separately, is to verify that the tooling itself is working on the target OS. |
| 4 | +name: lint-go |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_call: |
| 8 | + inputs: |
| 9 | + timeout: |
| 10 | + required: true |
| 11 | + type: number |
| 12 | + go-version: |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + runner-for-linux: |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + runner-for-freebsd: |
| 19 | + required: true |
| 20 | + type: string |
| 21 | + runner-for-macos: |
| 22 | + required: true |
| 23 | + type: string |
| 24 | + runner-for-windows: |
| 25 | + required: true |
| 26 | + type: string |
| 27 | + |
| 28 | +env: |
| 29 | + GOTOOLCHAIN: local |
| 30 | + |
| 31 | +jobs: |
| 32 | + lint-go: |
| 33 | + name: ${{ format('{0}{1}', matrix.goos, matrix.canary && ' (go canary)' || '') }} |
| 34 | + timeout-minutes: ${{ inputs.timeout }} |
| 35 | + runs-on: "${{ matrix.runner }}" |
| 36 | + defaults: |
| 37 | + run: |
| 38 | + shell: bash |
| 39 | + |
| 40 | + strategy: |
| 41 | + fail-fast: false |
| 42 | + matrix: |
| 43 | + include: |
| 44 | + - runner: ${{ inputs.runner-for-linux }} |
| 45 | + goos: linux |
| 46 | + canary: false |
| 47 | + - runner: ${{ inputs.runner-for-freebsd }} |
| 48 | + goos: freebsd |
| 49 | + canary: false |
| 50 | + - runner: ${{ inputs.runner-for-macos }} |
| 51 | + goos: darwin |
| 52 | + canary: false |
| 53 | + - runner: ${{ inputs.runner-for-windows }} |
| 54 | + goos: windows |
| 55 | + canary: false |
| 56 | + # Additionally lint linux for canary |
| 57 | + - runner: ${{ inputs.runner-for-linux }} |
| 58 | + goos: linux |
| 59 | + canary: true |
| 60 | + |
| 61 | + env: |
| 62 | + GO_VERSION: ${{ inputs.go-version }} |
| 63 | + |
| 64 | + steps: |
| 65 | + - name: "Init: checkout" |
| 66 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 67 | + with: |
| 68 | + fetch-depth: 1 |
| 69 | + |
| 70 | + - if: ${{ matrix.canary }} |
| 71 | + name: "Init (canary): retrieve GO_VERSION" |
| 72 | + run: | |
| 73 | + latest_go="$(. ./hack/provisioning/version/fetcher.sh; go::canary::for::go-setup)" |
| 74 | + printf "GO_VERSION=%s\n" "$latest_go" >> "$GITHUB_ENV" |
| 75 | + [ "$latest_go" != "" ] || \ |
| 76 | + echo "::warning title=No canary go::There is currently no canary go version to test. Steps will not run." |
| 77 | +
|
| 78 | + - if: ${{ env.GO_VERSION != '' }} |
| 79 | + name: "Init: install go" |
| 80 | + uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0 |
| 81 | + with: |
| 82 | + go-version: ${{ env.GO_VERSION }} |
| 83 | + check-latest: true |
| 84 | + |
| 85 | + - if: ${{ env.GO_VERSION != '' }} |
| 86 | + name: "Init: install dev-tools" |
| 87 | + run: | |
| 88 | + echo "::group:: make install-dev-tools" |
| 89 | + make install-dev-tools |
| 90 | + echo "::endgroup::" |
| 91 | +
|
| 92 | + - if: ${{ env.GO_VERSION != '' }} |
| 93 | + name: "Run" |
| 94 | + run: | |
| 95 | + # On canary, lint for all supported targets |
| 96 | + if [ "${{ matrix.canary }}" != "" ]; then |
| 97 | + NO_COLOR=true GOOS="${{ matrix.goos }}" make lint-go-all |
| 98 | + else |
| 99 | + NO_COLOR=true GOOS="${{ matrix.goos }}" make lint-go |
| 100 | + fi |
0 commit comments