-
Notifications
You must be signed in to change notification settings - Fork 0
219 lines (206 loc) · 6.9 KB
/
golang.yaml
File metadata and controls
219 lines (206 loc) · 6.9 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
name: Golang CI
on:
pull_request:
branches:
- main
paths:
- '**.go'
permissions:
contents: write
pull-requests: write
jobs:
golang-build-check:
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
working-directory: scripts/dofy
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-golang
- name: Run go build
run: go build -v ./cmd/main.go
golang-vet-check:
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
working-directory: scripts/dofy
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-golang
- name: Run go vet
run: go vet ./...
golang-fmt-check:
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
working-directory: scripts/dofy
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-golang
- name: Run go fmt
run: go fmt ./...
- name: Check diff
run: |
if [[ $(git status --porcelain) ]]; then
git diff
exit 1
fi
golang-lint-check:
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
working-directory: scripts/dofy
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-golang
- uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
with:
working-directory: scripts/dofy
golang-test-comment-check:
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
working-directory: scripts/dofy
env:
HTML_REPORT_URL_PATH: reports/${{ github.ref_name }}/${{ github.run_id }}/${{ github.run_attempt }}/cov
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-golang
- uses: Homebrew/actions/setup-homebrew@dfdfb5351a41336813a6f4ea45c6dddbc6bcf464
- name: Run go test
id: golang-test
run: |
set +e
TEST_OUT=$(go test ./... -coverpkg=./... -coverprofile=cover.out -p=5)
TEST_EXIT_CODE=$?
if [ $TEST_EXIT_CODE -eq 0 ]; then
go tool cover -html=cover.out -o index.html
fi
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
{
echo "comment<<$EOF"
printf "# Test coverage\n\n"
if [ $TEST_EXIT_CODE -eq 0 ]; then
printf ":white_check_mark: All tests passed successfully.\n\n"
printf "| Status | Package | Time | Coverage |\n"
printf "|--------|---------|------|----------|\n"
echo "$TEST_OUT" | sed -E "s/^\?\s+/?:/g; s/^ok\s+/ok:/g; s/^\s/:/g; s/\s+/ /g; s/coverage:/::/g; s/([0-9.]+)s\s::/\:\1s\:/g; s/ of statements//g;" | sed -e "s/in .\/...//g" | awk -F'[:]' '{ print "| " $1 " | " $2 " | " $3 " |" $4 " |"}'
else
printf ":red_circle: Some tests failed.\n\n"
printf "<details>\n"
printf "<summary>go test result</summary>\n"
printf "\n\`\`\`\n\n"
echo "$TEST_OUT"
printf "\n\`\`\`\n\n"
printf "</details>\n"
fi
echo "$EOF"
} >> "$GITHUB_ENV"
exit $TEST_EXIT_CODE
continue-on-error: true
- uses: actions/upload-artifact@v4
if: ${{ steps.golang-test.outcome == 'success' }}
with:
name: cov html
path: ${{ github.workspace }}/scripts/dofy/index.html
if-no-files-found: error
- uses: actions/checkout@v4
if: ${{ steps.golang-test.outcome == 'success' }}
with:
ref: github-pages
clean: false
- name: Set Git User
if: ${{ steps.golang-test.outcome == 'success' }}
working-directory: .
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Push HTML Report
if: ${{ steps.golang-test.outcome == 'success' }}
timeout-minutes: 3
working-directory: .
run: |
mkdir -p ${{ env.HTML_REPORT_URL_PATH }}
mv ./scripts/dofy/index.html ${{ env.HTML_REPORT_URL_PATH }}/index.html
git add ${{ env.HTML_REPORT_URL_PATH }}
git commit -m "workflow: add HTML report for run-id ${{ github.run_id }} (attempt: ${{ github.run_attempt }})"
while true; do
if ! git pull --rebase; then
echo "Failed to rebase. Please review manually."
exit 1
fi
if git push; then
echo "Successfully pushed HTML report to repo."
exit 0
fi
done
- uses: actions/checkout@v4
if: ${{ steps.golang-test.outcome == 'success' }}
- name: Create PR comment
uses: marocchino/sticky-pull-request-comment@d2ad0de260ae8b0235ce059e63f2949ba9e05943 # v2.9.3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ github.event.pull_request.number }}
header: golang-test
message: |
${{ env.comment }}
## Cov HTML ${{ github.run_id }}: ${{ github.run_attempt }}
[Cov HTML Report](https://shiron-dev.github.io/dotfiles/${{ env.HTML_REPORT_URL_PATH }})
- name: Error check
if: ${{ steps.golang-test.outcome != 'success' }}
run: exit 1
golang-test-check:
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
working-directory: scripts/dofy
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-golang
- uses: Homebrew/actions/setup-homebrew@dfdfb5351a41336813a6f4ea45c6dddbc6bcf464
- name: Set up gotestfmt
uses: gotesttools/gotestfmt-action@8b4478c7019be847373babde9300210e7de34bfb # v2.5.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run go test
id: golang-test
run: |
set +e
TEST_OUT=$(go test -json -v ./... -p=5 2>&1)
TEST_EXIT=$?
echo "$TEST_OUT" | tee /tmp/gotest.log | gotestfmt
exit $TEST_EXIT
continue-on-error: true
- uses: actions/upload-artifact@v4
with:
name: test-log
path: /tmp/gotest.log
if-no-files-found: error
- name: Error check
if: ${{ steps.golang-test.outcome != 'success' }}
run: exit 1
golang-generate-check:
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
working-directory: scripts/dofy
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: ./.github/actions/setup-golang
- name: Run go generate
run: go generate ./...
- name: Check diff
run: |
if [[ $(git status --porcelain) ]]; then
git diff
exit 1
fi