-
Notifications
You must be signed in to change notification settings - Fork 124
467 lines (414 loc) · 16.5 KB
/
release.yaml
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
name: Release
on:
push:
branches: [release, release-dev, release-test, main]
tags:
- "v*.*.*"
env:
CARGO_TERM_COLOR: always
BUCKET_NAME: "dozer-releases"
ECR_REGISTRY: public.ecr.aws/k7k6x1d4
ECR_REPOSITORY: dozer
DOCKERHUB_REGISTRY: getdozer
DOCKERHUB_REPOSITORY: dozer
permissions:
id-token: write # This is required for requesting the JWT
contents: write # This is required for actions/checkout
jobs:
# https://github.com/orhun/git-cliff/blob/main/.github/workflows/cd.yml
prepare:
name: Prepare
runs-on: ubuntu-20.04
timeout-minutes: 60
outputs:
release_body: ${{ steps.release.outputs.release_body }}
version: ${{ steps.version.outputs.version }}
prerelease: ${{ steps.version.outputs.prerelease }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Generate a changelog
uses: orhun/git-cliff-action@v1
id: git-cliff
with:
config: .github/config/cliff.toml
args: -vv --latest --strip header
env:
OUTPUT: CHANGES.md
- name: Set the release body
id: release
shell: bash
run: |
r=$(cat ${{ steps.git-cliff.outputs.changelog }})
r="$(printf "$r" | tail -n +3)"
r="${r//'%'/'%25'}"
r="${r//$'\n'/'%0A'}"
r="${r//$'\r'/'%0D'}"
echo "::set-output name=release_body::$r"
- name: Set release version
id: version
run: |
tag=$(printf "%q" ${{ github.ref_name }})
if [[ $tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::set-output name=version::$tag"
echo "::set-output name=prerelease::false"
else
echo "::set-output name=version::dev"
echo "::set-output name=prerelease::true"
fi
release-linux-aarch64:
name: Release Linux binary for aarch64
runs-on: ${{ matrix.os }}
needs: prepare
strategy:
fail-fast: false
matrix:
include:
- build: aarch64
os: ubuntu-20-16-cores
target: aarch64-unknown-linux-gnu
linker: gcc-aarch64-linux-gnu
use-cross: true
file_name: dozer
asset_name: dozer-linux-aarch64
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install minimal stable with clippy and rustfmt
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.target }}
components: rustfmt, clippy
- name: APT update
run: |
sudo apt update
- name: Install target specific tools
if: matrix.use-cross
run: |
sudo apt-get install -y ${{ matrix.linker }}
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: ⚡ Cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/.crates.toml
~/.cargo/.crates2.json
~/.cargo/.package-cache
~/.cargo/registry/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-release-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-release-${{ hashFiles('Cargo.lock') }}
${{ runner.os }}-cargo-release-
- name: Configure target aarch64 GNU
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
echo '[target.aarch64-unknown-linux-gnu]' >> ~/.cargo/config
echo 'linker = "aarch64-linux-gnu-gcc"' >> ~/.cargo/config
echo 'JEMALLOC_SYS_WITH_LG_PAGE=16' >> $GITHUB_ENV
- name: Cargo build
uses: actions-rs/cargo@v1
with:
command: build
use-cross: false
args: --release --target ${{ matrix.target }} --bin ${{ matrix.file_name }}
- name: List target output files
run: ls -lR ./target
- name: Install cargo-deb
run: cargo install cargo-deb
- name: Compile deb file
run: cargo-deb -p dozer-cli --target ${{ matrix.target }} --output ./deb/${{matrix.asset_name}}.deb
- name: Prepare release assets
shell: bash
run: |
mkdir -p release
cp {LICENSE,README.md,CHANGELOG.md} release/ 2> /dev/null || echo "Copy Failed...Ignoring.."
cp target/${{ matrix.target }}/release/${{matrix.file_name}} release/
mv release/ ${{matrix.asset_name}}/
tar -czvf ${{matrix.asset_name}}.tar.gz ${{matrix.asset_name}}/
cp deb/${{matrix.asset_name}}.deb ${{matrix.asset_name}}/
ls -l ${{matrix.asset_name}}
- name: Upload the release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{matrix.asset_name}}*
file_glob: true
overwrite: true
tag: ${{ needs.prepare.outputs.version }}
release_name: "Development Release - ${{ needs.prepare.outputs.version }}"
prerelease: ${{ needs.prepare.outputs.prerelease }}
body: "${{ needs.prepare.outputs.release_body }}"
- name: Set env variables
env:
VERSION: ${{ needs.prepare.outputs.version }}
RELEASE_NAME: ${{matrix.asset_name}}.tar.gz
run: |
echo "RELEASE_NAME=${{env.RELEASE_NAME}}" >> $GITHUB_ENV
echo "DEB_NAME=${{matrix.asset_name}}.deb" >> $GITHUB_ENV
echo "VERSION=${{env.VERSION}}" >> $GITHUB_ENV
echo "ARTIFACT_URL=https://${{ env.BUCKET_NAME }}.s3.ap-southeast-1.amazonaws.com/${{ env.VERSION }}/${{ env.RELEASE_NAME }}" >> $GITHUB_ENV
- name: List deb output files
run: ls -lR ./deb
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-session-name: deployer
aws-region: ap-southeast-1
- name: Upload release to S3
id: upload_s3
run: |
aws s3 cp $RELEASE_NAME s3://${{ env.BUCKET_NAME }}/$VERSION/$RELEASE_NAME
- name: Upload release deb to S3
id: upload_s3_deb
run: |
aws s3 cp deb/$DEB_NAME s3://${{ env.BUCKET_NAME }}/$VERSION/$DEB_NAME
release-macos-apple-silicon:
name: Release binary for macOS silicon
runs-on: ${{ matrix.os }}
needs: prepare
strategy:
fail-fast: false
matrix:
include:
- os: macos-12
target: aarch64-apple-darwin
file_name: dozer
asset_name: dozer-macos-aarch64
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Installing Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
target: ${{ matrix.target }}
override: true
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: ⚡ Cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/.crates.toml
~/.cargo/.crates2.json
~/.cargo/.package-cache
~/.cargo/registry/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-release-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-release-${{ hashFiles('Cargo.lock') }}
${{ runner.os }}-cargo-release-
- name: Cargo build
uses: actions-rs/cargo@v1
with:
command: build
args: --release --target ${{ matrix.target }} --bin ${{ matrix.file_name }}
- name: List target output files
run: ls -lR ./target
- name: Prepare release assets
shell: bash
run: |
mkdir -p release
cp {LICENSE,README.md,CHANGELOG.md} release/ 2> /dev/null || echo "Copy Failed...Ignoring.."
cp target/${{ matrix.target }}/release/${{matrix.file_name}} release/
mv release/ ${{matrix.asset_name}}/
tar -czvf ${{matrix.asset_name}}.tar.gz ${{matrix.asset_name}}/
- name: Upload the release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{matrix.asset_name}}*
file_glob: true
overwrite: true
tag: ${{ needs.prepare.outputs.version }}
release_name: "Development Release - ${{ needs.prepare.outputs.version }}"
prerelease: ${{ needs.prepare.outputs.prerelease }}
body: "${{ needs.prepare.outputs.release_body }}"
- name: Set env variables
env:
VERSION: ${{ needs.prepare.outputs.version }}
RELEASE_NAME: ${{matrix.asset_name}}.tar.gz
run: |
echo "RELEASE_NAME=${{env.RELEASE_NAME}}" >> $GITHUB_ENV
echo "VERSION=${{env.VERSION}}" >> $GITHUB_ENV
echo "ARTIFACT_URL=https://${{ env.BUCKET_NAME }}.s3.ap-southeast-1.amazonaws.com/${{ env.VERSION }}/${{ env.RELEASE_NAME }}" >> $GITHUB_ENV
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-session-name: deployer
aws-region: ap-southeast-1
- name: Upload release to S3
id: upload_s3
run: |
aws s3 cp $RELEASE_NAME s3://${{ env.BUCKET_NAME }}/$VERSION/$RELEASE_NAME
release:
name: Release
runs-on:
labels: ${{ matrix.os }}
needs: prepare
timeout-minutes: 60
strategy:
matrix:
os: [ubuntu-20-16-cores]
include:
- os: ubuntu-20-16-cores
file_name: dozer
target: x86_64-unknown-linux-gnu
asset_name: dozer-linux-amd64
- os: macos-12
file_name: dozer
target: x86_64-apple-darwin
asset_name: dozer-macos-amd64
steps:
- uses: actions/checkout@v3
- name: Install minimal stable with clippy and rustfmt
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.target }}
components: rustfmt, clippy
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: ⚡ Cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/.crates.toml
~/.cargo/.crates2.json
~/.cargo/.package-cache
~/.cargo/registry/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-release-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-release-${{ hashFiles('Cargo.lock') }}
${{ runner.os }}-cargo-release-
- name: Install cargo-deb
if: matrix.os == 'ubuntu-20-16-cores'
run: cargo install cargo-deb
- name: Compile deb file
if: matrix.os == 'ubuntu-20-16-cores'
run: cargo-deb -p dozer-cli --output ./deb/${{matrix.asset_name}}.deb
- name: Build package
if: matrix.os != 'ubuntu-20-16-cores'
run: cargo build --release --bin ${{ matrix.file_name }}
- name: Build package for ubuntu (with kafka & snowflake)
if: matrix.os == 'ubuntu-20-16-cores'
run: cargo build --release --bin ${{ matrix.file_name }} --features "kafka snowflake"
- name: Prepare release assets
shell: bash
run: |
mkdir -p release
cp {LICENSE,README.md,CHANGELOG.md} release/ 2> /dev/null || echo "Copy Failed...Ignoring.."
cp target/release/${{matrix.file_name}} release/
mv release/ ${{matrix.asset_name}}/
tar -czvf ${{matrix.asset_name}}.tar.gz \
${{matrix.asset_name}}/
cp deb/${{matrix.asset_name}}.deb ${{matrix.asset_name}}/ 2>/dev/null || :
ls -l ${{matrix.asset_name}}
- name: Upload the release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{matrix.asset_name}}*
file_glob: true
overwrite: true
tag: ${{ needs.prepare.outputs.version }}
release_name: "Development Release - ${{ needs.prepare.outputs.version }}"
prerelease: ${{ needs.prepare.outputs.prerelease }}
body: "${{ needs.prepare.outputs.release_body }}"
- name: Set env variables
env:
VERSION: ${{ needs.prepare.outputs.version }}
RELEASE_NAME: ${{matrix.asset_name}}.tar.gz
run: |
echo "RELEASE_NAME=${{env.RELEASE_NAME}}" >> $GITHUB_ENV
echo "DEB_NAME=${{matrix.asset_name}}.deb" >> $GITHUB_ENV
echo "VERSION=${{env.VERSION}}" >> $GITHUB_ENV
echo "ARTIFACT_URL=https://${{ env.BUCKET_NAME }}.s3.ap-southeast-1.amazonaws.com/${{ env.VERSION }}/${{ env.RELEASE_NAME }}" >> $GITHUB_ENV
- name: configure aws credentials
if: matrix.os == 'ubuntu-20-16-cores'
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-session-name: deployer
aws-region: ap-southeast-1
- name: Upload release to S3
id: upload_s3
if: matrix.os == 'ubuntu-20-16-cores'
run: |
aws s3 cp $RELEASE_NAME s3://${{ env.BUCKET_NAME }}/$VERSION/$RELEASE_NAME
- name: Upload release deb to S3
id: upload_s3_deb
if: matrix.os == 'ubuntu-20-16-cores'
run: |
aws s3 cp deb/$DEB_NAME s3://${{ env.BUCKET_NAME }}/$VERSION/$DEB_NAME
- name: Build, tag, and push image to Amazon ECR
id: build_push_ecr
if: matrix.os == 'ubuntu-20-16-cores'
env:
IMAGE_TAG: ${{ needs.prepare.outputs.version }}
run: |
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin $ECR_REGISTRY
docker build -f ci/Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA .
docker push $ECR_REGISTRY/$ECR_REPOSITORY --all-tags
- name: Update latest image if releasing
if: (needs.prepare.outputs.prerelease == 'false') && (matrix.os == 'ubuntu-20-16-cores')
env:
IMAGE_TAG: ${{ needs.prepare.outputs.version }}
run: |
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
- name: Log in to Docker Hub
if: (github.event_name == 'release') && (needs.prepare.outputs.prerelease == 'false') && (matrix.os == 'ubuntu-20-16-cores')
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image to Docker Hub
if: (github.event_name == 'release') && (needs.prepare.outputs.prerelease == 'false') && (matrix.os == 'ubuntu-20-16-cores')
env:
IMAGE_TAG: ${{ needs.prepare.outputs.version }}
uses: docker/build-push-action@v2
with:
context: .
file: ./ci/Dockerfile
push: true
tags: ${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_REPOSITORY }}:latest,${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: Release notification
if: ${{ env.VERSION != 'dev' && matrix.os == 'ubuntu-20-16-cores'}}
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_RELEASE_HOOK }}
DISCORD_EMBEDS: '[ {
"title": "New version `${{env.VERSION}}` released",
"author": { "icon_url": "https://avatars.githubusercontent.com/${{ github.actor }}", "name": "${{ github.actor }}", "url": "https://github.com/${{github.actor}}" },
"fields": [
{ "name": "Repository", "value": "[getdozer/dozer](https://github.com/getdozer/dozer)", "inline": true },
{ "name": "Binary", "value": "[${{ env.RELEASE_NAME }}](${{ env.ARTIFACT_URL }})", "inline": true },
{ "name": "Using Binary", "value": "`dozer -h`"},
{ "name": "Release Notes", "value": "Release notes can be found [here](https://github.com/getdozer/dozer/releases/tag/${{env.VERSION}})"}
],
"color": 990099
}]'
uses: Ilshidur/action-discord@master