-
Notifications
You must be signed in to change notification settings - Fork 0
196 lines (168 loc) · 4.83 KB
/
cicd.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
name: CI/CD
on:
push:
paths-ignore:
- ".devcontainer"
- ".github/workflows/pkg.yml"
- ".github/workflows/update-packagers.yml"
- ".github/dependabot.yml"
- "templates"
- "LICENSE"
- "*.md"
- "test.sh"
pull_request:
paths-ignore:
- ".devcontainer"
- ".github/workflows/pkg.yml"
- ".github/workflows/update-packagers.yml"
- ".github/dependabot.yml"
- "templates"
- "LICENSE"
- "*.md"
- "test.sh"
jobs:
test-n-build:
name: Test and build
runs-on: ubuntu-20.04
steps:
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Checkout
uses: actions/checkout@v3
- name: Restore cache
uses: Swatinem/rust-cache@v1
- name: Test
uses: actions-rs/cargo@v1
with:
command: test
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --release
- name: Archive
run: |
mv target/release/alerter .
tar -czvf alerter-$(cargo read-manifest | jq -r .version).tar.gz alerter templates
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: alerter-archive
path: alerter-*.tar.gz
package:
name: Package
needs: test-n-build
uses: ./.github/workflows/pkg.yml
docker:
name: Docker image
needs: test-n-build
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set docker image tag
if: startsWith(github.ref, 'refs/tags/')
run: echo "DOCKER_TAG=:$(cargo read-manifest | jq -r .version)" >> $GITHUB_ENV
- name: Login to DockerHub
uses: docker/login-action@v2
if: startsWith(github.ref, 'refs/tags/')
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GHCR
uses: docker/login-action@v2
if: startsWith(github.ref, 'refs/tags/')
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: ${{ startsWith(github.ref, 'refs/tags/') }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
ultram4rine/alerter:latest
ghcr.io/ultram4rine/alerter:latest
ultram4rine/alerter${{ env.DOCKER_TAG }}
ghcr.io/ultram4rine/alerter${{ env.DOCKER_TAG }}
release:
name: Release
runs-on: ubuntu-20.04
if: startsWith(github.ref, 'refs/tags/')
needs:
- test-n-build
- package
- docker
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download archive
uses: actions/download-artifact@v3
with:
name: alerter-archive
path: archive
- name: Download Deb package
uses: actions/download-artifact@v3
with:
name: alerter-deb
path: packages
- name: Download RPM package
uses: actions/download-artifact@v3
with:
name: alerter-rpm
path: packages
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::$(cargo read-manifest | jq -r .version)
- name: Create release body
id: extract_changes
uses: ultram4rine/extract-changes-action@v1
with:
changelog: CHANGELOG.md
version: ${{ steps.get_version.outputs.VERSION }}
- name: Release
uses: softprops/action-gh-release@v1
with:
body: ${{ steps.extract_changes.outputs.changes }}
files: |
archive/alerter-*.tar.gz
packages/**/*
publish_crate:
name: Publish crate
runs-on: ubuntu-20.04
if: startsWith(github.ref, 'refs/tags/')
needs:
- test-n-build
- package
- docker
steps:
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Checkout
uses: actions/checkout@v3
- name: Restore cache
uses: Swatinem/rust-cache@v1
- name: Login to crates.io
uses: actions-rs/cargo@v1
with:
command: login
args: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Publish to crates.io
uses: actions-rs/cargo@v1
with:
command: publish