name: golangci-lint on: push: paths: - pkg/** - .github/workflows/go-lint.yml - go.* branches: - main pull_request: permissions: contents: read jobs: detect-changes: # Run on `grafana/grafana` main branch, or on pull requests to prevent double-running on mirrors if: (github.event_name == 'pull_request' || (github.event_name == 'push' && github.repository == 'grafana/grafana')) name: Detect whether code changed runs-on: ubuntu-latest permissions: contents: read outputs: changed: ${{ steps.detect-changes.outputs.backend }} steps: - uses: actions/checkout@v5 with: persist-credentials: true # required to get more history in the changed-files action fetch-depth: 2 - name: Detect changes id: detect-changes uses: ./.github/actions/change-detection with: self: .github/workflows/go-lint.yml go-fmt: needs: detect-changes if: needs.detect-changes.outputs.changed == 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 with: persist-credentials: false - uses: actions/setup-go@v6.0.0 with: go-version-file: ./go.mod - name: Run gofmt run: | GOFMT="$(go list -m -f '{{.Dir}}' | xargs -I{} sh -c 'test ! -f {}/.nolint && echo {}' | xargs gofmt -s -e -l 2>&1 | grep -v '/pkg/build/' || true)" if [ -n "$GOFMT" ]; then echo "Found files that are not gofmt'ed" echo "Run 'gofmt -s -w .' or 'make gofmt' or install the pre-commit hook with 'make lefthook-install'" echo "${GOFMT}" exit 1 fi lint-go: needs: detect-changes if: needs.detect-changes.outputs.changed == 'true' runs-on: ubuntu-x64-large-io steps: - uses: actions/checkout@v5 with: persist-credentials: false - uses: actions/setup-go@v6.0.0 with: go-version-file: ./go.mod - name: golangci-lint uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 with: version: v2.5.0 args: | --verbose $(go list -m -f '{{.Dir}}' | xargs -I{} sh -c 'test ! -f {}/.nolint && echo {}/...') install-mode: binary