Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ nested module, run the action with `working-directory` set to that module.
It accepts unimported `testdata` files. The Linux lint job does not lint files that only
load on Windows or macOS.

The full-tree dead-code check runs last. It fails on any `unused` or
`unparam` finding, and the directive check rejects new suppressions for
both linters. Set `dead-code: "false"` to turn off both checks. To check
for dead code on pushes to `main`, run:

```sh
golangci-lint run --config .golangci.yaml --enable-only unused,unparam \
--allow-parallel-runners --issues-exit-code=1 --path-prefix=./ ./...
```

Set `working-directory` for a Go module outside the repo root. Set `config`
and `baseline` to paths relative to that directory to use different names.
Use `golangci-lint-version` to override `v2.15.0` or `guarded-linters` to
Expand Down
16 changes: 16 additions & 0 deletions lint-baseline/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ inputs:
allow-new-modules:
description: Allow new go.mod and go.work files.
default: "false"
dead-code:
description: Check the whole Go module for unused code and parameters.
default: "true"
runs:
using: composite
steps:
Expand Down Expand Up @@ -135,6 +138,7 @@ runs:
ALLOW_GENERATED: ${{ inputs.allow-generated }}
ALLOW_NEW_MODULES: ${{ inputs.allow-new-modules }}
MODULE_DIR: ${{ inputs.working-directory }}
DEAD_CODE: ${{ inputs.dead-code }}
run: |
tags=$("$RUNNER_TEMP/lint-baseline" config-check --config "$CONFIG" --linters "$BASELINE_LINTERS")
bash "$GITHUB_ACTION_PATH/with-lint-env.sh" bash -ec '
Expand All @@ -145,6 +149,7 @@ runs:
GOOS=$os CGO_ENABLED=1 go list -e -json="$fields" -deps -test "${args[@]}" ./...
done > "$RUNNER_TEMP/golist.json"
' _ "$tags"
[[ $DEAD_CODE != true ]] || GUARDED_LINTERS+=,unused,unparam
GIT_ATTR_SOURCE=$PR_MERGE_BASE git -c core.quotePath=true -C "$GITHUB_WORKSPACE" diff \
--no-ext-diff --no-textconv --no-color --no-relative --no-renames --text \
--src-prefix=a/ --dst-prefix=b/ --unified=0 --inter-hunk-context=0 \
Expand Down Expand Up @@ -190,3 +195,14 @@ runs:
bash "$GITHUB_ACTION_PATH/lint-json.sh" "$CONFIG" "$RUNNER_TEMP/lint.json"
"$RUNNER_TEMP/lint-baseline" check --lint-json "$RUNNER_TEMP/lint.json" \
--baseline "$BASELINE" "${base_args[@]}" --root .
- name: Check full-tree dead code
if: inputs.dead-code == 'true'
shell: bash
working-directory: ${{ inputs.working-directory }}
env:
CONFIG: ${{ inputs.config }}
run: |
bash "$GITHUB_ACTION_PATH/with-lint-env.sh" bash -o pipefail -c '
golangci-lint run --config "$CONFIG" --enable-only unused,unparam --allow-parallel-runners \
--issues-exit-code=1 --path-prefix=./ ./... 2>&1 | tr "\r" " " | sed "s/^/lint:dead: /"
'