-
Notifications
You must be signed in to change notification settings - Fork 8
254 lines (222 loc) · 7.49 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
name: Build
env:
GO_VERSION: "1.23"
ATTACHMENTS: ""
GOPATH: ${{ github.workspace }}
on:
release:
types:
- published
push:
branches:
- master
pull_request:
branches:
- master
permissions:
contents: write
packages: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Chechout
uses: actions/checkout@v4
with:
path: ./src/github.com/${{ github.repository }}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: "**/go.sum"
- name: Install dependencies
run: |
cd ./src/github.com/${{ github.repository }}
go mod download
- name: Run tests
env:
RELEASE_VERSION: devel # version doesn't really matter for tests but still has to be set
run: |
cd ./src/github.com/${{ github.repository }}
make test
- name: Codecov
uses: codecov/codecov-action@v5
with:
file: ./src/github.com/${{ github.repository }}/cover.out
token: ${{ secrets.CODECOV_TOKEN }}
build:
runs-on: ubuntu-latest
needs: test
strategy:
matrix:
go-os: [darwin, windows, linux, freebsd]
go-arch: [amd64, 386, arm, arm64]
exclude:
# excludes 32 bit architectures for darwin builds
- go-os: darwin
go-arch: 386
- go-os: darwin
go-arch: arm
steps:
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository }}
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Chechout
uses: actions/checkout@v4
with:
path: ./src/github.com/${{ github.repository }}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: "**/go.sum"
- name: Install dependencies
run: |
cd ./src/github.com/${{ github.repository }}
go mod download
- name: Build
env:
RELEASE_VERSION: ${{ steps.meta.outputs.version }}
OS: ${{ matrix.go-os }}
GOOS: ${{ matrix.go-os }}
ARCH: ${{ matrix.go-arch }}
GOARCH: ${{ matrix.go-arch }}
run: |
cd ./src/github.com/${{ github.repository }}
make build
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: s3sync-service-${{ steps.meta.outputs.version }}-${{ matrix.go-os }}-${{ matrix.go-arch }}
path: ./src/github.com/${{ github.repository }}/bin/s3sync-service-*
docker:
runs-on: ubuntu-latest
needs: test
steps:
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
zmazay/s3sync-service
quay.io/s3sync-service/s3sync-service
ghcr.io/${{ github.repository }}
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Chechout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to quay.io
uses: docker/login-action@v3
with:
registry: "quay.io"
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Login to ghcr.io
uses: docker/login-action@v3
with:
registry: "ghcr.io"
username: ${{ secrets.GHCR_REGISTRY_USERNAME }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/386,linux/ppc64le
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args:
RELEASE_VERSION=${{ steps.meta.outputs.version }}
publish:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'release' }}
needs: build
steps:
- name: Chechout
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: artifacts/
pattern: s3sync-service-*
- name: Upload assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
for artifact in $(ls artifacts/*); do ATTACHMENTS="${ATTACHMENTS} ${artifact}"; done;
gh release upload ${{ github.ref_name }} ${ATTACHMENTS}
helm-release:
name: helm-release
runs-on: ubuntu-latest
if: ${{ github.event_name == 'release' }}
needs: docker
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }}
steps:
- uses: actions/checkout@v4
- name: Install Helm
uses: azure/[email protected]
- name: Check if version exists
id: version-check
run: |
exists=$(aws s3api head-object --bucket ${{ vars.CHARTS_BUCKET_NAME }} --key charts/s3sync-service-${{ github.event.release.tag_name }}.tgz || true)
if [ -z "${exists}" ]; then
echo "exists=false" >> $GITHUB_OUTPUT
else
echo "exists=$exists" >> $GITHUB_OUTPUT
fi
- name: Package Helm Chart
if: steps.version-check.outputs.exists != true
run: |
cd charts
helm package s3sync-service -d ./s3sync-service/charts \
--version ${{ github.event.release.tag_name }} \
--app-version ${{ github.event.release.tag_name }}
- name: Get existing index
if: steps.version-check.outputs.exists != true
run: |
cd charts
aws s3 cp s3://${{ vars.CHARTS_BUCKET_NAME }}/index.yaml ./s3sync-service/index.yaml
- name: Generate new Helm index file
if: steps.version-check.outputs.exists != true
run: |
cd charts
helm repo index s3sync-service --url https://charts.s3sync-service.org/ --merge ./s3sync-service/index.yaml
- name: Upload the charts and index files
if: steps.version-check.outputs.exists != true
run: |
cd charts
aws s3 cp ./s3sync-service/index.html s3://${{ vars.CHARTS_BUCKET_NAME }}
aws s3 cp ./s3sync-service/index.yaml s3://${{ vars.CHARTS_BUCKET_NAME }}
aws s3 sync ./s3sync-service s3://${{ vars.CHARTS_BUCKET_NAME }} --exclude "*" --include "charts/*"