-
Notifications
You must be signed in to change notification settings - Fork 5
297 lines (248 loc) · 11.5 KB
/
Copy pathci-main.yml
File metadata and controls
297 lines (248 loc) · 11.5 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
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
name: ci main
# Full pipeline on push to main: format, build/test, publish artifacts + Docker,
# release snapshot, notify. PRs use ci-pr.yml (format + build/test only).
#
# Job graph:
#
# format ─────────────────────────────────────────────┐
# build (linux, asan debug) ── publish ── release ────┼── notify
# │ (always)
on:
push:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: write
checks: write
packages: write
jobs:
# ════════════════════════════════════════════════════════════════════════════
# Verify: format + build/test matrix
# ════════════════════════════════════════════════════════════════════════════
format:
runs-on: ubuntu-latest
container: debian:trixie
steps:
- name: Install tools
run: apt-get update && apt-get install -y --no-install-recommends ca-certificates git clang-format
- uses: actions/checkout@v4
- name: Check formatting
run: bash scripts/format.sh --check
build:
strategy:
fail-fast: false
matrix:
include:
- name: linux
preset: default
build_dir: build
runner: ubuntu-22.04
- name: asan debug
preset: san
build_dir: build-san
runner: ubuntu-22.04
name: ${{ matrix.name }}
runs-on: ${{ matrix.runner }}
steps:
- name: Generate app token
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.OMOQ_APP_ID }}
private-key: ${{ secrets.OMOQ_APP_PRIV_KEY }}
- uses: actions/checkout@v4
with:
submodules: true
- name: Install system dependencies
run: bash deps/moxygen/standalone/install-system-deps.sh
- name: Download moxygen artifacts
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: bash scripts/setup-deps-tarball.sh
- name: Configure
run: bash scripts/configure.sh ${{ matrix.build_dir }} ${{ matrix.preset }}
- name: Build
run: cmake --build ${{ matrix.build_dir }} -j$(getconf _NPROCESSORS_ONLN)
- name: Test
env:
ASAN_OPTIONS: ${{ matrix.name == 'asan debug' && 'detect_leaks=1:abort_on_error=1' || '' }}
run: ctest --test-dir ${{ matrix.build_dir }} --output-on-failure --output-junit test-results.xml
- name: Publish test results
uses: dorny/test-reporter@v1.9.1
if: success() || failure()
with:
name: "test (${{ matrix.name }})"
path: ${{ matrix.build_dir }}/test-results.xml
reporter: java-junit
fail-on-empty: ${{ job.status == 'success' && 'true' || 'false' }}
# ════════════════════════════════════════════════════════════════════════════
# Publish: build o-rly artifacts + Docker image (needs verify to pass)
# ════════════════════════════════════════════════════════════════════════════
publish:
needs: [build]
strategy:
fail-fast: false
matrix:
include:
- name: ubuntu-22.04-amd64
name: publish (${{ matrix.name }})
runs-on: ubuntu-22.04
steps:
- name: Generate app token
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.OMOQ_APP_ID }}
private-key: ${{ secrets.OMOQ_APP_PRIV_KEY }}
- uses: actions/checkout@v4
with:
submodules: true
- name: Install system dependencies
run: bash deps/moxygen/standalone/install-system-deps.sh
- name: Download moxygen artifacts
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: bash scripts/setup-deps-tarball.sh
- name: Set up ccache
uses: hendrikmuhs/ccache-action@v1
with:
key: publish-${{ matrix.name }}
max-size: 500M
- name: Configure
run: |
cmake -S . -B _build --preset default \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_PREFIX_PATH="$(cat .scratch/cmake_prefix_path.txt)" \
-DBUILD_TESTING=OFF
- name: Build
run: cmake --build _build -j$(getconf _NPROCESSORS_ONLN)
- name: Install
run: cmake --install _build --prefix "$GITHUB_WORKSPACE/install"
- name: Log in to GHCR
if: runner.os == 'Linux'
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build and push Docker image
if: runner.os == 'Linux'
run: |
SHORT="${GITHUB_SHA:0:7}"
IMAGE="ghcr.io/${{ github.repository }}"
docker build -f docker/Dockerfile \
-t "${IMAGE}:${SHORT}" \
-t "${IMAGE}:latest" \
.
docker push "${IMAGE}:${SHORT}"
docker push "${IMAGE}:latest"
- name: Package
id: package
run: |
ARTIFACT="${{ github.event.repository.name }}-${{ matrix.name }}.tar.gz"
tar czf "$ARTIFACT" -C "$GITHUB_WORKSPACE/install" .
echo "artifact=$ARTIFACT" >> "$GITHUB_OUTPUT"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.package.outputs.artifact }}
path: ${{ steps.package.outputs.artifact }}
retention-days: 90
# ════════════════════════════════════════════════════════════════════════════
# Release: create/update snapshot-latest pre-release (all green)
# ════════════════════════════════════════════════════════════════════════════
release:
needs: [build, publish]
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts/
- name: Publish snapshot
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
SHORT="${GITHUB_SHA:0:7}"
TAG="snapshot-latest"
gh release delete "$TAG" --yes 2>/dev/null || true
git tag -d "$TAG" 2>/dev/null || true
git push origin ":refs/tags/$TAG" 2>/dev/null || true
gh release create "$TAG" artifacts/**/* \
--title "Latest build ($SHORT)" \
--prerelease \
--notes "$(cat <<EOF
Rolling snapshot of the latest build from \`main\`.
**Commit:** \`${GITHUB_SHA}\`
**Built:** $(date -u +%Y-%m-%dT%H:%M:%SZ)
**Docker:** \`ghcr.io/${{ github.repository }}:${SHORT}\`
This pre-release is automatically replaced on every push to \`main\`.
EOF
)"
# ════════════════════════════════════════════════════════════════════════════
# Notify: aggregate status (runs after everything)
# ════════════════════════════════════════════════════════════════════════════
notify:
needs: [format, build, publish, release]
if: always()
runs-on: ubuntu-22.04
steps:
- name: Notify Slack
continue-on-error: true
env:
SLACK_WEBHOOK_URL: ${{ secrets.OMOQ_SLACK_WEBHOOK_URL }}
run: |
SHORT="${GITHUB_SHA:0:7}"
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
# Map job results to status symbols
fmt_status() {
case "$1" in
success) echo "✓" ;;
failure) echo "✗" ;;
cancelled) echo "⊘" ;;
*) echo "—" ;;
esac
}
FMT=$(fmt_status "${{ needs.format.result }}")
VER=$(fmt_status "${{ needs.build.result }}")
PUB=$(fmt_status "${{ needs.publish.result }}")
REL=$(fmt_status "${{ needs.release.result }}")
STATUS="format:${FMT} verify:${VER} publish:${PUB} release:${REL}"
if [ "${{ needs.release.result }}" = "success" ]; then
REL_URL="${{ github.server_url }}/${{ github.repository }}/releases/tag/snapshot-latest"
TEXT=":white_check_mark: *${{ github.repository }}* \`${{ github.ref_name }}\` \`${SHORT}\` — ${STATUS} <${RUN_URL}|#${{ github.run_number }}> artifacts: <${REL_URL}|view>"
else
TEXT=":x: *${{ github.repository }}* \`${{ github.ref_name }}\` \`${SHORT}\` — ${STATUS} <${RUN_URL}|#${{ github.run_number }}>"
fi
curl -s -X POST "$SLACK_WEBHOOK_URL" \
-H "Content-Type: application/json" \
--data "{\"text\": \"${TEXT}\"}"
- name: Notify email
continue-on-error: true
env:
AWS_ACCESS_KEY_ID: ${{ secrets.OMOQ_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.OMOQ_AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1
run: |
SHORT="${GITHUB_SHA:0:7}"
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
FMT="${{ needs.format.result }}"
VER="${{ needs.build.result }}"
PUB="${{ needs.publish.result }}"
REL="${{ needs.release.result }}"
STATUS="format:${FMT} verify:${VER} publish:${PUB} release:${REL}"
if [ "${{ needs.release.result }}" = "success" ]; then
REL_URL="${{ github.server_url }}/${{ github.repository }}/releases/tag/snapshot-latest"
SUBJECT="[o-rly] published ${{ github.ref_name }} ${SHORT}"
BODY="Repository: ${{ github.repository }}\nBranch: ${{ github.ref_name }}\nCommit: ${GITHUB_SHA}\nStatus: ${STATUS}\nDocker: ghcr.io/${{ github.repository }}:${SHORT}\nArtifacts: ${REL_URL}\nRun: ${RUN_URL}"
else
SUBJECT="[o-rly] pipeline failed ${{ github.ref_name }} ${SHORT}"
BODY="Repository: ${{ github.repository }}\nBranch: ${{ github.ref_name }}\nCommit: ${GITHUB_SHA}\nStatus: ${STATUS}\nRun: ${RUN_URL}"
fi
aws ses send-email \
--from "noreply@ci.openmoq.org" \
--destination '{"ToAddresses":["github-notifications@openmoq.org"]}' \
--message "{
\"Subject\": {\"Data\": \"${SUBJECT}\"},
\"Body\": {\"Text\": {\"Data\": \"${BODY}\"}}
}"