-
-
Notifications
You must be signed in to change notification settings - Fork 9
255 lines (223 loc) · 8.07 KB
/
Copy pathci.yml
File metadata and controls
255 lines (223 loc) · 8.07 KB
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
name: Rust CI
on:
push:
branches:
- master
- production
- dev
- testing
tags:
- 'v*'
pull_request:
branches:
- master
jobs:
build-and-test:
name: Build & Test (features=${{ matrix.features }})
runs-on: ubuntu-latest
env:
CONFIG_FIXTURES_TOKEN: ${{ secrets.CONFIG_FIXTURES_TOKEN }}
strategy:
fail-fast: false
matrix:
features: [default, minimal]
rust: [stable]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout shared pipe fixtures repo
id: checkout_shared_fixtures
if: ${{ env.CONFIG_FIXTURES_TOKEN != '' }}
continue-on-error: true
uses: actions/checkout@v4
with:
repository: trydirect/config
ref: main
token: ${{ env.CONFIG_FIXTURES_TOKEN }}
path: config-fixtures-repo
fetch-depth: 1
persist-credentials: false
sparse-checkout: |
shared-fixtures
- name: Shared pipe fixtures unavailable
if: ${{ env.CONFIG_FIXTURES_TOKEN == '' || steps.checkout_shared_fixtures.outcome != 'success' }}
run: |
echo "::notice::Shared pipe fixtures are unavailable for this workflow run; shared-fixture tests will be skipped."
- name: Link shared pipe fixtures
if: ${{ env.CONFIG_FIXTURES_TOKEN != '' && steps.checkout_shared_fixtures.outcome == 'success' }}
run: |
rm -rf "${GITHUB_WORKSPACE}/../config" "${GITHUB_WORKSPACE}/../shared-fixtures"
ln -sfn "${GITHUB_WORKSPACE}/config-fixtures-repo/shared-fixtures" "${GITHUB_WORKSPACE}/../shared-fixtures"
test -d "${GITHUB_WORKSPACE}/../shared-fixtures/pipe-contract"
- name: Setup Rust toolchain (${{ matrix.rust }})
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo build artifacts
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: Show rustc and cargo versions
run: |
rustc -V
cargo -V
- name: Build (default features)
if: matrix.features == 'default'
run: cargo build --release
- name: Build (minimal features)
if: matrix.features == 'minimal'
run: cargo build --release --no-default-features --features minimal
- name: Run tests (default features)
if: matrix.features == 'default'
env:
STATUS_PANEL_USERNAME: admin
STATUS_PANEL_PASSWORD: admin
AGENT_ID: ci-agent
AGENT_TOKEN: ci-token
NGINX_CONTAINER: nginx
METRICS_INTERVAL_SECS: 1
run: |
cargo test --all --verbose
cargo test --test http_routes --verbose
- name: Run tests (minimal features)
if: matrix.features == 'minimal'
env:
STATUS_PANEL_USERNAME: admin
STATUS_PANEL_PASSWORD: admin
AGENT_ID: ci-agent
AGENT_TOKEN: ci-token
NGINX_CONTAINER: nginx
METRICS_INTERVAL_SECS: 1
run: |
cargo test --no-default-features --features minimal --all --verbose
cargo test --no-default-features --features minimal --test http_routes --verbose
- name: Rustfmt check
run: cargo fmt --all -- --check
- name: Clippy (default)
if: matrix.features == 'default'
run: cargo clippy -- -D warnings
- name: Clippy (minimal)
if: matrix.features == 'minimal'
run: cargo clippy --no-default-features --features minimal -- -D warnings
build-release-binaries:
name: Build Release Binaries (Linux x86_64)
runs-on: ubuntu-latest
needs: build-and-test
if: github.ref == 'refs/heads/production' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
strategy:
matrix:
target: [x86_64-unknown-linux-gnu, x86_64-unknown-linux-musl]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install musl tools
if: matrix.target == 'x86_64-unknown-linux-musl'
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Cache cargo build artifacts
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Build release binary
run: cargo build --release --target ${{ matrix.target }}
- name: Strip binary
run: strip target/${{ matrix.target }}/release/status
- name: Create artifact name
id: artifact
run: |
BRANCH=${GITHUB_REF#refs/*/}
if [[ "${{ matrix.target }}" == "x86_64-unknown-linux-musl" ]]; then
SIMPLE_NAME="status-linux-x86_64-musl"
else
SIMPLE_NAME="status-linux-x86_64"
fi
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
echo "name=${SIMPLE_NAME}-${BRANCH}" >> $GITHUB_OUTPUT
else
echo "name=${SIMPLE_NAME}-${BRANCH}-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
fi
echo "binary=${SIMPLE_NAME}" >> $GITHUB_OUTPUT
- name: Rename binary
run: |
cp target/${{ matrix.target }}/release/status ${{ steps.artifact.outputs.binary }}
- name: Upload binary artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.artifact.outputs.name }}
path: ${{ steps.artifact.outputs.binary }}
retention-days: 30
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: build-release-binaries
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- name: Download musl binary artifact
uses: actions/download-artifact@v4
with:
pattern: status-linux-x86_64-musl-*
merge-multiple: true
- name: Prepare release assets
run: |
ls -la status-linux-x86_64-musl
chmod +x status-linux-x86_64-musl
sha256sum status-linux-x86_64-musl > status-linux-x86_64-musl.sha256
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
files: |
status-linux-x86_64-musl
status-linux-x86_64-musl.sha256
docker-build:
name: Docker Build & Push (branches/tags)
runs-on: ubuntu-latest
needs: build-and-test
env:
STACKER_REPO_TOKEN: ${{ secrets.CONFIG_FIXTURES_TOKEN }}
if: |
github.ref == 'refs/heads/production' ||
github.ref == 'refs/heads/master' ||
github.ref == 'refs/heads/testing' ||
github.ref == 'refs/heads/dev' ||
startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout repository
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 DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Compute image tags
id: vars
run: |
REF_NAME="${GITHUB_REF#refs/*/}"
TAGS="trydirect/status:${REF_NAME}\ntrydirect/status:${GITHUB_SHA::7}"
if [[ "${GITHUB_REF}" == "refs/heads/dev" ]]; then
TAGS="${TAGS}\ntrydirect/status:unstable\ntrydirect/status:latest"
fi
echo "ref_name=${REF_NAME}" >> $GITHUB_OUTPUT
echo "sha_short=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
echo "tags<<EOF" >> $GITHUB_OUTPUT
echo -e "${TAGS}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Build and push image
uses: docker/build-push-action@v5
with:
context: .
build-contexts: |
stacker=./stacker
file: Dockerfile.prod
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.vars.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max