-
Notifications
You must be signed in to change notification settings - Fork 42
293 lines (253 loc) · 9.46 KB
/
release.yml
File metadata and controls
293 lines (253 loc) · 9.46 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
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
name: Release Binary and Docker Versioned
on:
push:
tags:
- "v*.*.*"
paths-ignore:
- "**.md"
- "docs/**"
workflow_dispatch:
permissions:
contents: write
jobs:
# Test job runs first with all Postgres versions
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: "1.24"
- name: Run tests (PostgreSQL 18)
run: |
echo "Testing with PostgreSQL 18"
PGSCHEMA_POSTGRES_VERSION=18 go test -v ./...
- name: Run tests (PostgreSQL 17)
run: |
echo "Testing with PostgreSQL 17"
PGSCHEMA_POSTGRES_VERSION=17 go test -v ./...
- name: Run tests (PostgreSQL 16)
run: |
echo "Testing with PostgreSQL 16"
PGSCHEMA_POSTGRES_VERSION=16 go test -v ./...
- name: Run tests (PostgreSQL 15)
run: |
echo "Testing with PostgreSQL 15"
PGSCHEMA_POSTGRES_VERSION=15 go test -v ./...
- name: Run tests (PostgreSQL 14)
run: |
echo "Testing with PostgreSQL 14"
PGSCHEMA_POSTGRES_VERSION=14 go test -v ./...
# Build binaries using native Go cross-compilation
build-binaries:
needs: test
runs-on: ubuntu-latest
strategy:
matrix:
os: [linux, darwin]
arch: [amd64, arm64]
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: "1.24"
- name: Read version
id: version
run: echo "version=$(cat internal/version/VERSION)" >> $GITHUB_OUTPUT
- name: Get build info
id: build_info
run: |
echo "GIT_COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "BUILD_DATE=$(date -u +"%Y-%m-%d %H:%M:%S")" >> $GITHUB_OUTPUT
- name: Build binary
run: |
CGO_ENABLED=0 GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build \
-ldflags "-X github.com/pgplex/pgschema/cmd.GitCommit=${{ steps.build_info.outputs.GIT_COMMIT }} -X 'github.com/pgplex/pgschema/cmd.BuildDate=${{ steps.build_info.outputs.BUILD_DATE }}'" \
-o pgschema-${{ steps.version.outputs.version }}-${{ matrix.os }}-${{ matrix.arch }} .
- name: Upload artifacts
uses: actions/upload-artifact@v7
with:
name: pgschema-${{ steps.version.outputs.version }}-${{ matrix.os }}-${{ matrix.arch }}
path: pgschema-${{ steps.version.outputs.version }}-${{ matrix.os }}-${{ matrix.arch }}
packages:
needs: build-binaries
runs-on: ubuntu-latest
strategy:
matrix:
arch: [amd64, arm64]
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Read version
id: version
run: echo "version=$(cat internal/version/VERSION)" >> $GITHUB_OUTPUT
- name: Download Linux binary
uses: actions/download-artifact@v8
with:
name: pgschema-${{ steps.version.outputs.version }}-linux-${{ matrix.arch }}
path: ./dist
- name: Install nfpm
run: |
echo "deb [trusted=yes] https://repo.goreleaser.com/apt/ /" | sudo tee /etc/apt/sources.list.d/goreleaser.list
sudo apt-get update
sudo apt-get install -y nfpm
- name: Prepare binary
run: |
chmod +x ./dist/pgschema-${{ steps.version.outputs.version }}-linux-${{ matrix.arch }}
mkdir -p ./package/usr/bin
cp ./dist/pgschema-${{ steps.version.outputs.version }}-linux-${{ matrix.arch }} ./package/usr/bin/pgschema
mkdir -p ./package/usr/share/doc/pgschema
cp LICENSE ./package/usr/share/doc/pgschema/
- name: Create nfpm config
run: |
cat > nfpm.yaml <<EOF
name: pgschema
arch: ${{ matrix.arch }}
platform: linux
version: ${{ steps.version.outputs.version }}
section: database
priority: optional
maintainer: Bytebase <support@bytebase.com>
description: |
PostgreSQL declarative schema migration tool.
Think of it as Terraform for your Postgres schemas - declare your desired state,
generate plan, preview changes, and apply them with confidence.
vendor: Bytebase
homepage: https://www.pgschema.com
license: Apache-2.0
contents:
- src: ./package/usr/bin/pgschema
dst: /usr/bin/pgschema
file_info:
mode: 0755
- src: ./package/usr/share/doc/pgschema/LICENSE
dst: /usr/share/doc/pgschema/LICENSE
file_info:
mode: 0644
rpm:
group: Applications/Databases
summary: PostgreSQL declarative schema migration tool
EOF
- name: Build DEB package
run: nfpm package --packager deb --target ./dist/
- name: Build RPM package
run: nfpm package --packager rpm --target ./dist/
- name: Upload DEB package
uses: actions/upload-artifact@v7
with:
name: pgschema-deb-${{ matrix.arch }}
path: ./dist/*.deb
- name: Upload RPM package
uses: actions/upload-artifact@v7
with:
name: pgschema-rpm-${{ matrix.arch }}
path: ./dist/*.rpm
release:
needs: [build-binaries, packages]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Read version
id: version
run: echo "version=$(cat internal/version/VERSION)" >> $GITHUB_OUTPUT
- name: Download artifacts
uses: actions/download-artifact@v8
with:
path: binaries
- name: Create release
uses: softprops/action-gh-release@da05d552573ad5aba039eaac05058a918a7bf631
with:
# go install requires tags to be prefixed with v.
tag_name: v${{ steps.version.outputs.version }}
name: Release v${{ steps.version.outputs.version }}
generate_release_notes: true
files: |
binaries/pgschema-${{ steps.version.outputs.version }}-linux-amd64/pgschema-${{ steps.version.outputs.version }}-linux-amd64
binaries/pgschema-${{ steps.version.outputs.version }}-linux-arm64/pgschema-${{ steps.version.outputs.version }}-linux-arm64
binaries/pgschema-${{ steps.version.outputs.version }}-darwin-arm64/pgschema-${{ steps.version.outputs.version }}-darwin-arm64
binaries/pgschema-${{ steps.version.outputs.version }}-darwin-amd64/pgschema-${{ steps.version.outputs.version }}-darwin-amd64
binaries/pgschema-deb-amd64/*.deb
binaries/pgschema-deb-arm64/*.deb
binaries/pgschema-rpm-amd64/*.rpm
binaries/pgschema-rpm-arm64/*.rpm
docker:
needs: [build-binaries, packages]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
REGISTRY: docker.io
IMAGE_NAME: pgplex/pgschema
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Read version
id: version
run: echo "version=$(cat internal/version/VERSION)" >> $GITHUB_OUTPUT
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}},value=v${{ steps.version.outputs.version }}
- name: Get build info
id: build_info
run: |
echo "GIT_COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "BUILD_DATE=$(date -u +"%Y-%m-%d %H:%M:%S")" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
GIT_COMMIT=${{ steps.build_info.outputs.GIT_COMMIT }}
BUILD_DATE=${{ steps.build_info.outputs.BUILD_DATE }}
homebrew:
needs: release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Read version
id: version
run: echo "version=$(cat internal/version/VERSION)" >> $GITHUB_OUTPUT
- name: Update Homebrew formula
uses: mislav/bump-homebrew-formula-action@v4
with:
formula-name: pgschema
formula-path: Formula/pgschema.rb
homebrew-tap: pgplex/homebrew-pgschema
download-url: https://github.com/pgplex/pgschema/releases/download/v${{ steps.version.outputs.version }}/pgschema-${{ steps.version.outputs.version }}-darwin-arm64
commit-message: |
pgschema ${{ steps.version.outputs.version }}
env:
COMMITTER_TOKEN: ${{ secrets.BREW_COMMITTER_TOKEN }}