diff --git a/.github/actions/golangci-lint/action.yml b/.github/actions/golangci-lint/action.yml index 20ad2689deb..0000dbef85b 100644 --- a/.github/actions/golangci-lint/action.yml +++ b/.github/actions/golangci-lint/action.yml @@ -46,23 +46,30 @@ runs: working-directory: ${{ inputs.go-directory }} shell: bash run: go build ./... - - name: Set golangci-lint working directory - shell: bash - id: set-working-directory - # XXX: Don't use `.` default working directory here due to issues with the golangci-lint-action. - run: | - if [ "${{ inputs.go-directory }}" == "." ]; then - echo "golangci-lint-working-directory=" | tee -a $GITHUB_OUTPUT - else - echo "golangci-lint-working-directory=${{ inputs.go-directory }}" | tee -a $GITHUB_OUTPUT - fi + # - name: Set golangci-lint working directory + # shell: bash + # id: set-working-directory + # # XXX: Don't use `.` default working directory here due to issues with the golangci-lint-action. + # run: | + # if [ "${{ inputs.go-directory }}" == "." ]; then + # echo "golangci-lint-working-directory=" | tee -a $GITHUB_OUTPUT + # else + # echo "golangci-lint-working-directory=${{ inputs.go-directory }}" | tee -a $GITHUB_OUTPUT + # fi + # - name: golangci-lint + # uses: golangci/golangci-lint-action@38e1018663fa5173f3968ea0777460d3de38f256 # v5.3.0 + # with: + # version: v1.61.0 + # only-new-issues: true + # args: --out-format colored-line-number,checkstyle:golangci-lint-report.xml + # working-directory: ${{ steps.set-working-directory.outputs.golangci-lint-working-directory }} - name: golangci-lint uses: golangci/golangci-lint-action@38e1018663fa5173f3968ea0777460d3de38f256 # v5.3.0 with: - version: v1.61.0 + version: v1.62.2 only-new-issues: true args: --out-format colored-line-number,checkstyle:golangci-lint-report.xml - working-directory: ${{ steps.set-working-directory.outputs.golangci-lint-working-directory }} + working-directory: ${{ inputs.go-directory }} - name: Print lint report artifact if: failure() shell: bash diff --git a/.github/workflows/ci-core.yml b/.github/workflows/ci-core.yml index c38ecd918ae..487158d500f 100644 --- a/.github/workflows/ci-core.yml +++ b/.github/workflows/ci-core.yml @@ -91,11 +91,29 @@ jobs: - '!nix-darwin-shell-hook.sh' - '!LICENSE' - '!.github/**' - + + # Golangci-lint needs path to each module to run in monorepo, + # so we resolve the modules first + resolve-modules: + name: Resolve Modules for GolangCI Lint + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-modules.outputs.matrix }} + steps: + - name: Checkout + uses: actions/checkout@v4.2.1 + - name: Set Modules for GolangCI Lint + id: set-modules + run: | + PATHS_TO_GO_MOD=$(find . -type f -name go.mod | awk -F'/go.mod' '{print $1}' | sort | uniq) + PATHS_TO_GO_MOD_JSON=$(echo "$PATHS_TO_GO_MOD" | jq -R -s -c 'split("\n")[:-1]') + echo "matrix=${PATHS_TO_GO_MOD_JSON}" >> $GITHUB_OUTPUT + golangci: + name: lint # We don't directly merge dependabot PRs, so let's not waste the resources if: ${{ (github.event_name == 'pull_request' || github.event_name == 'schedule') && github.actor != 'dependabot[bot]' }} - name: lint + needs: [filter, run-frequency, resolve-modules] permissions: # For golangci-lint-actions to annotate code in the PR. checks: write @@ -103,12 +121,17 @@ jobs: # For golangci-lint-action's `only-new-issues` option. pull-requests: read runs-on: ubuntu-24.04-8cores-32GB-ARM - needs: [filter, run-frequency] + strategy: + matrix: + modules: ${{fromJson(needs.resolve-modules.outputs.matrix)}} steps: - - uses: actions/checkout@v4.2.1 - - name: Golang Lint - uses: ./.github/actions/golangci-lint + - name: Checkout + uses: actions/checkout@v4.2.1 + - name: Golang Lint (${{ matrix.modules }}) if: ${{ needs.filter.outputs.should-run-golangci == 'true' }} + uses: ./actions/golangci-lint + with: + go-directory: ${{ matrix.modules }} - name: Notify Slack if: ${{ failure() && needs.run-frequency.outputs.one-per-day-frequency == 'true' }} uses: slackapi/slack-github-action@6c661ce58804a1a20f6dc5fbee7f0381b469e001 # v1.25.0