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
86 changes: 86 additions & 0 deletions .github/workflows/go-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ on:
type: string
required: false
default: ''
govulncheck:
description: >-
Check the module and the Go standard library against the Go vulnerability
database (govulncheck reports only vulnerabilities the code calls).
'fail' fails the job on a finding, 'warn' reports it as a warning without
failing (while a fix is on its way), 'off' skips the check.
type: string
required: false
default: 'fail'
govulncheck-version:
description: >-
golang.org/x/vuln release to run (e.g. v1.10.0). Pinned like
golangci-lint-version, so a new release can't break callers without a
code change; bumped via Renovate PRs.
type: string
required: false
# renovate: datasource=go depName=golang.org/x/vuln
default: 'v1.10.0'

jobs:
quality:
Expand Down Expand Up @@ -77,3 +95,71 @@ jobs:

- name: Run Unit Tests
run: go test ./... -v

vulncheck:
name: Vulnerability check
if: inputs.govulncheck != 'off'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Check the govulncheck input
env:
MODE: ${{ inputs.govulncheck }}
run: |
case "$MODE" in
fail|warn) ;;
*) echo "::error::govulncheck must be 'fail', 'warn' or 'off', not '$MODE'"; exit 1 ;;
esac

- name: Checkout repository
uses: actions/checkout@v7

- name: Set up Go
uses: actions/setup-go@v7
with:
go-version: ${{ inputs.go-version }}
cache: true

- name: Set up Node.js
if: inputs.node-version != ''
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: ${{ inputs.node-cache-dependency-path != '' && 'npm' || '' }}
cache-dependency-path: ${{ inputs.node-cache-dependency-path }}

- name: Pre-build
if: inputs.pre-build-command != ''
env:
PRE_BUILD_COMMAND: ${{ inputs.pre-build-command }}
run: bash -euo pipefail -c "$PRE_BUILD_COMMAND"

# govulncheck is built with the job's Go (go run), so it can read the
# standard library of the version the code is built with. Exit code 3
# means vulnerabilities were found; anything else non-zero is an error
# (the code didn't load), which fails the job in both modes.
- name: Run govulncheck
env:
MODE: ${{ inputs.govulncheck }}
VERSION: ${{ inputs.govulncheck-version }}
run: |
set +e
go run "golang.org/x/vuln/cmd/govulncheck@${VERSION}" ./... | tee "$RUNNER_TEMP/govulncheck.txt"
rc=${PIPESTATUS[0]}
set -e
if [ "$rc" -eq 3 ]; then
{
echo "## govulncheck: vulnerabilities found"
echo
echo '```'
cat "$RUNNER_TEMP/govulncheck.txt"
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
if [ "$MODE" = "warn" ]; then
echo "::warning::govulncheck found vulnerabilities the code calls (govulncheck: warn, so the job passes). See the job summary."
exit 0
fi
echo "::error::govulncheck found vulnerabilities the code calls. Update the listed modules or Go, or set govulncheck: warn while a fix is on its way."
fi
exit "$rc"
11 changes: 10 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ All repositories in `divmora` should call the centralized reusable workflows hos

| Reusable Workflow | Purpose | Caller Example |
|:---|:---|:---|
| **`go-ci.yml`** | Go linting (`golangci-lint`) and unit testing. | `uses: divmora/.github/.github/workflows/go-ci.yml@main` |
| **`go-ci.yml`** | Go linting (`golangci-lint`), unit testing and a vulnerability check (`govulncheck`). | `uses: divmora/.github/.github/workflows/go-ci.yml@main` |
| **`node-ci.yml`** | Node.js / TypeScript testing, linting, and building with pnpm/npm caching. | `uses: divmora/.github/.github/workflows/node-ci.yml@main` |
| **`python-ci.yml`** | Python testing (`pytest`) and linting (`ruff`). | `uses: divmora/.github/.github/workflows/python-ci.yml@main` |
| **`cfn-ci.yml`** | AWS CloudFormation & StackSet template linting (`cfn-lint`, `yamllint`). | `uses: divmora/.github/.github/workflows/cfn-ci.yml@main` |
Expand Down Expand Up @@ -228,6 +228,15 @@ A repo whose Go build needs files that aren't committed (for example a web UI th
```
- golangci-lint v2 needs a v2-format `.golangci.yml` (`version: "2"`). A v1 config fails with `unsupported version of the configuration`. Because the workflow uses `install-mode: goinstall`, the caller's `go-version` must also meet the release's minimum Go version (v2.15.0 needs Go >= 1.26).

### `go-ci.yml`: vulnerability check (govulncheck)

`go-ci.yml` has a **Vulnerability check** job that runs [govulncheck](https://go.dev/doc/security/vuln/) on the module. It reports only vulnerabilities in code the program actually calls, in its modules or the Go standard library, so findings are real.

- **Input `govulncheck`**: `fail` (default) fails the job on a finding; `warn` reports it (a warning plus the full report in the job summary) without failing; `off` skips the job. Use `warn` only while a fix is on its way, and go back to `fail` once it lands.
- **Same build as the tests**: the job uses the caller's `go-version`, `node-version` and `pre-build-command`, and builds govulncheck with that Go. Standard-library findings depend on that Go version: `go-version: '1.26'` installs the latest 1.26 patch. A `go-version` older than `go.mod`'s `go` line makes Go switch to exactly that `go.mod` version, an old patch, so keep `go-version` at least the `go.mod` minor.
- **Pinned release**: input `govulncheck-version` (golang.org/x/vuln), bumped by Renovate like golangci-lint.
- **Fixing a finding**: the report names the module and the fixed version. Run `go get <module>@<fixed version> && go mod tidy`, or raise `go-version` for a standard-library fix. To check locally: `go run golang.org/x/vuln/cmd/govulncheck@latest ./...`.

---

## 6. Standard Verification Commands Matrix
Expand Down
11 changes: 9 additions & 2 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"description": "Dependabot handles actions, gomod, npm, pip and docker here. Renovate covers only values Dependabot cannot bump, such as the pinned golangci-lint version in go-ci.yml.",
"description": "Dependabot handles actions, gomod, npm, pip and docker here. Renovate covers only values Dependabot cannot bump, such as the pinned golangci-lint and govulncheck versions in go-ci.yml.",
"extends": ["config:recommended"],
"enabledManagers": ["custom.regex"],
"customManagers": [
{
"customType": "regex",
"description": "Bump the pinned golangci-lint version in reusable workflows",
"description": "Bump the pinned golangci-lint and govulncheck versions in reusable workflows",
"managerFilePatterns": ["/^\\.github/workflows/[^/]+\\.ya?ml$/"],
"matchStrings": [
"# renovate: datasource=(?<datasource>[a-z-]+) depName=(?<depName>[^\\s]+)\\s+default: '(?<currentValue>[^']+)'"
Expand All @@ -20,6 +20,13 @@
"semanticCommitScope": "",
"commitMessageTopic": "golangci-lint",
"labels": ["dependencies", "ci"]
},
{
"matchDepNames": ["golang.org/x/vuln"],
"semanticCommitType": "ci",
"semanticCommitScope": "",
"commitMessageTopic": "govulncheck",
"labels": ["dependencies", "ci"]
}
]
}