-
Notifications
You must be signed in to change notification settings - Fork 1
259 lines (232 loc) · 10.4 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
255
256
257
258
259
on:
push:
branches:
- "develop"
- "dev/*"
tags:
- "v*.*.*"
pull_request:
branches:
- "develop"
name: Build Pipeline
permissions:
checks: write
packages: write
pull-requests: write
security-events: read
statuses: write
contents: write
jobs:
check:
name: Check on ${{ matrix.host }} against ${{ matrix.toolchain }} Rust
strategy:
fail-fast: false
matrix:
include:
- { toolchain: stable, host: ubuntu-22.04 }
- { toolchain: nightly, host: macos-12 }
runs-on: ${{ matrix.host }}
steps:
- name: Checkout source
uses: actions/[email protected]
- name: Install ${{ matrix.toolchain }} toolchain
uses: actions-rs/[email protected]
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
components: rustfmt, clippy
- name: Set up cargo cache
uses: actions/[email protected]
continue-on-error: false
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: cargo-${{ runner.os }}-${{ matrix.toolchain }}-${{ matrix.target }}-${{ matrix.profile }}-${{ hashFiles('**/Cargo.lock') }}-check
restore-keys: |
cargo-${{ runner.os }}-${{ matrix.toolchain }}-${{ matrix.target }}-${{ matrix.profile }}-${{ hashFiles('**/Cargo.lock') }}-check
cargo-${{ runner.os }}-${{ matrix.toolchain }}-${{ matrix.target }}-${{ matrix.profile }}-${{ hashFiles('**/Cargo.lock') }}
cargo-${{ runner.os }}-${{ matrix.toolchain }}-${{ matrix.target }}-${{ matrix.profile }}
cargo-${{ runner.os }}-${{ matrix.toolchain }}-${{ matrix.target }}
- name: Check formatting
uses: actions-rs/[email protected]
with:
command: fmt
args: --all -- --check
- name: Static analysis with clippy
uses: actions-rs/[email protected]
with:
command: clippy
- name: Static analysis with clippy
uses: actions-rs/[email protected]
with:
command: clippy
args: --tests
- name: Run tests
uses: actions-rs/[email protected]
with:
command: test
- name: Check for security issues
uses: actions-rs/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
build-binary:
name: ${{ matrix.profile == 'debug' && 'Debug build' || 'Build' }} ${{ matrix.desc }} binary (${{ matrix.target }})
strategy:
fail-fast: false
matrix:
include:
- { desc: arm-mac, target: aarch64-apple-darwin, host: macos-12, profile: release, toolchain: stable }
- { desc: arm-mac-dbg, target: aarch64-apple-darwin, host: macos-12, profile: debug, toolchain: stable }
- { desc: intel-mac, target: x86_64-apple-darwin, host: macos-12, profile: release, toolchain: stable }
- { desc: intel-mac-dbg, target: x86_64-apple-darwin, host: macos-12, profile: debug, toolchain: stable }
- { desc: arm-linux, target: armv7-unknown-linux-gnueabihf, host: ubuntu-22.04, profile: release, toolchain: stable }
- { desc: arm-linux-dbg, target: armv7-unknown-linux-gnueabihf, host: ubuntu-22.04, profile: debug, toolchain: stable }
- { desc: arm-linux-static, target: armv7-unknown-linux-musleabihf, host: ubuntu-22.04, profile: release, toolchain: stable }
- { desc: arm-linux-static-dbg, target: armv7-unknown-linux-musleabihf, host: ubuntu-22.04, profile: debug, toolchain: stable }
- { desc: arm64-linux, target: aarch64-unknown-linux-gnu, host: ubuntu-22.04, profile: release, toolchain: stable }
- { desc: arm64-linux-dbg, target: aarch64-unknown-linux-gnu, host: ubuntu-22.04, profile: debug, toolchain: stable }
- { desc: arm64-linux-static, target: aarch64-unknown-linux-musl, host: ubuntu-22.04, profile: release, toolchain: stable }
- { desc: arm64-linux-static-dbg, target: aarch64-unknown-linux-musl, host: ubuntu-22.04, profile: debug, toolchain: stable }
- { desc: x86_64-linux, target: x86_64-unknown-linux-gnu, host: ubuntu-22.04, profile: release, toolchain: stable }
- { desc: x86_64-linux-dbg, target: x86_64-unknown-linux-gnu, host: ubuntu-22.04, profile: debug, toolchain: stable }
- { desc: x86_64-linux-static, target: x86_64-unknown-linux-musl, host: ubuntu-22.04, profile: release, toolchain: stable }
- { desc: x86_64-linux-static-dbg, target: x86_64-unknown-linux-musl, host: ubuntu-22.04, profile: debug, toolchain: stable }
runs-on: ${{ matrix.host }}
steps:
- name: Checkout source
uses: actions/[email protected]
- name: Install ${{ matrix.toolchain }} toolchain
uses: actions-rs/[email protected]
with:
toolchain: stable
profile: minimal
target: ${{ matrix.target }}
components: rustfmt, clippy
- name: Set up cargo cache
uses: actions/[email protected]
continue-on-error: false
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: cargo-${{ runner.os }}-${{ matrix.toolchain }}-${{ matrix.target }}-${{ matrix.profile }}-${{ hashFiles('**/Cargo.lock') }}-build
restore-keys: |
cargo-${{ runner.os }}-${{ matrix.toolchain }}-${{ matrix.target }}-${{ matrix.profile }}-${{ hashFiles('**/Cargo.lock') }}-build
cargo-${{ runner.os }}-${{ matrix.toolchain }}-${{ matrix.target }}-${{ matrix.profile }}-${{ hashFiles('**/Cargo.lock') }}
cargo-${{ runner.os }}-${{ matrix.toolchain }}-${{ matrix.target }}-${{ matrix.profile }}
cargo-${{ runner.os }}-${{ matrix.toolchain }}-${{ matrix.target }}
- name: Install cross
uses: actions-rs/[email protected]
with:
use-cross: true
command: help # We just need to make sure that cross is available
- name: Build ${{ matrix.profile }} archive
run: make dist
env:
CARGO: cross
DEBUG: ${{ matrix.profile == 'debug' && 1 || 0 }}
RELEASE: ${{ startsWith(github.ref, 'refs/tags/') && 1 || 0 }}
SUFFIX: ${{ matrix.desc }}
TARGET: ${{ matrix.target }}
- name: Find archive
run: echo archive=`ls prometheus-weathermen-*.tar.zz` >> $GITHUB_OUTPUT
id: list-archive
- name: Upload ${{ matrix.profile }} binary
uses: actions/[email protected]
with:
name: ${{ steps.list-archive.outputs.archive }}
path: ${{ steps.list-archive.outputs.archive }}
if-no-files-found: error
build-docker:
needs: [build-binary]
name: Build Docker images
runs-on: ubuntu-22.04
env:
CONTAINER_BINARY_DIR: target/container-binaries
if: github.event_name != 'pull_request'
steps:
- name: Checkout source
uses: actions/[email protected]
- name: Download binaries
uses: actions/[email protected]
id: docker_download
- name: Prepare binaries
id: docker_binaries
shell: bash
run: make container-binaries PLATFORM_FILE=$GITHUB_OUTPUT
env:
BINARY_ARCHIVE_DIR: ${{ steps.docker_download.outputs.download-path }}
- name: Generate metadata
id: docker_metadata
uses: docker/[email protected]
with:
images: |
lstrojny/prometheus-weathermen
ghcr.io/lstrojny/prometheus-weathermen
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
labels: |
org.opencontainers.image.licenses=MIT OR Apache2
- name: Set up QEMU
uses: docker/[email protected]
with:
platforms: ${{ steps.docker_binaries.outputs.platforms }}
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Login to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GHCR
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/[email protected]
with:
context: .
push: true
tags: ${{ steps.docker_metadata.outputs.tags }}
labels: ${{ steps.docker_metadata.outputs.labels }}
platforms: ${{ steps.docker_binaries.outputs.platforms }}
build-args: CONTAINER_BINARY_DIR=${{ env.CONTAINER_BINARY_DIR }}
- name: Docker Hub Description
uses: peter-evans/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: lstrojny/prometheus-weathermen
short-description: A prometheus exporter endpoint for weather data
release:
needs: [check, build-binary, build-docker]
name: Release
runs-on: ubuntu-22.04
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Download binaries
uses: actions/[email protected]
id: download
- name: Publish GitHub release
uses: softprops/[email protected]
with:
fail_on_unmatched_files: true
# Nested because for each archive a sub-folder of the same name is create to avoid conflicts when downloading
files: ${{ steps.download.outputs.download-path }}/prometheus-weathermen-*.tar.zz/prometheus-weathermen-*.tar.zz
generate_release_notes: true