# Add govulncheck to a Cobra CLI's CI

Yes. An agent adds a govulncheck workflow to your Cobra CLI that fails only on vulnerabilities the binary can reach, runs on pushes and weekly, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-govulncheck-to-ci/cobra/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads what CI already runs before adding a job, because a vulnerability scan that duplicates the test matrix or runs on a toolchain that cannot install the scanner is noise. In a Cobra CLI like spf13/cobra-cli, `go.mod` declares `go 1.15` with two direct dependencies, `github.com/spf13/cobra` v1.6.1 and `github.com/spf13/viper` v1.12.0, and `main.go` calls `cmd.Execute()` from `cmd/root.go`, where `rootCmd` registers `add` and `init` with `--config`, `--author`, `--license` and `--viper` flags bound through viper. `.github/workflows/test.yml` runs on push, pull request and dispatch: a `golangci-lint` job on Go 1.17 with `golangci-lint-action@v2`, a `test-unix` matrix of Ubuntu and macOS across Go 1.14 to 1.17 that installs `richgo` and `gox` and runs `make test build`, and a `test-win` job under MSYS2. `.github/dependabot.yml` already opens weekly pull requests for `gomod` and `github-actions`. The `Makefile` runs `richgo test -v ./...` and cross-builds with `gox` into `bin/`.

Dependabot says a newer version exists; it does not say whether the version in use has a known vulnerability, or whether the binary calls the affected function. That is govulncheck's job, so the agent adds `.github/workflows/govulncheck.yml` rather than a step inside the matrix: the scanner needs a current Go toolchain to install, and the matrix exists to prove the CLI still builds on old ones. The workflow runs on `push`, `pull_request`, `workflow_dispatch` and a weekly `schedule`, with `permissions: contents: read` and one job that uses `golang/govulncheck-action`, pinned to its v1.1.0 release, with `go-package: ./...` and `cache-dependency-path: go.sum`. `go-version-input` is left at the action's default of `stable`, which the pull request explains: the `go 1.15` directive in `go.mod` is a floor, so the module builds on a current toolchain, and a scan on a toolchain Go no longer supports would be a scan of a standard library nobody ships. `output-format` stays `text`, because the action's `json` and `sarif` formats return success even when something is found and the point of the job is to fail.

The schedule matters more than the push trigger. Advisories are published against code that has not changed, so a repository with no commits for a month still needs to learn that `viper` v1.12.0 or one of its transitive modules has a finding. The weekly run gives the maintainers that signal on the Actions tab without a pull request to prompt it, and `workflow_dispatch` lets a maintainer re-run after reading an advisory. The agent writes the cron in the workflow with a comment on the day and hour in UTC.

In its sandbox the agent installs the scanner with `go install golang.org/x/vuln/cmd/govulncheck@latest`, runs `govulncheck ./...` against the module, and puts the output in the pull request description. Findings are listed by module, affected function and fixed version, and `go.mod` is not changed in this pull request, so that a dependency bump is reviewed on its own, with the scan as its reason. The agent validates the workflow file with `actionlint`, runs `go build ./...` and `go test ./...` so the branch is known good, adds a line to `README.md` under the existing development notes saying how to run the scan locally, and opens the pull request.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add govulncheck to this Cobra CLI's CI. Read go.mod, main.go, cmd/root.go, Makefile, .golangci.yml, .github/workflows/test.yml and .github/dependabot.yml first. Write .github/workflows/govulncheck.yml that runs on push, pull_request, workflow_dispatch and a weekly schedule, with permissions contents read, using golang/govulncheck-action pinned to its v1.1.0 release with go-package ./... and cache-dependency-path go.sum; leave go-version-input at its default stable and keep output-format text so the job fails on a reachable vulnerability; explain in the pull request why the scan does not join the Go 1.14 to 1.17 matrix. Install govulncheck here with go install golang.org/x/vuln/cmd/govulncheck@latest, run govulncheck ./..., and paste the output into the pull request; if it reports findings, list each with its module, function and fixed version but do not change go.mod. Validate the workflow with actionlint, run go build ./... and go test ./..., add a short README note on running the scan locally, and open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request that adds `.github/workflows/govulncheck.yml` and a few lines to `README.md`. The description pastes the `govulncheck ./...` output from the sandbox, either the line saying no vulnerabilities were found or the findings with module, function and fixed version, and states why the job uses a current Go toolchain rather than the matrix's versions.

The run's record holds the scanner install, the scan, the `actionlint` run, and `go build` and `go test` on the branch. `go.mod`, `go.sum` and `test.yml` are unchanged; the new workflow sits beside the existing one and shares its triggers.

Before merging, a reviewer decides what to do with any finding the description lists, since the job will fail on the pull request's own push if a reachable vulnerability exists, and whether Dependabot's weekly `gomod` pull requests should now be gated on this check through the repository's branch protection.

## Run it on every new Go repository

A team with many Go modules starts one run per repository from its own server: one `POST /o/{org}/sessions` each, with that repository in `resources` and a `request_id` that is a UUID v5 of the repository's full name, so a retried call returns the run already started rather than a second pull request. Each run reads that module's own workflows, so a repository that already runs the scan gets no duplicate and one with a `go.work` file gets `go-version-file` pointed at it.

Once the workflow is in, an automation on the Project with a `github` trigger on `pull_request.opened` and `pull_request.synchronize` and the prompt "if this pull request changes go.mod, run govulncheck ./... on the branch and comment with any finding and its fixed version" turns every Dependabot bump into a scanned one. The trigger adds the pull request after the prompt; only work by an owner, member or collaborator fires it, never a fork's.

## Why run it on Rush?

A vulnerability workflow is easy to add and easy to add wrong: a scan in a matrix whose oldest toolchain cannot install the scanner, a JSON output that never fails the job, or a workflow that runs only on push and so never catches an advisory against unchanged code. The agent reads the existing matrix and the action's inputs, runs the scanner for real on the module in its own sandbox, and writes the one workflow that fits.

The sandbox keeps the scan output and the build and test runs with the run, and the pull request cites them. For a team with many Go CLIs and services, each gets its own run and its own pull request with its own first scan, so the maintainers see the state of each module rather than a template.

## Frequently asked questions

### Why not add govulncheck as a step in the existing test matrix?

Because the matrix runs Go 1.14 to 1.17 to prove the CLI still builds there, and the scanner needs a current toolchain to install. A separate job on `stable` scans the module as it would be built today, and the module's `go 1.15` directive is a floor, not a pin, so it builds fine. The matrix keeps its purpose and the scan keeps its toolchain.

### Will the job fail on vulnerabilities the binary never calls?

No. govulncheck reports a finding as affecting the binary only when a call path from the module's code reaches the vulnerable function; findings in modules that are imported but not reached are listed separately and do not fail the job. That is why it adds something Dependabot cannot: Dependabot knows a newer version exists, not whether the current one matters.

### Why keep text output rather than SARIF for the Security tab?

Because the action returns success with `json` or `sarif` output even when findings exist, so a workflow using them cannot block a merge. A reviewer who wants SARIF uploads can add a second job that writes to a file and uploads it; the pull request says so and keeps the failing job as the gate.

### What happens if the first scan finds something?

The pull request lists it with the module, the function and the version that fixes it, and the workflow's own run on the branch fails, which is the honest state. The fix is a `go get` bump reviewed on its own; the agent keeps `go.mod` out of this change so the workflow and the upgrade are two decisions.

## More Cobra jobs

- [Add a JSON Output Flag to a Cobra CLI](https://getrush.ai/run/add-json-output-flag/cobra/)
- [Generate Man Pages for a Cobra CLI](https://getrush.ai/run/add-man-page/cobra/)
- [Add an SBOM to the Release of a Cobra CLI](https://getrush.ai/run/add-sbom-to-release/cobra/)

## The same job on other stacks

- [Add govulncheck to CI for a Fiber Multi-Module Repository](https://getrush.ai/run/add-govulncheck-to-ci/fiber/)
- [Add govulncheck to a Go CLI's CI](https://getrush.ai/run/add-govulncheck-to-ci/go-cli/)

## More jobs like this: Hand off a long task

- [Add Graceful Shutdown to an Actix Web App](https://getrush.ai/run/add-graceful-shutdown/actix/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
