Skip to content

Commit 6c93510

Browse files
committed
CI with Github Actions
1 parent 7cd94e7 commit 6c93510

File tree

5 files changed

+375
-24
lines changed

5 files changed

+375
-24
lines changed

.github/workflows/main.yml

Lines changed: 347 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,347 @@
1+
name: Build and Draft Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
env:
9+
REGISTRY_IMAGE: germanorizzo/ws4sqlite
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Modify ws4sqlite.exe
20+
run: sed -i 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sqlite.go
21+
working-directory: src/
22+
23+
- name: Test
24+
run: go test -v -timeout 6m
25+
working-directory: src/
26+
27+
build:
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
34+
- name: Modify ws4sqlite.exe
35+
run: sed -i 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sqlite.go
36+
working-directory: src/
37+
38+
- name: Build dir generation
39+
run: mkdir bin/
40+
41+
- name: Compile and Pack Artifact [linux/amd64]
42+
run: |
43+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath
44+
tar czf ../bin/ws4sqlite-${{ github.ref_name }}-linux-amd64.tar.gz ws4sqlite
45+
rm ws4sqlite
46+
working-directory: src/
47+
48+
- name: Compile and Pack Artifact [linux/arm]
49+
run: |
50+
CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -trimpath
51+
tar czf ../bin/ws4sqlite-${{ github.ref_name }}-linux-arm.tar.gz ws4sqlite
52+
rm ws4sqlite
53+
working-directory: src/
54+
55+
- name: Compile and Pack Artifact [linux/arm64]
56+
run: |
57+
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath
58+
tar czf ../bin/ws4sqlite-${{ github.ref_name }}-linux-arm64.tar.gz ws4sqlite
59+
rm ws4sqlite
60+
working-directory: src/
61+
62+
- name: Compile and Pack Artifact [linux/riscv64]
63+
run: |
64+
CGO_ENABLED=0 GOOS=linux GOARCH=riscv64 go build -trimpath
65+
tar czf ../bin/ws4sqlite-${{ github.ref_name }}-linux-riscv64.tar.gz ws4sqlite
66+
rm ws4sqlite
67+
working-directory: src/
68+
69+
- name: Compile and Pack Artifact [linux/s390x]
70+
run: |
71+
CGO_ENABLED=0 GOOS=linux GOARCH=s390x go build -trimpath
72+
tar czf ../bin/ws4sqlite-${{ github.ref_name }}-linux-s390x.tar.gz ws4sqlite
73+
rm ws4sqlite
74+
working-directory: src/
75+
76+
- name: Compile and Pack Artifact [darwin/amd64]
77+
run: |
78+
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -trimpath
79+
zip -9 ../bin/ws4sqlite-${{ github.ref_name }}-darwin-amd64.zip ws4sqlite
80+
rm ws4sqlite
81+
working-directory: src/
82+
83+
- name: Compile and Pack Artifact [darwin/arm64]
84+
run: |
85+
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -trimpath
86+
zip -9 ../bin/ws4sqlite-${{ github.ref_name }}-darwin-arm64.zip ws4sqlite
87+
rm ws4sqlite
88+
working-directory: src/
89+
90+
- name: Compile and Pack Artifact [windows/amd64]
91+
run: |
92+
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath
93+
zip -9 ../bin/ws4sqlite-${{ github.ref_name }}-win-amd64.zip ws4sqlite.exe
94+
rm ws4sqlite.exe
95+
working-directory: src/
96+
97+
- name: Compile and Pack Artifact [windows/arm64]
98+
run: |
99+
CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build -trimpath
100+
zip -9 ../bin/ws4sqlite-${{ github.ref_name }}-win-arm64.zip ws4sqlite.exe
101+
rm ws4sqlite.exe
102+
working-directory: src/
103+
104+
- name: Compile and Pack Artifact [freebsd/amd64]
105+
run: |
106+
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -trimpath
107+
tar czf ../bin/ws4sqlite-${{ github.ref_name }}-freebsd-amd64.tar.gz ws4sqlite
108+
rm ws4sqlite
109+
working-directory: src/
110+
111+
- name: Compile and Pack Artifact [freebsd/arm64]
112+
run: |
113+
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm64 go build -trimpath
114+
tar czf ../bin/ws4sqlite-${{ github.ref_name }}-freebsd-arm64.tar.gz ws4sqlite
115+
rm ws4sqlite
116+
working-directory: src/
117+
118+
- name: Upload artifacts
119+
uses: actions/upload-artifact@v4
120+
with:
121+
name: artifacts
122+
path: bin/
123+
retention-days: 1
124+
125+
release:
126+
needs:
127+
- build
128+
- test
129+
runs-on: ubuntu-latest
130+
131+
steps:
132+
- name: Download artifacts
133+
uses: actions/download-artifact@v4
134+
with:
135+
name: artifacts
136+
path: bin/
137+
138+
- name: Create Draft Release
139+
id: create_release
140+
uses: actions/create-release@v1
141+
env:
142+
GITHUB_TOKEN: ${{ secrets.TOKEN }}
143+
with:
144+
body: _replace_me_
145+
tag_name: ${{ github.ref_name }}
146+
release_name: Version ${{ github.ref_name }}
147+
draft: true
148+
prerelease: false
149+
150+
- name: Release Artifact [linux/amd64]
151+
uses: actions/upload-release-asset@v1
152+
env:
153+
GITHUB_TOKEN: ${{ secrets.TOKEN }}
154+
with:
155+
upload_url: ${{ steps.create_release.outputs.upload_url }}
156+
asset_path: bin/ws4sqlite-${{ github.ref_name }}-linux-amd64.tar.gz
157+
asset_name: ws4sqlite-${{ github.ref_name }}-linux-amd64.tar.gz
158+
asset_content_type: application/gzip
159+
160+
- name: Release Artifact [linux/arm]
161+
uses: actions/upload-release-asset@v1
162+
env:
163+
GITHUB_TOKEN: ${{ secrets.TOKEN }}
164+
with:
165+
upload_url: ${{ steps.create_release.outputs.upload_url }}
166+
asset_path: bin/ws4sqlite-${{ github.ref_name }}-linux-arm.tar.gz
167+
asset_name: ws4sqlite-${{ github.ref_name }}-linux-arm.tar.gz
168+
asset_content_type: application/gzip
169+
170+
- name: Release Artifact [linux/arm64]
171+
uses: actions/upload-release-asset@v1
172+
env:
173+
GITHUB_TOKEN: ${{ secrets.TOKEN }}
174+
with:
175+
upload_url: ${{ steps.create_release.outputs.upload_url }}
176+
asset_path: bin/ws4sqlite-${{ github.ref_name }}-linux-arm64.tar.gz
177+
asset_name: ws4sqlite-${{ github.ref_name }}-linux-arm64.tar.gz
178+
asset_content_type: application/gzip
179+
180+
- name: Release Artifact [linux/riscv64]
181+
uses: actions/upload-release-asset@v1
182+
env:
183+
GITHUB_TOKEN: ${{ secrets.TOKEN }}
184+
with:
185+
upload_url: ${{ steps.create_release.outputs.upload_url }}
186+
asset_path: bin/ws4sqlite-${{ github.ref_name }}-linux-riscv64.tar.gz
187+
asset_name: ws4sqlite-${{ github.ref_name }}-linux-riscv64.tar.gz
188+
asset_content_type: application/gzip
189+
190+
- name: Release Artifact [linux/s390x]
191+
uses: actions/upload-release-asset@v1
192+
env:
193+
GITHUB_TOKEN: ${{ secrets.TOKEN }}
194+
with:
195+
upload_url: ${{ steps.create_release.outputs.upload_url }}
196+
asset_path: bin/ws4sqlite-${{ github.ref_name }}-linux-s390x.tar.gz
197+
asset_name: ws4sqlite-${{ github.ref_name }}-linux-s390x.tar.gz
198+
asset_content_type: application/gzip
199+
200+
- name: Release Artifact [darwin/amd64]
201+
uses: actions/upload-release-asset@v1
202+
env:
203+
GITHUB_TOKEN: ${{ secrets.TOKEN }}
204+
with:
205+
upload_url: ${{ steps.create_release.outputs.upload_url }}
206+
asset_path: bin/ws4sqlite-${{ github.ref_name }}-darwin-amd64.zip
207+
asset_name: ws4sqlite-${{ github.ref_name }}-darwin-amd64.zip
208+
asset_content_type: application/zip
209+
210+
- name: Release Artifact [darwin/arm64]
211+
uses: actions/upload-release-asset@v1
212+
env:
213+
GITHUB_TOKEN: ${{ secrets.TOKEN }}
214+
with:
215+
upload_url: ${{ steps.create_release.outputs.upload_url }}
216+
asset_path: bin/ws4sqlite-${{ github.ref_name }}-darwin-arm64.zip
217+
asset_name: ws4sqlite-${{ github.ref_name }}-darwin-arm64.zip
218+
asset_content_type: application/zip
219+
220+
- name: Release Artifact [windows/amd64]
221+
uses: actions/upload-release-asset@v1
222+
env:
223+
GITHUB_TOKEN: ${{ secrets.TOKEN }}
224+
with:
225+
upload_url: ${{ steps.create_release.outputs.upload_url }}
226+
asset_path: bin/ws4sqlite-${{ github.ref_name }}-win-amd64.zip
227+
asset_name: ws4sqlite-${{ github.ref_name }}-win-amd64.zip
228+
asset_content_type: application/zip
229+
230+
- name: Release Artifact [windows/arm64]
231+
uses: actions/upload-release-asset@v1
232+
env:
233+
GITHUB_TOKEN: ${{ secrets.TOKEN }}
234+
with:
235+
upload_url: ${{ steps.create_release.outputs.upload_url }}
236+
asset_path: bin/ws4sqlite-${{ github.ref_name }}-win-arm64.zip
237+
asset_name: ws4sqlite-${{ github.ref_name }}-win-arm64.zip
238+
asset_content_type: application/zip
239+
240+
- name: Release Artifact [freebsd/amd64]
241+
uses: actions/upload-release-asset@v1
242+
env:
243+
GITHUB_TOKEN: ${{ secrets.TOKEN }}
244+
with:
245+
upload_url: ${{ steps.create_release.outputs.upload_url }}
246+
asset_path: bin/ws4sqlite-${{ github.ref_name }}-freebsd-amd64.tar.gz
247+
asset_name: ws4sqlite-${{ github.ref_name }}-freebsd-amd64.tar.gz
248+
asset_content_type: application/gzip
249+
250+
- name: Release Artifact [freebsd/arm64]
251+
uses: actions/upload-release-asset@v1
252+
env:
253+
GITHUB_TOKEN: ${{ secrets.TOKEN }}
254+
with:
255+
upload_url: ${{ steps.create_release.outputs.upload_url }}
256+
asset_path: bin/ws4sqlite-${{ github.ref_name }}-freebsd-arm64.tar.gz
257+
asset_name: ws4sqlite-${{ github.ref_name }}-freebsd-arm64.tar.gz
258+
asset_content_type: application/gzip
259+
260+
# https://docs.docker.com/build/ci/github-actions/multi-platform/
261+
262+
build-docker:
263+
runs-on: ubuntu-latest
264+
strategy:
265+
fail-fast: false
266+
matrix:
267+
platform:
268+
- linux/amd64
269+
- linux/arm/v7
270+
- linux/arm64
271+
steps:
272+
- name: Prepare
273+
run: |
274+
platform=${{ matrix.platform }}
275+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
276+
- name: Checkout
277+
uses: actions/checkout@v4
278+
- name: Modify ws4sqlite.exe
279+
run: sed -i 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sqlite.go
280+
working-directory: src/
281+
- name: Docker meta
282+
id: meta
283+
uses: docker/metadata-action@v5
284+
with:
285+
images: ${{ env.REGISTRY_IMAGE }}
286+
# - name: Set up QEMU
287+
# uses: docker/setup-qemu-action@v3
288+
- name: Set up Docker Buildx
289+
uses: docker/setup-buildx-action@v3
290+
- name: Login to Docker Hub
291+
uses: docker/login-action@v3
292+
with:
293+
username: ${{ secrets.DOCKERHUB_USERNAME }}
294+
password: ${{ secrets.DOCKERHUB_TOKEN }}
295+
- name: Build and push by digest
296+
id: build
297+
uses: docker/build-push-action@v5
298+
with:
299+
context: .
300+
platforms: ${{ matrix.platform }}
301+
labels: ${{ steps.meta.outputs.labels }}
302+
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
303+
- name: Export digest
304+
run: |
305+
mkdir -p /tmp/digests
306+
digest="${{ steps.build.outputs.digest }}"
307+
touch "/tmp/digests/${digest#sha256:}"
308+
- name: Upload digest
309+
uses: actions/upload-artifact@v4
310+
with:
311+
name: digests-${{ env.PLATFORM_PAIR }}
312+
path: /tmp/digests/*
313+
if-no-files-found: error
314+
retention-days: 1
315+
316+
merge-docker:
317+
runs-on: ubuntu-latest
318+
needs:
319+
- build-docker
320+
- test
321+
steps:
322+
- name: Download digests
323+
uses: actions/download-artifact@v4
324+
with:
325+
path: /tmp/digests
326+
pattern: digests-*
327+
merge-multiple: true
328+
- name: Set up Docker Buildx
329+
uses: docker/setup-buildx-action@v3
330+
- name: Docker meta
331+
id: meta
332+
uses: docker/metadata-action@v5
333+
with:
334+
images: ${{ env.REGISTRY_IMAGE }}
335+
- name: Login to Docker Hub
336+
uses: docker/login-action@v3
337+
with:
338+
username: ${{ secrets.DOCKERHUB_USERNAME }}
339+
password: ${{ secrets.DOCKERHUB_TOKEN }}
340+
- name: Create manifest list and push
341+
working-directory: /tmp/digests
342+
run: |
343+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
344+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
345+
- name: Inspect image
346+
run: |
347+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

BUILDING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ The build system uses `make`. There are two kinds of targets:
88

99
All binaries generated for distribution are statically linked.
1010

11+
**N.B.**: the actual releases are performed with Github Actions, so they don't use these targets directly; they do use the same instructions however.
12+
13+
Please also note that in `Makefile` and `ws4sqlite.go` the version is specified as `v0.0.0`, to be replaced by the Github Action's script. Replace it at your leisure.
14+
1115
## Direct targets
1216

1317
#### make build
File renamed without changes.

0 commit comments

Comments
 (0)