Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing print of lint errors in golangci-lint action #246

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
19 changes: 12 additions & 7 deletions .github/workflows/golangci_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ jobs:
- name: Install golangci-lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2

# go.work makes it necessary to run linter manually
- name: Run golangci-lint
run: find . -name "go.mod" -execdir $(go env GOPATH)/bin/golangci-lint run --enable=gofmt --tests=false --exclude-use-default --timeout=5m0s --out-format checkstyle:golangci-lint-report.xml \;
run: docker run --rm -v ${{ github.workspace }}:/app -w /app golangci/golangci-lint:v1.54.2 golangci-lint run --max-issues-per-linter 0 --max-same-issues 0 --out-format checkstyle:golangci-lint-results.xml,json:golangci-lint-results.json || true

- name: Check golangci-lint report for errors
run: find . -name "golangci-lint-report.xml" -exec grep "error" {} + && exit 1 || true
run: |
if jq -e '.Issues | length > 0' golangci-lint-results.json; then
echo "Lint issues found:"
jq '.Issues[] | "\(.FromLinter): \(.Pos.Filename):\(.Pos.Line) \(.Text)"' golangci-lint-results.json
exit 1
else
echo "No issues found"
fi

- name: Upload golangci-lint report
- name: Upload golangci-lint JSON report
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still upload xml and download it as XML to sonar, I am not sure it will be correct to tie it to JSON

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix the typo, my bad. The artifact that is uploaded is in xml format.

if: always()
uses: actions/upload-artifact@v3
with:
name: golangci-lint-report
patrickhuie19 marked this conversation as resolved.
Show resolved Hide resolved
path: |
./golangci-lint-report.xml
path: ./golangci-lint-results.xml
2 changes: 1 addition & 1 deletion .github/workflows/sonar-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
shell: bash
run: |
echo "sonarqube_coverage_report_paths=$(find -type f -name '*coverage.out' -printf "%p,")" >> $GITHUB_OUTPUT
echo "sonarqube_golangci_report_paths=$(find -type f -name 'golangci-lint-report.xml' -printf "%p,")" >> $GITHUB_OUTPUT
echo "sonarqube_golangci_report_paths=$(find -type f -name 'golangci-lint-results.xml' -printf "%p,")" >> $GITHUB_OUTPUT

- name: SonarQube Scan
if: always()
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sonar.projectKey=smartcontractkit_chainlink-common
sonar.sources=.
chudilka1 marked this conversation as resolved.
Show resolved Hide resolved

# Full exclusions from the static analysis
sonar.exclusions=**/mocks/**/*, **/testdata/**/*, **/script/**/*, **/generated/**/*, **/fixtures/**/*, **/docs/**/*, **/tools/**/*, **/*.pb.go, **/*report.xml, **/*.txt, **/*.abi, **/*.bin
sonar.exclusions=**/mocks/**/*, **/testdata/**/*, **/script/**/*, **/generated/**/*, **/fixtures/**/*, **/docs/**/*, **/tools/**/*, **/*.pb.go, **/*results, **/*.txt, **/*.abi, **/*.bin
# Coverage exclusions
sonar.coverage.exclusions=**/*_test.go

Expand Down