Open kolyshkin opened 2 years ago
Actually you don't need to use the action on second run. You can call golangci-lint
directly:
jobs:
lint:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "${{ env.GO_VERSION }}"
- name: install deps
run: |
sudo apt -q update
sudo apt -q install libseccomp-dev
- uses: golangci/golangci-lint-action@v3
with:
version: "${{ env.LINT_VERSION }}"
# Extra linters, only checking new code from pull requests.
- run: golangci-lint --config .golangci-extra.yml --new-from-rev=origin/${{ github.base_ref }} --out-format=github-actions
Actually you don't need to use the action on second run. You can call
golangci-lint
directly.
Awesome, thanks, let me check this
Actually you don't need to use the action on second run. You can call
golangci-lint
directly.Awesome, thanks, let me check this
OTOH it would still be nice to have something like extra-run:
which would do the same without the need to specify extra options manually.
For some reason it's not working (quoting https://github.com/opencontainers/runc/runs/6017736006?check_suite_focus=true):
Run golangci-lint run --config .golangci-extra.yml --new-from-rev=origin/main --out-format=github-actions
level=warning msg="[runner] Can't process result by diff processor: can't prepare diff by revgrep: could not read git repo: error executing git diff \"origin/main\" \"\": exit status 128"
I also see that the implementation of only-new-issues
does some more than setting --new-from-rev
(see https://github.com/golangci/golangci-lint-action/blob/c675eb70db3aa26b496bc4e64da320480338d41b/src/run.ts#L22-L75) -- apparently it fetches the PR diff.
I guess I can use --new-from-rev=origin/main
if I check out the repo in full (i.e. add fetch-depth: 0
parameter to actions/checkout
, but that would be an overkill.
OK, made it working, see https://github.com/opencontainers/runc/pull/3457
It should, you need to have something like
jobs:
lint:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2 # So we can do git diff HEAD~1
- uses: actions/setup-go@v3
with:
go-version: "${{ env.GO_VERSION }}"
- name: install deps
run: |
sudo apt -q update
sudo apt -q install libseccomp-dev
- uses: golangci/golangci-lint-action@v3
with:
version: v1.45
# Extra linters, only checking new code from a pull request.
- run: golangci-lint run --config .golangci-extra.yml --new-from-rev=HEAD~1 --out-format=github-actions
This relies on the fact that the last commit being fetched is the merge commit (somehow created by github) which shows the full diff for the PR.
In my repository (https://github.com/opencontainers/runc) I use two distinct linter configs:
The first config is used everywhere (on main and release branches, as well as for PRs)
The second config is
only-new-issues: true
)if: github.event_name == 'pull_request'
)The idea behind this setup is simple: since we have a pretty big codebase, we can't possibly modify it to satisfy some more stricter and/or opinionated linters (such as
godot
,revive
,gocritic
, ordupl
), nor it makes sense to do so -- but we can impose stricter standards for the newly added code.Now, the GHA CI implementation (with the
.golangci-extra.yml
file with extra linters) looks like this:All this works, except that since I use
golangci/golangci-lint-action
twice, it actually downloads and installs golangci-lint twice (for example, see the log at https://github.com/opencontainers/runc/runs/5982042602?check_suite_focus=true.Proposal modify the action to detect that it is being used for the second time, and skip the second, redundant golangci-lint setup.