-
Notifications
You must be signed in to change notification settings - Fork 1
250 lines (223 loc) · 10.3 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
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:
toolchain: [stable, nightly]
host: [ubuntu-22.04, macos-13]
runs-on: ${{ matrix.host }}
steps:
- name: Checkout source
uses: actions/checkout@v4.1.6
- name: Install ${{ matrix.toolchain }} toolchain
uses: actions-rs/toolchain@v1.0.7
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
components: rustfmt, clippy
override: true
- name: Set up cargo cache
uses: actions/cache@v4.0.2
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
run: cargo fmt -- --check
- name: Static analysis with clippy
run: cargo clippy --all-targets ${{ matrix.toolchain == 'nightly' && '-F nightly' || '' }}
- name: Run tests
run: cargo test
- name: Run benchmarks
run: cargo bench ${{ matrix.toolchain == 'nightly' && '-F nightly' || '' }}
if: matrix.toolchain == 'nightly'
- name: Check for security issues
uses: actions-rs/audit-check@v1.2.0
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-13, profile: release, toolchain: stable }
- { desc: arm-mac-dbg, target: aarch64-apple-darwin, host: macos-13, profile: debug, toolchain: stable }
- { desc: intel-mac, target: x86_64-apple-darwin, host: macos-13, profile: release, toolchain: stable }
- { desc: intel-mac-dbg, target: x86_64-apple-darwin, host: macos-13, 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/checkout@v4.1.6
- name: Install ${{ matrix.toolchain }} toolchain
uses: actions-rs/toolchain@v1.0.7
with:
toolchain: stable
profile: minimal
target: ${{ matrix.target }}
components: rustfmt, clippy
- name: Set up cargo cache
uses: actions/cache@v4.0.2
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/cargo@v1.0.3
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/upload-artifact@v4.3.3
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/checkout@v4.1.6
- name: Download binaries
uses: actions/download-artifact@v4.1.8
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/metadata-action@v5.5.1
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/setup-qemu-action@v3.0.0
with:
platforms: ${{ steps.docker_binaries.outputs.platforms }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.3.0
- name: Login to Docker Hub
uses: docker/login-action@v3.1.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GHCR
uses: docker/login-action@v3.1.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5.3.0
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/dockerhub-description@v4.0.0
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/download-artifact@v4.1.8
id: download
- name: Publish GitHub release
uses: softprops/action-gh-release@v2.0.5
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