Files
fleet/.github/workflows/golangci-lint.yml
T
jacobshandlingandVictor Lyuboslavsky 79b7d83bf5 Use nilaway to incrementally check for unsafe nil pointer dereferences (#39030)
**Related issue:** Resolves #32999 

- Enhanced internal code quality tooling by implementing a custom
linting build configuration.
- Updated continuous integration workflow to utilize the new custom
build process for improved code analysis and consistency checks.

### Confirmed that running local custom `golangci-lint` build with
`nilaway` plugin catches lots of issues when run on `fleet/`:
<img width="1555" height="939" alt="Screenshot 2026-01-29 at 2 47 50 PM"
src="https://github.com/user-attachments/assets/c6a18400-fdf0-4104-97d8-e117efc28ed6"
/>
<img width="301" height="109" alt="Screenshot 2026-01-29 at 2 48 36 PM"
src="https://github.com/user-attachments/assets/b459ee7b-b391-457a-9191-17d56a80c783"
/>

### Confirmed that new incremental CI step using custom `golangci-lint`
build with `nilaway` plugin _does not_ check any `.go` files when none
have been modified, and so passes successfully (incremental check works
as expected):
<img width="337" height="197" alt="Screenshot 2026-01-29 at 2 45 24 PM"
src="https://github.com/user-attachments/assets/c7ae585e-2e10-4ebf-a3a3-96c26063f1e4"
/>

### Confirmed that new incremental CI step using custom `golangci-lint`
build with `nilaway` plugin _does_ check modified lines of `.go` files,
and so successfully flags a potentially unsafe dereference and fails the
job (incremental check works as expected):
<img width="825" height="491" alt="Screenshot 2026-01-29 at 5 50 01 PM"
src="https://github.com/user-attachments/assets/82bc5616-6fb9-4357-b8bc-c7eebc42c2d8"
/>

### Honorable mention:
`nilaway` agrees that `listHostSoftware` is a wild beast:
<img width="1277" height="190" alt="Screenshot 2026-01-29 at 5 52 32 PM"
src="https://github.com/user-attachments/assets/dfade2a8-fbcc-4bae-98f9-6bf1089620d2"
/>

- [x] QA'd all new/changed functionality manually

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Fleet dev cycle reliability improvements**


<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Victor Lyuboslavsky <2685025+getvictor@users.noreply.github.com>
2026-02-06 08:51:17 -06:00

143 lines
5.1 KiB
YAML

name: golangci-lint
on:
push:
branches:
- main
- patch-*
- prepare-*
paths:
- '**.go'
- '.github/workflows/golangci-lint.yml'
- '.golangci.yml'
- '.golangci-incremental.yml'
- '.custom-gcl.yml'
pull_request:
paths:
- '**.go'
- '.github/workflows/golangci-lint.yml'
- '.golangci.yml'
- '.golangci-incremental.yml'
- '.custom-gcl.yml'
workflow_dispatch: # Manual
# This allows a subsequently queued workflow run to interrupt previous runs
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id}}
cancel-in-progress: true
defaults:
run:
# fail-fast using bash -eo pipefail. See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference
shell: bash
permissions:
contents: read
jobs:
golangci:
permissions:
contents: read # for actions/checkout to fetch code
pull-requests: read # for actions/checkout to fetch pull requests
name: lint
strategy:
fail-fast: false
matrix:
# See #9943, we just need to add windows-latest here once all issues are fixed.
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
# Tell git not to change line endings when checking out files on Windows. Without this gofmt
# flags every single file on windows-latest
- run: 'git config --global core.autocrlf input'
- name: Harden Runner
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
with:
egress-policy: audit
- name: Checkout code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Install Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version-file: 'go.mod'
- name: Install dependencies (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
# The following packages are needed to build Fleet Desktop on Ubuntu.
sudo apt update -y && sudo apt install -y gcc libgtk-3-dev libayatana-appindicator3-dev
- name: Run go lint
run: |
# Don't forget to update
# docs/Contributing/Testing-and-local-development.md when this version changes
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@a4b55ebc3471c9fbb763fd56eefede8050f99887 # v2.7.1
SKIP_INCREMENTAL=1 make lint-go
- name: Run cloner-check tool
run: |
go run ./tools/cloner-check/main.go -check
- name: Ensure all FLEET_DEV_* env var accesses are proxied
run: |
if grep -R 'os.Getenv("FLEET_DEV' --include="*.go" .; then
echo "Error: Found unproxied FLEET_DEV_* env var access. Please proxy via dev_mode.Env()." >&2
exit 1
else
echo "OK: No unproxied FLEET_DEV_* env var accesses found."
fi
- name: Restrict FLEET_DEV_* env var overrides to test code only
run: |
if grep -R 'SetOverride("FLEET_DEV' --include="*.go" --exclude="*_test.go" --exclude="testing_utils.go" --exclude-dir="mdmtest" .; then
echo "Error: Found FLEET_DEV_* overrides in non-test code." >&2
exit 1
else
echo "OK: No FLEET_DEV_* overrides in non-test code."
fi
golangci-incremental:
# Only run on pull requests (needs base branch for incremental comparison)
if: github.event_name == 'pull_request'
permissions:
contents: read
pull-requests: read
name: lint-incremental
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
with:
egress-policy: audit
- name: Checkout code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
fetch-depth: 0 # Fetch full history for accurate diff
- name: Install Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version-file: 'go.mod'
- name: Install dependencies (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
# The following packages are needed to build Fleet Desktop on Ubuntu.
sudo apt update -y && sudo apt install -y gcc libgtk-3-dev libayatana-appindicator3-dev
- name: Run incremental go lint
run: |
# Don't forget to update
# docs/Contributing/Testing-and-local-development.md when this version changes
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@a4b55ebc3471c9fbb763fd56eefede8050f99887 # v2.7.1
# custom build of golangci-lint that incorporates nilaway - see .custom-gcl.yml
golangci-lint custom
./custom-gcl run -c .golangci-incremental.yml --new-from-rev=origin/${{ github.base_ref }} --timeout 15m ./...