Open kke opened 2 years ago
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.
@kke Will look at this, thanks for the report.
I am seeing the same issue in GitHub Actions (false negatives with only-new-issues: true
and false positives with only-new-issues: false
).
If enabling GitHub Actions to run the tests on push to main (post merge), then the effect would be as if only-new-issues
was set to false
.
Interestingly, everything works as expected locally, meaning no false positives and no false negatives even for fresh git clones.
Local version:
$ golangci-lint --version
golangci-lint has version 1.51.2 built from 3e8facb on 2023-02-19T20:54:52Z
$ uname -a
Darwin compartes.local 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:42:11 PST 2023; root:xnu-8792.81.3~2/RELEASE_X86_64 x86_64
CI version:
Requested golangci-lint 'v1.51', using 'v1.51.2', calculation took 56ms
Installing golangci-lint v1.51.2...
Downloading https://github.com/golangci/golangci-lint/releases/download/v1.51.2/golangci-lint-1.51.2-linux-amd64.tar.gz ...
✅ Failure locally (correct):
% golangci-lint run :(
WARN [linters_context] rowserrcheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649.
query/error.go:1:14: Pattern ((20\d\d\-2023)|(2023)) doesn't match. (goheader)
// Copyright 2022 Searis AS
The linter checks that the year-range math the current year for changed files.
❌ Failures in CI with only-new-issues: true
(false negatives):
None; Issue not reported because the change in the file was not located near the header.
❌ Failures in CI with only-new-issues: false
, or on merge to master (false positives):
Error: Pattern ((20\d\d\-2023)|(2023)) doesn't match. (goheader)
Error: Pattern ((20\d\d\-2023)|(2023)) doesn't match. (goheader)
Error: Pattern ((20\d\d\-2023)|(2023)) doesn't match. (goheader)
These are false positives; seams the file-change time from Git(?) is ignored.
Solved the false positive case by adding fetch-depth: 0
to the Checkout step.
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # Required for go-header check.
Without this, Git will clone only the last commit, and go-header
will be unable to check the modification time of the files.
Welcome
Description of the problem
Trying to enforce changing the boilerplate copyright year only for changed files in PRs using the github action.
When using the action with
only-new-issues: true
, the diff very rarely touches the header, mostly only when new files are added, allowing the action to pass without changing the year in the copyright, making the linter ineffective.If using
only-new-issues: false
, every file is reported failing the header check even if they weren't touched.Another problem is build directives (
// +build !windows
), gofmt moves them to top before the boilerplate, goheader fails for each of these because the header doesn't start from the top, so those files need to be excluded.Version of golangci-lint
Configuration file
Go environment
Verbose output of running
...
Code example or link to a public repository
...