-
Notifications
You must be signed in to change notification settings - Fork 105
99 lines (99 loc) · 3.01 KB
/
go.yaml
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
92
93
94
95
96
97
98
99
name: Go
on:
push:
branches:
- main
paths:
- "cx-content-moderation/**"
pull_request:
branches:
- main
paths:
- "cx-content-moderation/**"
permissions: read-all
jobs:
# Split build and lint into a few different jobs so they can run in parallel.
build:
name: Build
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./cx-content-moderation
steps:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "^1.20"
- name: Checkout code
uses: actions/checkout@v4
- name: Build code
# Use find to build all modules. '-execdir ... ;' doesn't set an exit code
# based on command results. So, create a file if a build fails and check
# if the file exists to set the right exit code.
run: |
ROOT_DIR=$(pwd) \
find . -name go.mod -execdir sh -c 'go build ./... || touch $ROOT_DIR/build_failed.txt' \; ; \
test ! -f build_failed.txt
lint:
name: Lint
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./cx-content-moderation
steps:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "^1.20"
- name: Checkout code
uses: actions/checkout@v4
- name: Install goimports
run: go install golang.org/x/tools/cmd/goimports@latest
- run: goimports -w .
- name: Run go mod tidy on all modules
run: find . -name go.mod -execdir go mod tidy \;
# If there are any diffs from goimports or go mod tidy, fail.
- name: Verify no changes from goimports and go mod tidy.
run: |
if [ -n "$(git status --porcelain)" ]; then
echo 'To fix this check, run "goimports -w . && find . -name go.mod -execdir go mod tidy \;"'
git status # Show the files that failed to pass the check.
exit 1
fi
- name: shellcheck
run: find . -name "*.sh" -exec shellcheck {} \;
vet:
name: Vet
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./cx-content-moderation
steps:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "^1.20"
- name: Checkout code
uses: actions/checkout@v4
- name: go vet
# Use find to build all modules. '-execdir ... ;' doesn't set an exit code
# based on command results. So, create a file if a build fails and check
# if the file exists to set the right exit code.
run: |
ROOT_DIR=$(pwd) \
find . -name go.mod -execdir sh -c 'go vet ./... || touch $ROOT_DIR/vet_failed.txt' \; ; \
test ! -f vet_failed.txt
test:
name: Root tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./cx-content-moderation
steps:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "^1.20"
- name: Check code
uses: actions/checkout@v4
- run: go test -v