Skip to content

Commit a4b9bf2

Browse files
committed
ci: add failure notifications; add publish release workflow
ci.yml: - notify-pr-failure: first-failure-only Slack on PR CI failure - notify-main-failure: Slack + email on push-to-main build failure publish.yml (new): - Builds o_rly + o_rly_core on ubuntu-22.04-amd64 - Packages binary tarball as {repo}-ubuntu-22.04-amd64.tar.gz - Creates gh release build-{sha} with 20-release rotation - Slack + email notifications (success and failure) - Rename-resilient: repo name via github.event.repository.name throughout
1 parent 663c4ca commit a4b9bf2

2 files changed

Lines changed: 210 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,63 @@ jobs:
5555
name: "test (${{ matrix.name }})"
5656
path: ${{ matrix.build_dir }}/test-results.xml
5757
reporter: java-junit
58+
59+
notify-pr-failure:
60+
runs-on: ubuntu-22.04
61+
needs: [build]
62+
if: failure() && github.event_name == 'pull_request'
63+
steps:
64+
- name: Notify Slack (first failure only)
65+
continue-on-error: true
66+
env:
67+
GH_TOKEN: ${{ github.token }}
68+
SLACK_WEBHOOK_URL: ${{ secrets.OMOQ_SLACK_WEBHOOK_URL }}
69+
run: |
70+
PREV=$(gh api \
71+
"repos/${{ github.repository }}/actions/workflows/ci.yml/runs?branch=${{ github.head_ref }}&event=pull_request&per_page=2" \
72+
--jq '.workflow_runs[1].conclusion // "none"' 2>/dev/null) || PREV="none"
73+
if [ "$PREV" = "failure" ]; then
74+
echo "Previous run also failed — skipping"
75+
exit 0
76+
fi
77+
TEXT=":x: *${{ github.repository }}* \`${{ github.head_ref }}\` failed — <${{ github.event.pull_request.html_url }}|PR #${{ github.event.pull_request.number }}> · <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|run> · <${{ github.event.pull_request.html_url }}/checks|tests>"
78+
curl -s -X POST "$SLACK_WEBHOOK_URL" \
79+
-H "Content-Type: application/json" \
80+
--data "{\"text\": \"${TEXT}\"}"
81+
82+
notify-main-failure:
83+
runs-on: ubuntu-22.04
84+
needs: [build]
85+
if: failure() && github.event_name == 'push'
86+
steps:
87+
- name: Notify Slack
88+
continue-on-error: true
89+
env:
90+
SLACK_WEBHOOK_URL: ${{ secrets.OMOQ_SLACK_WEBHOOK_URL }}
91+
run: |
92+
SHORT="${GITHUB_SHA:0:12}"
93+
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
94+
TEXT=":x: *${{ github.repository }}* \`${{ github.ref_name }}\` \`${SHORT}\` — build failed · <${RUN_URL}|run>"
95+
curl -s -X POST "$SLACK_WEBHOOK_URL" \
96+
-H "Content-Type: application/json" \
97+
--data "{\"text\": \"${TEXT}\"}"
98+
99+
- name: Notify email
100+
continue-on-error: true
101+
env:
102+
AWS_ACCESS_KEY_ID: ${{ secrets.OMOQ_AWS_ACCESS_KEY_ID }}
103+
AWS_SECRET_ACCESS_KEY: ${{ secrets.OMOQ_AWS_SECRET_ACCESS_KEY }}
104+
AWS_DEFAULT_REGION: us-east-1
105+
run: |
106+
SHORT="${GITHUB_SHA:0:12}"
107+
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
108+
REPO_NAME="${{ github.event.repository.name }}"
109+
SUBJECT="[${REPO_NAME}] build FAILED ${{ github.ref_name }} ${SHORT}"
110+
BODY="${{ github.repository }} · ${{ github.ref_name }} · ${SHORT}\n${RUN_URL}"
111+
aws ses send-email \
112+
--from "noreply@ci.openmoq.org" \
113+
--destination '{"ToAddresses":["github-notifications@openmoq.org"]}' \
114+
--message "{
115+
\"Subject\": {\"Data\": \"$SUBJECT\"},
116+
\"Body\": {\"Text\": {\"Data\": \"$BODY\"}}
117+
}"

.github/workflows/publish.yml

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: publish release
2+
3+
# Builds o-rly on each target platform and publishes per-architecture
4+
# artifact tarballs as a GitHub Release keyed by commit SHA.
5+
6+
on:
7+
push:
8+
branches: [main]
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: write
13+
packages: write # reserved for future Docker image publishing
14+
15+
jobs:
16+
build:
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
include:
21+
- name: ubuntu-22.04-amd64
22+
runner: ubuntu-22.04
23+
24+
name: ${{ matrix.name }}
25+
runs-on: ${{ matrix.runner }}
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
submodules: true
31+
32+
- name: Install system dependencies
33+
run: bash deps/moxygen/standalone/install-system-deps.sh
34+
35+
- name: Download moxygen release tarball
36+
env:
37+
GH_TOKEN: ${{ github.token }}
38+
run: bash scripts/setup-deps-tarball.sh
39+
40+
- name: Set up ccache
41+
uses: hendrikmuhs/ccache-action@v1
42+
with:
43+
key: publish-${{ matrix.name }}
44+
max-size: 500M
45+
46+
- name: Configure
47+
run: |
48+
cmake -S . -B _build --preset default \
49+
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
50+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
51+
-DCMAKE_PREFIX_PATH="$(cat .scratch/cmake_prefix_path.txt)" \
52+
-DBUILD_TESTING=OFF
53+
54+
- name: Build
55+
run: cmake --build _build -j$(nproc)
56+
57+
- name: Install
58+
run: cmake --install _build --prefix "$GITHUB_WORKSPACE/install"
59+
60+
- name: Package
61+
id: package
62+
run: |
63+
ARTIFACT="${{ github.event.repository.name }}-${{ matrix.name }}.tar.gz"
64+
tar czf "$ARTIFACT" -C "$GITHUB_WORKSPACE/install" .
65+
echo "artifact=$ARTIFACT" >> "$GITHUB_OUTPUT"
66+
67+
- name: Upload artifact
68+
uses: actions/upload-artifact@v4
69+
with:
70+
name: ${{ steps.package.outputs.artifact }}
71+
path: ${{ steps.package.outputs.artifact }}
72+
retention-days: 90
73+
74+
release:
75+
runs-on: ubuntu-22.04
76+
needs: [build]
77+
if: always()
78+
steps:
79+
- uses: actions/checkout@v4
80+
if: needs.build.result == 'success'
81+
82+
- name: Download all artifacts
83+
if: needs.build.result == 'success'
84+
uses: actions/download-artifact@v4
85+
with:
86+
path: artifacts/
87+
88+
- name: Create release
89+
if: needs.build.result == 'success'
90+
env:
91+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92+
run: |
93+
SHORT="${GITHUB_SHA:0:12}"
94+
TAG="build-${SHORT}"
95+
gh release create "$TAG" artifacts/**/* \
96+
--repo "${{ github.repository }}" \
97+
--title "build ${SHORT}" \
98+
--notes "Automated release from \`${{ github.ref_name }}\` at \`${SHORT}\`."
99+
100+
# Prune old releases, keep 20
101+
gh api "repos/${{ github.repository }}/releases" \
102+
--jq 'sort_by(.created_at) | reverse | .[20:] | .[].tag_name' \
103+
| while read -r tag; do
104+
gh release delete "$tag" --repo "${{ github.repository }}" --yes --cleanup-tag 2>/dev/null || true
105+
done
106+
107+
- name: Notify Slack
108+
if: always()
109+
continue-on-error: true
110+
env:
111+
SLACK_WEBHOOK_URL: ${{ secrets.OMOQ_SLACK_WEBHOOK_URL }}
112+
run: |
113+
SHORT="${GITHUB_SHA:0:12}"
114+
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
115+
if [ "${{ needs.build.result }}" = "success" ]; then
116+
REL_URL="${{ github.server_url }}/${{ github.repository }}/releases/tag/build-${SHORT}"
117+
TEXT=":white_check_mark: *${{ github.repository }}* \`${{ github.ref_name }}\` \`${SHORT}\` — <${REL_URL}|release> · <${RUN_URL}|run>"
118+
else
119+
TEXT=":x: *${{ github.repository }}* \`${{ github.ref_name }}\` \`${SHORT}\` — build failed · <${RUN_URL}|run>"
120+
fi
121+
curl -s -X POST "$SLACK_WEBHOOK_URL" \
122+
-H "Content-Type: application/json" \
123+
--data "{\"text\": \"${TEXT}\"}"
124+
125+
- name: Notify email
126+
if: always()
127+
continue-on-error: true
128+
env:
129+
AWS_ACCESS_KEY_ID: ${{ secrets.OMOQ_AWS_ACCESS_KEY_ID }}
130+
AWS_SECRET_ACCESS_KEY: ${{ secrets.OMOQ_AWS_SECRET_ACCESS_KEY }}
131+
AWS_DEFAULT_REGION: us-east-1
132+
run: |
133+
SHORT="${GITHUB_SHA:0:12}"
134+
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
135+
REPO_NAME="${{ github.event.repository.name }}"
136+
RESULT="${{ needs.build.result }}"
137+
JOB_STATUS="${{ job.status }}"
138+
if [ "$RESULT" = "success" ] && [ "$JOB_STATUS" = "success" ]; then
139+
SUBJECT="[${REPO_NAME}] published ${{ github.ref_name }} ${SHORT}"
140+
else
141+
SUBJECT="[${REPO_NAME}] build FAILED ${{ github.ref_name }} ${SHORT}"
142+
fi
143+
BODY="${{ github.repository }} · ${{ github.ref_name }} · ${SHORT}\n${RUN_URL}"
144+
aws ses send-email \
145+
--from "noreply@ci.openmoq.org" \
146+
--destination '{"ToAddresses":["github-notifications@openmoq.org"]}' \
147+
--message "{
148+
\"Subject\": {\"Data\": \"$SUBJECT\"},
149+
\"Body\": {\"Text\": {\"Data\": \"$BODY\"}}
150+
}"

0 commit comments

Comments
 (0)