-
-
Notifications
You must be signed in to change notification settings - Fork 1
164 lines (140 loc) · 5.15 KB
/
ci.yml
File metadata and controls
164 lines (140 loc) · 5.15 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
name: CI
on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
cache: true
- name: Run tests
run: go test -v -race -coverprofile=coverage.out ./...
- name: Upload coverage
uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0
if: github.event_name == 'push'
with:
files: ./coverage.out
fail_ci_if_error: false
continue-on-error: true
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
cache: true
- name: Run golangci-lint
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
with:
version: v2.11
args: --timeout=5m
generate:
name: Verify generated code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
cache: true
- name: Install mise
uses: jdx/mise-action@1648a7812b9aeae629881980618f079932869151 # v4.0.1.6.4.0.1
with:
install: true
- name: Generate code
run: go generate ./...
- name: Check for uncommitted changes
run: |
if ! git diff --exit-code; then
echo "Generated code is out of sync. Please run 'go generate ./...' and commit the changes."
exit 1
fi
build:
name: Build binaries
runs-on: ubuntu-latest
strategy:
matrix:
target:
- cmd/server
- cmd/worker
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
cache: true
- name: Build ${{ matrix.target }}
run: go build -v ./${{ matrix.target }}
docker:
name: Build and push Docker image
runs-on: ubuntu-latest
needs: [test, lint, build]
if: github.event_name == 'push'
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
- uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
- uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: App image metadata
id: app-meta
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=sha,prefix=,enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=sha,prefix=dev-,enable=${{ github.ref == 'refs/heads/dev' }}
type=raw,value=dev-latest,enable=${{ github.ref == 'refs/heads/dev' }}
- name: Migrate image metadata
id: migrate-meta
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0
with:
images: ghcr.io/${{ github.repository }}/migrate
tags: |
type=sha,prefix=,enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=sha,prefix=dev-,enable=${{ github.ref == 'refs/heads/dev' }}
type=raw,value=dev-latest,enable=${{ github.ref == 'refs/heads/dev' }}
- name: Build and push app image
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0
with:
context: .
target: app
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.app-meta.outputs.tags }}
labels: ${{ steps.app-meta.outputs.labels }}
cache-from: type=gha,scope=app
cache-to: type=gha,scope=app,mode=max
build-args: |
VERSION=${{ github.sha }}
- name: Build and push migrate image
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0
with:
context: .
target: migrate
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.migrate-meta.outputs.tags }}
labels: ${{ steps.migrate-meta.outputs.labels }}
cache-from: type=gha,scope=migrate
cache-to: type=gha,scope=migrate,mode=max