Debian Codegraph @

website/content/docs/running-staticcheck/ci/github-actions/index.md

raw
1 ---
2 title: GitHub Actions
3 description: Running Staticcheck in GitHub Actions
4 aliases:
5 - /docs/running-staticcheck/github-actions
6 ---
7 We publish [our own action](https://github.com/marketplace/actions/staticcheck) for [GitHub Actions](https://github.com/features/actions),
8 which makes it very simple to run Staticcheck in CI on GitHub.
9
10 ## Examples
11
12 At its simplest, just add `dominikh/staticcheck-action` as a step in your existing workflow.
13 A minimal workflow might look like this:
14
15 ```yaml
16 name: "CI"
17 on: ["push", "pull_request"]
18
19 jobs:
20 ci:
21 name: "Run CI"
22 runs-on: ubuntu-latest
23 steps:
24 - uses: actions/checkout@v1
25 with:
26 fetch-depth: 1
27 - uses: dominikh/[email protected]
28 with:
29 version: "2022.1.1"
30 ```
31
32 A more advanced example that runs tests, go vet and Staticcheck on multiple OSs and Go versions looks like this:
33
34 ```yaml
35 name: "CI"
36 on: ["push", "pull_request"]
37
38 jobs:
39 ci:
40 name: "Run CI"
41 strategy:
42 fail-fast: false
43 matrix:
44 os: ["windows-latest", "ubuntu-latest", "macOS-latest"]
45 go: ["1.16.x", "1.17.x"]
46 runs-on: ${{ matrix.os }}
47 steps:
48 - uses: actions/checkout@v1
49 with:
50 fetch-depth: 1
51 - uses: WillAbides/[email protected]
52 with:
53 go-version: ${{ matrix.go }}
54 - run: "go test ./..."
55 - run: "go vet ./..."
56 - uses: dominikh/[email protected]
57 with:
58 version: "2022.1.1"
59 install-go: false
60 cache-key: ${{ matrix.go }}
61 ```
62
63 Note that this example could benefit from further improvements, such as caching of Go's build cache.
64
65 ## Managing Go
66
67 By default, `staticcheck-action` installs Go so that it can install and run Staticcheck.
68 It also saves and restores Go's build cache (in addition to Staticcheck's own cache) to speed up future runs.
69 This is intended for trivial jobs that only run Staticcheck, not other steps such as `go test`.
70
71 For more complicated jobs, it is strongly recommended that you set `install-go` to `false`,
72 install Go yourself (e.g. by using [`actions/setup-go`](https://github.com/actions/setup-go) or [`WillAbides/setup-go-faster`](https://github.com/WillAbides/setup-go-faster)),
73 and save and restore the Go build cache, for improved performance.
74
75 When installing Go, make sure the version meets Staticcheck's minimum requirements.
76 A given Staticcheck release supports the last two versions of Go (such as Go 1.16 and Go 1.17) at the time of release.
77 The action itself requires at least Go 1.16.
78
79 ## Options
80
81 ### `version`
82
83 Which version of Staticcheck to use.
84 Because new versions of Staticcheck introduce new checks that may break your build,
85 it is recommended to pin to a specific version and to update Staticheck consciously.
86
87 It defaults to `latest`, which installs the latest released version of Staticcheck.
88
89 ### `min-go-version`
90
91 Minimum version of Go to support. This affects the diagnostics reported by Staticcheck,
92 avoiding suggestions that are not applicable to older versions of Go.
93
94 If unset, this will default to the Go version specified in your go.mod.
95
96 See https://staticcheck.dev/docs/running-staticcheck/cli/#go for more information.
97
98 ### `build-tags`
99
100 Go build tags that get passed to Staticcheck via the `-tags` flag.
101
102 ### `install-go`
103
104 Whether the action should install a suitable version of Go to install and run Staticcheck.
105 If Staticcheck is the only action in your job, this option can usually be left on its default value of `true`.
106 If your job already installs Go prior to running Staticcheck, for example to run unit tests, it is best to set this option to `false`.
107
108 The latest release of Staticcheck works with the last two minor releases of Go.
109 The action itself requires at least Go 1.16.
110
111 ### `cache-key`
112
113 String to include in the cache key, in addition to the default, which is `runner.os`.
114 This is useful when using multiple Go versions.