ci(lint): filter new issues from git instead of the PR patch API
`only-new-issues: true` makes golangci-lint-action ask the GitHub API for
the pull request patch, and that endpoint refuses any diff over 20000
lines:
failed to fetch pull request patch: RequestError [HttpError]:
Sorry, the diff exceeded the maximum number of lines (20000):
{"resource":"PullRequest","field":"diff","code":"too_large"}
The action does not fail on that error — it falls back to linting
everything. With the backlog this repository carries (5672 findings at
the time of writing) the job then reports hundreds of issues in files the
pull request never touched, capped at 50 per linter, and cannot pass no
matter how clean the change is. Tencent/WeKnora#3470 hit this at 28050
diff lines.
golangci-lint computes the same filter itself with --new-from-merge-base,
which reads git rather than the API and has no size limit. `fetch-depth: 0`
on the checkout is what makes the base commit available, and the changes
job above already relies on it, so nothing else needs to move.
Verified against that pull request's branch: full run reports 5672 issues,
`--new-from-merge-base=<base sha>` reports 0, both from the repository root
and from the cli module directory.
main
parent
7fa6f028fc
commit
9b0b0910ba
|
|
@ -1,10 +1,18 @@
|
|||
name: Go Lint
|
||||
|
||||
# The repository carries a large backlog of pre-existing golangci-lint findings,
|
||||
# so pull requests are only judged on the code they introduce (`only-new-issues`).
|
||||
# That filter needs a pull request diff, which is why this workflow has no other
|
||||
# trigger; the companion go-lint-cache.yml keeps the caches this job restores
|
||||
# from warm on main.
|
||||
# so pull requests are only judged on the code they introduce. The filter needs
|
||||
# a pull request diff, which is why this workflow has no other trigger; the
|
||||
# companion go-lint-cache.yml keeps the caches this job restores from warm on
|
||||
# main.
|
||||
#
|
||||
# The filter is golangci-lint's own `--new-from-merge-base` rather than the
|
||||
# action's `only-new-issues`, because that option asks the GitHub API for the
|
||||
# pull request patch and the API refuses any diff over 20000 lines
|
||||
# ("code": "too_large"). On a large pull request the action silently falls back
|
||||
# to linting everything, which reports the entire backlog and can never pass.
|
||||
# Computing the merge base from git has no size limit, and `fetch-depth: 0`
|
||||
# below is what makes the base commit available to do it.
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
|
|
@ -101,4 +109,7 @@ jobs:
|
|||
with:
|
||||
version: ${{ env.GOLANGCI_LINT_VERSION }}
|
||||
working-directory: ${{ matrix.module }}
|
||||
only-new-issues: true
|
||||
# Deliberately off: see the note at the top of this file. The same
|
||||
# filtering is done below, from git.
|
||||
only-new-issues: false
|
||||
args: --new-from-merge-base=${{ github.event.pull_request.base.sha }}
|
||||
|
|
|
|||
Loading…
Reference in New Issue