Skip to content

Commit

Permalink
Update golangci-lint action to go through all dirs if no working dire…
Browse files Browse the repository at this point in the history
…ctory set
  • Loading branch information
chudilka1 committed Nov 26, 2024
1 parent 959ab5a commit 41d1c8c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
31 changes: 19 additions & 12 deletions .github/actions/golangci-lint/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions .github/scripts/resolve-modules.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# Recursively finds all directories with a go.mod file and creates
# a GitHub Actions JSON output option. This is used by the linter action.

echo "Resolving modules in $(pwd)"

PATHS=$(find . -mindepth 2 -type f -name go.mod -printf '{"workdir":"%h"},')
echo "::set-output name=matrix::{\"include\":[${PATHS%?}]}"
29 changes: 24 additions & 5 deletions .github/workflows/ci-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,43 @@ 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-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4.2.1
- name: Make script executable
run: chmod +x ./scripts/resolve-modules.sh
- name: Set Matrix for GolangCI Lint
id: set-matrix
run: ./scripts/resolve-modules.sh

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
permissions:
# For golangci-lint-actions to annotate code in the PR.
checks: write
contents: read
# For golangci-lint-action's `only-new-issues` option.
pull-requests: read
runs-on: ubuntu-24.04-8cores-32GB-ARM
needs: [filter, run-frequency]
needs: [filter, run-frequency, resolve-modules]
steps:
- uses: actions/checkout@v4.2.1
- name: Checkout
uses: actions/checkout@v4.2.1
- name: Golang Lint
uses: ./.github/actions/golangci-lint
if: ${{ needs.filter.outputs.should-run-golangci == 'true' }}
uses: ./actions/golangci-lint
with:
go-directory: ${{ steps.resolve-modules.outputs.matrix }}
- name: Notify Slack
if: ${{ failure() && needs.run-frequency.outputs.one-per-day-frequency == 'true' }}
uses: slackapi/slack-github-action@6c661ce58804a1a20f6dc5fbee7f0381b469e001 # v1.25.0
Expand Down

0 comments on commit 41d1c8c

Please sign in to comment.