From ab4b2b09046b216c8ba7dda4fb161bd836054121 Mon Sep 17 00:00:00 2001 From: Alexandr Yepishev Date: Tue, 26 Nov 2024 10:26:15 +0000 Subject: [PATCH] Update golangci-lint action to go through all dirs if no working directory set --- .github/workflows/ci-core.yml | 39 +++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-core.yml b/.github/workflows/ci-core.yml index c38ecd918ae..2ac1cb1f06b 100644 --- a/.github/workflows/ci-core.yml +++ b/.github/workflows/ci-core.yml @@ -91,11 +91,33 @@ jobs: - '!nix-darwin-shell-hook.sh' - '!LICENSE' - '!.github/**' - - golangci: + + # 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 # 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]' }} + needs: [filter, run-frequency] + 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 + if: ${{ needs.filter.outputs.should-run-golangci == 'true' }} + run: | + PATHS_TO_GO_MOD=$(find . -type f -name go.mod | awk -F'/go.mod' '{if ($1 == ".") print "./"; else print $1}') + 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]' }} + needs: [filter, run-frequency, resolve-modules] permissions: # For golangci-lint-actions to annotate code in the PR. checks: write @@ -103,12 +125,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: ./.github/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