├── CHANGES.md ├── FUNDING.yml ├── LICENSE ├── README.md ├── action.yaml └── matchers.json /CHANGES.md: -------------------------------------------------------------------------------- 1 | # 1.3.1 2 | - Update README to be clearer 3 | - Update README to provide timeless examples 4 | - Update setup-go-faster dependency from v1.8.0 to v1.14.0 5 | - Update actions/cache dependency from v3 to v4 6 | - Update installed Go version from 1.19.x to "stable" 7 | 8 | # 1.3.0 9 | - Add the output-format option 10 | - Add the output-file option 11 | - Add the merge-files option 12 | - Update action/cache dependency from v2 to v3 13 | - Update setup-go-faster dependency from v1.7.0 to v1.8.0 14 | - Update installed Go version from 1.17.x to 1.19.x 15 | 16 | # 1.2.0 17 | - Add the `checks` option 18 | - Add the `working-directory` option 19 | 20 | # 1.1.0 21 | - The action will store and restore Go's cache if install-go is set to true. 22 | 23 | # 1.0.0 24 | Initial release. 25 | -------------------------------------------------------------------------------- /FUNDING.yml: -------------------------------------------------------------------------------- 1 | patreon: dominikh 2 | github: dominikh 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Dominik Honnef 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # staticcheck-action 2 | 3 | This action runs [Staticcheck](https://staticcheck.io) to find bugs and other problems in your Go code. 4 | 5 | ## Usage 6 | 7 | At its simplest, just add `dominikh/staticcheck-action` as a step in your existing workflow. 8 | A minimal workflow might look like this: 9 | 10 | ```yaml 11 | name: "CI" 12 | on: ["push", "pull_request"] 13 | 14 | jobs: 15 | ci: 16 | name: "Run CI" 17 | runs-on: ubuntu-latest 18 | steps: 19 | - uses: actions/checkout@v2 20 | with: 21 | fetch-depth: 1 22 | - uses: dominikh/staticcheck-action@v1 23 | with: 24 | version: "latest" 25 | ``` 26 | 27 | A more advanced example that runs tests, go vet and Staticcheck on multiple OSs and Go versions looks like this: 28 | 29 | ```yaml 30 | name: "CI" 31 | on: ["push", "pull_request"] 32 | 33 | jobs: 34 | ci: 35 | name: "Run CI" 36 | strategy: 37 | fail-fast: false 38 | matrix: 39 | os: ["windows-latest", "ubuntu-latest", "macOS-latest"] 40 | go: ["1.18.x", "1.19.x"] 41 | dir: ["server", "client"] 42 | runs-on: ${{ matrix.os }} 43 | steps: 44 | - uses: actions/checkout@v2 45 | with: 46 | fetch-depth: 1 47 | - uses: WillAbides/setup-go-faster@v1.14.0 48 | with: 49 | go-version: ${{ matrix.go }} 50 | - run: "go test ./..." 51 | - run: "go vet ./..." 52 | - uses: dominikh/staticcheck-action@v1 53 | with: 54 | version: "latest" 55 | install-go: false 56 | cache-key: ${{ matrix.go }} 57 | working-directory: ${{ matrix.dir }} 58 | ``` 59 | 60 | 61 | 62 | Please see [GitHub's documentation on Actions](https://docs.github.com/en/actions) for extensive 63 | documentation on how to write and tweak workflows. 64 | 65 | ## Options 66 | 67 | ### `version` 68 | 69 | Which version of Staticcheck to use. 70 | Because new versions of Staticcheck introduce new checks that may break your build, 71 | it is recommended to pin to a specific version and to update Staticheck consciously. 72 | 73 | It defaults to `latest`, which installs the latest released version of Staticcheck. 74 | 75 | ### `min-go-version` 76 | 77 | Minimum version of Go that Staticcheck will report diagnostics for. That is, some 78 | diagnostics don't apply to older versions of Go. 79 | 80 | If unset, this will default to the Go version specified in your go.mod. The default is 81 | usually what you want. 82 | 83 | See https://staticcheck.io/docs/running-staticcheck/cli/#go for more information. 84 | 85 | ### `build-tags` 86 | 87 | Go build tags that get passed to Staticcheck via the `-tags` flag. 88 | 89 | ### `install-go` 90 | 91 | Whether the action should install the latest version of Go to install and run Staticcheck. 92 | If Staticcheck is the only action in your job, this option can usually be left on its default value of `true`. 93 | 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`. 94 | 95 | The latest release of Staticcheck works with the last minor release of Go at the time. 96 | 97 | ### `cache-key` 98 | 99 | String to include in the cache key, in addition to the default, which is `runner.os`. 100 | This is useful when using multiple Go versions. 101 | 102 | ### `working-directory` 103 | 104 | Relative path to the working directory Staticcheck should be executed in. 105 | This is useful when dealing with multiple projects within one repository. 106 | 107 | Can be easily combined with a directory [`matrix`](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix), 108 | see the advanced example above. 109 | 110 | -------------------------------------------------------------------------------- /action.yaml: -------------------------------------------------------------------------------- 1 | name: "Staticcheck" 2 | description: "Run Staticcheck on your Go code" 3 | author: "Dominik Honnef" 4 | branding: 5 | icon: "alert-triangle" 6 | color: "blue" 7 | inputs: 8 | version: 9 | description: | 10 | The version of Staticcheck to use. Because new versions of 11 | Staticcheck introduce new checks that may break your build, it 12 | is recommended to pin to a specific version and to update 13 | Staticheck consciously. 14 | required: true 15 | default: "latest" 16 | min-go-version: 17 | description: | 18 | Minimum version of Go to support. This affects the diagnostics 19 | reported by Staticcheck, avoiding suggestions that are not 20 | applicable to older versions of Go. 21 | 22 | If unset, this will default to the Go version specified in your 23 | go.mod. 24 | 25 | See https://staticcheck.io/docs/running-staticcheck/cli/#go 26 | for more information. 27 | required: false 28 | default: "module" 29 | build-tags: 30 | description: "Build tags" 31 | required: false 32 | checks: 33 | description: | 34 | Value to pass to Staticcheck in the -checks flag. This doesn't 35 | normally need to be set. 36 | required: false 37 | default: "inherit" 38 | install-go: 39 | description: | 40 | Let the action install the latest version of Go. 41 | If set to false, the action expects you to have installed Go already. 42 | The latest release of Staticcheck works with the last minor release of Go at that time. 43 | The action itself requires at least Go 1.16. 44 | required: true 45 | default: true 46 | cache-key: 47 | description: | 48 | String to include in the cache key, in addition to the default, which is runner.os. 49 | This is useful when using multiple Go versions. 50 | required: false 51 | working-directory: 52 | description: | 53 | Relative path to the working directory Staticcheck should be executed in. 54 | This is useful when dealing with multiple projects within one repository. 55 | required: false 56 | default: "." 57 | output-format: 58 | description: | 59 | Output format to use. This corresponds to Staticcheck's -f flag. Usually you will want to use the default 60 | ("text"), as this format creates annotations on pull requests. When combining multiple runs with merge-files, you 61 | want to use the "binary" format on the individual runs to create the inputs to the merge run. 62 | required: false 63 | default: "text" 64 | output-file: 65 | description: | 66 | File to write Staticcheck's output to. Defaults to stdout. 67 | required: false 68 | merge-files: 69 | description: | 70 | A newline-separated list of files to pass to "staticcheck -merge". 71 | required: false 72 | 73 | runs: 74 | using: "composite" 75 | steps: 76 | - id: install_go 77 | if: ${{ inputs.install-go != 'false' }} 78 | uses: WillAbides/setup-go-faster@v1.14.0 79 | with: 80 | go-version: "stable" 81 | - uses: actions/cache@v4 82 | if: ${{ inputs.merge-files == '' }} 83 | with: 84 | path: | 85 | ${{ runner.temp }}/staticcheck 86 | ${{ inputs.install-go != 'false' && steps.install_go.outputs.GOCACHE || '' }} 87 | # use a unique cache key for storing, then restore from the newest cache entry we can. 88 | key: staticcheck-${{ runner.os }}-${{ inputs.cache-key }}-${{ github.sha }} 89 | restore-keys: | 90 | staticcheck-${{ runner.os }}-${{ inputs.cache-key }}- 91 | - env: 92 | version: ${{ inputs.version }} 93 | buildTags: ${{ inputs.build-tags }} 94 | minGoVersion: ${{ inputs.min-go-version }} 95 | checks: ${{ inputs.checks }} 96 | format: ${{ inputs.output-format }} 97 | file: ${{ inputs.output-file }} 98 | merge: ${{ inputs.merge-files }} 99 | working-directory: ${{ inputs.working-directory }} 100 | run: | 101 | export STATICCHECK_CACHE="${{ runner.temp }}/staticcheck" 102 | go install "honnef.co/go/tools/cmd/staticcheck@${version}" 103 | echo "::add-matcher::$GITHUB_ACTION_PATH/matchers.json" 104 | write_output() { 105 | if [ -z "${file}" ]; then 106 | cat 107 | else 108 | cat >"${file}" 109 | fi 110 | } 111 | if [ -z "${merge}" ]; then 112 | $(go env GOPATH)/bin/staticcheck -tags "${buildTags}" -checks "${checks}" -f "${format}" -go "${minGoVersion}" ./... | write_output 113 | else 114 | IFS=$'\n' 115 | $(go env GOPATH)/bin/staticcheck -checks "${checks}" -f "${format}" -merge ${merge} | write_output 116 | fi 117 | shell: bash 118 | -------------------------------------------------------------------------------- /matchers.json: -------------------------------------------------------------------------------- 1 | { 2 | "problemMatcher": [ 3 | { 4 | "owner": "staticcheck", 5 | "pattern": [ 6 | { 7 | "regexp": "^\\s*(.+\\.go):(?:(\\d+):(\\d+):)? (.*)", 8 | "file": 1, 9 | "line": 2, 10 | "column": 3, 11 | "message": 4 12 | } 13 | ] 14 | } 15 | ] 16 | } 17 | --------------------------------------------------------------------------------