forked from ipdxco/unified-github-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
91 lines (90 loc) · 3.57 KB
/
go-check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: Go Checks
on:
workflow_call:
inputs:
go-version:
required: false
type: string
jobs:
unit:
runs-on: ubuntu-latest
name: All
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- id: config
uses: pl-strflt/uci/.github/actions/read-config@main
- id: go-mod
uses: pl-strflt/uci/.github/actions/read-go-mod@main
- id: go
uses: actions/setup-go@v4
with:
go-version: ${{ inputs.go-version || (fromJSON(steps.go-mod.outputs.json).Go && format('{0}.x', fromJSON(steps.go-mod.outputs.json).Go)) }}
cache: false
- name: Run repo-specific setup
uses: ./.github/actions/go-check-setup
if: hashFiles('./.github/actions/go-check-setup') != ''
- name: Install staticcheck
env:
STATICCHECK_VERSIONS: |
{
"1.21": "9e12e6014d3b0a854950490051ad1338fc6badd1",
"1.20": "9e12e6014d3b0a854950490051ad1338fc6badd1",
"1.19": "376210a89477dedbe6fdc4484b233998650d7b3c",
"1.18": "376210a89477dedbe6fdc4484b233998650d7b3c",
"1.17": "c8caa92bad8c27ae734c6725b8a04932d54a147b",
"1.16": "4dc1992c9bb4310ba1e98b30c8d7d46444891d3b",
"1.15": "5b7de96f09104e2be384aa93a7c821eb5e77378b",
"1.14": "5b7de96f09104e2be384aa93a7c821eb5e77378b",
"1.13": "afd67930eec2a9ed3e9b19f684d17a062285f16a"
}
GO_VERSION: ${{ steps.go.outputs.go-version }}
GO111MODULE: on
run: |
version="$(jq -nr 'env.STATICCHECK_VERSIONS | fromjson | .[env.GO_VERSION | sub("\\.[^.]+$"; "")] // "latest"')"
echo "Installing staticcheck@$version"
go install honnef.co/go/tools/cmd/staticcheck@$version || go get honnef.co/go/tools/cmd/staticcheck@$version
- name: Check that go.mod is tidy
uses: protocol/multiple-go-modules@v1.2
with:
run: |
go mod tidy
if [[ -n $(git ls-files --other --exclude-standard --directory -- go.sum) ]]; then
echo "go.sum was added by go mod tidy"
exit 1
fi
git diff --exit-code -- go.sum go.mod
- name: gofmt
if: success() || failure() # run this step even if the previous one failed
run: |
out=$(gofmt -s -l .)
if [[ -n "$out" ]]; then
echo $out | awk '{print "::error file=" $0 ",line=0,col=0::File is not gofmt-ed."}'
exit 1
fi
- name: go vet
if: success() || failure() # run this step even if the previous one failed
uses: protocol/multiple-go-modules@v1.2
with:
run: go vet ./...
- name: staticcheck
if: success() || failure() # run this step even if the previous one failed
uses: protocol/multiple-go-modules@v1.2
with:
run: |
set -o pipefail
staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g'
- name: go generate
uses: protocol/multiple-go-modules@v1.2
if: (success() || failure()) && fromJSON(steps.config.outputs.json).gogenerate == true
with:
run: |
git clean -fd # make sure there aren't untracked files / directories
go generate -x ./...
# check if go generate modified or added any files
if ! $(git add . && git diff-index HEAD --exit-code --quiet); then
echo "go generated caused changes to the repository:"
git status --short
exit 1
fi