-
Notifications
You must be signed in to change notification settings - Fork 73
269 lines (232 loc) · 7.56 KB
/
build.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
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
name: Build
on:
pull_request:
push:
branches:
- main
tags:
- 'v*'
permissions:
contents: write
packages: write
jobs:
cross-build:
name: cross-platform build
runs-on: ubuntu-24.04
container:
image: surjection/goreleaser-cross:v1.23-v2.4.8
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
# Mark the checkout as 'safe' despite being owned by `root`
- run: git config --global --add safe.directory $GITHUB_WORKSPACE
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: '~> v2'
args: build --snapshot
- uses: actions/upload-artifact@v4
with:
name: platform-binaries
path: dist/
if-no-files-found: error
test:
name: 'test (pg: ${{ matrix.pgVersion }}, schema: ${{ matrix.testSchema }})'
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
pgVersion: ['14.8', '15.3', '16.4', '17.0' ,'latest']
testSchema: [ 'public', 'non_public' ]
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Run tests
run: go test ./...
env:
POSTGRES_VERSION: ${{ matrix.pgVersion }}
PGROLL_TEST_SCHEMA: ${{ matrix.testSchema }}
lint:
name: lint
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.61.0
# Optional: golangci-lint command line arguments.
#
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
args: --timeout=30m --out-format=colored-line-number --config=.golangci.yml
- name: Ensure JSON examples are formatted
run: |
for file in ./examples/*.json; do
if ! diff <(cat $file | jq) <(cat $file); then
echo "$file is not formatted: run 'cat $file | jq' to fix";
exit 1;
fi
done
type-generation:
name: type generation
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Generate types
run: |
chmod 666 pkg/state/init.sql
make generate
- name: Ensure generated types are up-to-date
run: |
if ! git diff --quiet; then
echo "generated types are out of date!"
echo "run 'make generate' to regenerate type definitions"
exit 1
fi
check-ledger:
name: check ledger
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Generate ledger
run: |
make ledger
- name: Ensure ledger is up to date
run: |
if ! git diff --quiet; then
echo "generated ledger is out of date!"
echo "run 'make ledger' to regenerate the ledger"
exit 1
fi
dead-code-check:
name: dead code check
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Install deadcode tool
run: |
go install golang.org/x/tools/cmd/deadcode@latest
- name: Run deadcode analysis
run: |
deadcode --test ./... > deadcode.out
if [ -s deadcode.out ]; then
echo "Dead code analysis found the following dead code:"
cat deadcode.out
exit 1
fi
license-check:
name: license check
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Ensure .go files have a license reference
run: |
curl -s https://raw.githubusercontent.com/lluissm/license-header-checker/master/install.sh | bash
./bin/license-header-checker -a -r .github/license-header.txt . go && [[ -z `git status -s` ]]
examples-schema-validation:
name: validate examples JSON
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Validate example migrations against JSON schema
run: |
npx -y ajv-cli --spec=draft2020 validate --strict-schema=false -s schema.json -d "./examples/*.json"
examples:
name: 'examples (pg: ${{ matrix.pgVersion }}, schema: ${{ matrix.testSchema }})'
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
pgVersion: ['14.8', '15.3', '16.4', '17.0' ,'latest']
testSchema: [ 'public', 'non_public' ]
services:
postgres:
image: postgres:${{ matrix.pgVersion }}
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Run example migrations
run: |
if [ "$PGROLL_SCHEMA" != "public" ]; then
psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U postgres -c "CREATE SCHEMA $PGROLL_SCHEMA;"
fi
make examples
env:
POSTGRES_PORT: 5432
POSTGRES_HOST: localhost
PGPASSWORD: postgres
PGROLL_SCHEMA: ${{ matrix.testSchema }}
release:
runs-on: ubuntu-24.04
container:
image: surjection/goreleaser-cross:v1.23-v2.4.8
needs: [test, lint, examples-schema-validation, examples, license-check, type-generation, dead-code-check, check-ledger, cross-build]
if: startsWith(github.ref, 'refs/tags/')
env:
DOCKER_CLI_EXPERIMENTAL: "enabled"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
# Mark the checkout as 'safe' despite being owned by `root`
- run: git config --global --add safe.directory $GITHUB_WORKSPACE
- run: git fetch --force --tags
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: '~> v2'
args: release --clean
env:
# We use two GitHub tokens here:
# * The actions-bound `GITHUB_TOKEN` with permissions to write packages.
# * The org level `GIT_TOKEN` to be able to publish the brew tap file.
# See: https://goreleaser.com/errors/resource-not-accessible-by-integration/
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAP_GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }}
GITHUB_USERNAME: ${{ github.repository_owner }}
DOCKER_USERNAME: ghcr.io/${{ github.repository_owner }}