-
Notifications
You must be signed in to change notification settings - Fork 8
238 lines (206 loc) · 6.99 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
name: Build
env:
GO_VERSION: "1.21"
ATTACHMENTS: ""
GOPATH: ${{ github.workspace }}
BUCKET: charts.s3sync-service.org
AWS_DEFAULT_REGION: us-east-1
on:
release:
types:
- published
push:
branches:
- master
pull_request:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Inject slug/short variables
uses: rlespinasse/[email protected]
- 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 }}
- name: Install dependencies
run: |
cd ./src/github.com/${{ github.repository }}
go mod download
- name: Run tests
env:
RELEASE_VERSION: ${{ env.GITHUB_REF_SLUG }}
run: |
cd ./src/github.com/${{ github.repository }}
make test
- name: Codecov
uses: codecov/codecov-action@v3
with:
file: ./src/github.com/${{ github.repository }}/cover.out
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: Inject slug/short variables
uses: rlespinasse/[email protected]
- 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 }}
- name: Install dependencies
run: |
cd ./src/github.com/${{ github.repository }}
go mod download
- name: Build
env:
RELEASE_VERSION: ${{ env.GITHUB_REF_SLUG }}
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-${{ env.GITHUB_REF_SLUG }}-${{ matrix.go-os }}-${{ matrix.go-arch }}
path: ./src/github.com/${{ github.repository }}/s3sync-service-*
docker:
runs-on: ubuntu-latest
# if: ${{ github.event_name != 'pull_request' }}
needs: test
strategy:
matrix:
include:
# empty registry for DockerHub
- registry: ""
username: DOCKERHUB_USERNAME
password: DOCKERHUB_TOKEN
base-repo: zmazay/s3sync-service
- registry: quay.io
username: QUAY_USERNAME
password: QUAY_TOKEN
base-repo: quay.io/s3sync-service/s3sync-service
- registry: ghcr.io
username: GHCR_REGISTRY_USERNAME
password: GITHUB_TOKEN
base-repo: ghcr.io/${{ github.repository }}
steps:
- name: Inject slug/short variables
uses: rlespinasse/[email protected]
- 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 registry
uses: docker/login-action@v3
with:
registry: ${{ matrix.registry }}
username: ${{ secrets[matrix.username] }}
password: ${{ secrets[matrix.password] }}
- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
tags: "${{ matrix.base-repo }}:${{ env.GITHUB_REF_SLUG }}"
publish:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'release' }}
needs: build
steps:
- name: Inject slug/short variables
uses: rlespinasse/[email protected]
- name: Chechout
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: artifacts/
- name: Upload assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
for artifact in $(ls artifacts/*); do ATTACHMENTS="${ATTACHMENTS} ${artifact}"; done;
gh release upload ${{ env.GITHUB_REF_SLUG }} ${ATTACHMENTS}
helm-release:
name: helm-release
runs-on: ubuntu-latest
if: ${{ github.event_name == 'release' }}
needs: docker
steps:
- uses: actions/checkout@v4
- name: Install Helm
run: |
curl https://baltocdn.com/helm/signing.asc | sudo apt-key add -
sudo apt-get install apt-transport-https --yes
echo "deb https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
sudo apt-get update -y
sudo apt-get install helm -y
- name: Install AWS CLI
run: sudo apt-get install awscli -y
- name: Check if version exists
id: version-check
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
cd charts
version=$(helm show chart ./s3sync-service | grep version | awk '{ print $2 }')
exists=$(aws s3api head-object --bucket ${BUCKET} --key charts/s3sync-service-${version}.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
- name: Get existing index
if: steps.version-check.outputs.exists != true
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
cd charts
aws s3 cp s3://${BUCKET}/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
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
cd charts
aws s3 cp ./s3sync-service/index.html s3://${BUCKET}
aws s3 cp ./s3sync-service/index.yaml s3://${BUCKET}
aws s3 sync ./s3sync-service s3://${BUCKET} --exclude "*" --include "charts/*"