-
Notifications
You must be signed in to change notification settings - Fork 73
255 lines (217 loc) · 8.34 KB
/
ci.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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
---
name: CI
on:
schedule:
# Saturday 8:00, after cleanup
- cron: "0 8 * * 6"
push:
branches:
- main
- hotfix/**
- release/**
pull_request:
jobs:
# test job
test:
name: Test
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os:
- ubuntu-20.04
go-version:
- 1.17.x
- tip
images:
- { postgres: "postgres:9.5", mysql: "mysql:5.6", mssql: "mcr.microsoft.com/mssql/server:2017-latest" }
- { postgres: "postgres:9.6", mysql: "mysql:5.7", mssql: "mcr.microsoft.com/mssql/server:2019-latest" }
- { postgres: "postgres:10", mysql: "mysql:8.0" }
- { postgres: "postgres:11" }
- { postgres: "postgres:12" }
- { postgres: "postgres:13" }
runs-on: ${{ matrix.os }}
env:
# no `-mod=readonly` to test PRs made by @dependabot;
# `make ci-check-changes` step below still checks what we need
WORKDIR: "${{ github.workspace }}/gopath/src/gopkg.in/reform.v1"
GOPATH: "${{ github.workspace }}/gopath"
GOBIN: "${{ github.workspace }}/gopath/bin"
GO111MODULE: "on"
GOPROXY: "https://proxy.golang.org"
GORACE: "halt_on_error=1"
REFORM_POSTGRES_IMAGE: "${{ matrix.images.postgres }}"
REFORM_MYSQL_IMAGE: "${{ matrix.images.mysql }}"
REFORM_MSSQL_IMAGE: "${{ matrix.images.mssql }}"
steps:
# Cache Go modules, build cache, installed packages and GOPATH sources
# to significantly decreases total CI time. See also cleanup.yaml.
- name: Enable Go cache
uses: actions/cache@v2
with:
path: |
~/.cache/go-build
${{ env.GOPATH }}/pkg
${{ env.GOPATH }}/src/github.com
${{ env.GOPATH }}/src/golang.org
key: ${{ matrix.os }}-${{ matrix.go-version }}
- name: Set up Go version ${{ matrix.go-version }}
if: matrix.go-version != 'tip'
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Set up Go tip
if: matrix.go-version == 'tip'
run: |
git clone --depth=1 https://go.googlesource.com/go $HOME/gotip
cd $HOME/gotip/src
./make.bash
echo "GOROOT=$HOME/gotip" >> $GITHUB_ENV
echo "$HOME/gotip/bin" >> $GITHUB_PATH
echo "$GOBIN" >> $GITHUB_PATH
- name: Set GO_VERSION
run: echo "GO_VERSION=$(go version)" >> $GITHUB_ENV
- name: Check out code into GOPATH
uses: actions/checkout@v2
with:
path: ${{ env.WORKDIR }}
- name: Pull Docker images
working-directory: ${{ env.WORKDIR }}
run: docker-compose pull
- name: Stop Ubuntu services
run: sudo systemctl stop mysql
# FIXME Is there a more ergonomic way?
- name: Update Go language version in the module
working-directory: ${{ env.WORKDIR }}
run: go mod edit -go=$(go list -f '{{ $tag := 0 }}{{ range $tag = context.ReleaseTags }}{{ end }}{{ slice $tag 2 }}' runtime)
- name: Download Go modules
working-directory: ${{ env.WORKDIR }}
run: go mod download
- name: Check that it is still possible to install reform without modules
working-directory: ${{ env.WORKDIR }}
run: |
env GO111MODULE=off go get -v -x ./...
reform -version
reform-db -version
- name: Run init target
working-directory: ${{ env.WORKDIR }}
run: make init
- name: Start development environment
working-directory: ${{ env.WORKDIR }}
run: make env-up-detach
- name: Run test target
working-directory: ${{ env.WORKDIR }}
run: make test
# TODO test again with updated deps
- name: Clean Go test cache
if: ${{ always() }}
run: go clean -testcache
# to ensure that all generators still work the same way
- name: Check that there are no source code changes
working-directory: ${{ env.WORKDIR }}
run: make ci-check-changes
- name: Upload coverage information
working-directory: ${{ env.WORKDIR }}
run: bash <(curl -s https://codecov.io/bash) -f coverage.txt -X fix -e GO_VERSION,REFORM_POSTGRES_IMAGE,REFORM_MYSQL_IMAGE,REFORM_MSSQL_IMAGE
- name: Run debug commands on failure
if: ${{ failure() }}
run: |
sudo apt-get install -qy tree
env
go version
go env
pwd
tree -d
ls -al
docker --version
docker-compose --version
# lint job
lint:
name: Lint
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os:
- ubuntu-20.04
go-version:
- 1.17.x
runs-on: ${{ matrix.os }}
env:
# no `-mod=readonly` to test PRs made by @dependabot;
# `make ci-check-changes` step below still checks what we need
WORKDIR: "${{ github.workspace }}/gopath/src/gopkg.in/reform.v1"
GOPATH: "${{ github.workspace }}/gopath"
GOBIN: "${{ github.workspace }}/gopath/bin"
GO111MODULE: "on"
GOPROXY: "https://proxy.golang.org"
GORACE: "halt_on_error=1"
REFORM_POSTGRES_IMAGE: "${{ matrix.images.postgres }}"
REFORM_MYSQL_IMAGE: "${{ matrix.images.mysql }}"
REFORM_MSSQL_IMAGE: "${{ matrix.images.mssql }}"
steps:
# Cache Go modules, build cache, installed packages and GOPATH sources
# to significantly decreases total CI time. See also cleanup.yaml.
- name: Enable Go cache
uses: actions/cache@v2
with:
path: |
~/.cache/go-build
${{ env.GOPATH }}/pkg
${{ env.GOPATH }}/src/github.com
${{ env.GOPATH }}/src/golang.org
key: ${{ matrix.os }}-${{ matrix.go-version }}
- name: Set up Go version ${{ matrix.go-version }}
if: matrix.go-version != 'tip'
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Set up Go tip
if: matrix.go-version == 'tip'
run: |
git clone --depth=1 https://go.googlesource.com/go $HOME/gotip
cd $HOME/gotip/src
./make.bash
echo "GOROOT=$HOME/gotip" >> $GITHUB_ENV
echo "$HOME/gotip/bin" >> $GITHUB_PATH
echo "$GOBIN" >> $GITHUB_PATH
- name: Set GO_VERSION
run: echo "GO_VERSION=$(go version)" >> $GITHUB_ENV
- name: Check out code into GOPATH
uses: actions/checkout@v2
with:
path: ${{ env.WORKDIR }}
# FIXME Is there a more ergonomic way?
- name: Update Go language version in the module
working-directory: ${{ env.WORKDIR }}
run: go mod edit -go=$(go list -f '{{ $tag := 0 }}{{ range $tag = context.ReleaseTags }}{{ end }}{{ slice $tag 2 }}' runtime)
- name: Download Go modules
working-directory: ${{ env.WORKDIR }}
run: go mod download
- name: Run init target
working-directory: ${{ env.WORKDIR }}
run: make init
- name: Run checks/linters
working-directory: ${{ env.WORKDIR }}
run: |
# use GITHUB_TOKEN because only it has access to GitHub Checks API
bin/golangci-lint run --config=.golangci-required.yml --out-format=line-number | env REVIEWDOG_GITHUB_API_TOKEN=${{ secrets.GITHUB_TOKEN }} bin/reviewdog -f=golangci-lint -name='Required linters' -reporter=github-check
# use GO_REFORM_BOT_TOKEN for better reviewer's name
bin/golangci-lint run --out-format=line-number | env REVIEWDOG_GITHUB_API_TOKEN=${{ secrets.GO_REFORM_BOT_TOKEN }} bin/reviewdog -f=golangci-lint -name='Optional linters' -reporter=github-pr-review
bin/go-consistent -pedantic ./... | env REVIEWDOG_GITHUB_API_TOKEN=${{ secrets.GO_REFORM_BOT_TOKEN }} bin/reviewdog -f=go-consistent -name='go-consistent' -reporter=github-pr-review
# to ensure that all generators still work the same way
- name: Check that there are no source code changes
working-directory: ${{ env.WORKDIR }}
run: make ci-check-changes
- name: Run debug commands on failure
if: ${{ failure() }}
run: |
sudo apt-get install -qy tree
env
go version
go env
pwd
tree -d
ls -al
docker --version
docker-compose --version