Skip to content

Commit a4d7c80

Browse files
committed
ci: move notify-failure to workflow_run to hide from PR checks
1 parent 26666f8 commit a4d7c80

2 files changed

Lines changed: 44 additions & 50 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -56,53 +56,3 @@ jobs:
5656
path: ${{ matrix.build_dir }}/test-results.xml
5757
reporter: java-junit
5858

59-
notify-failure:
60-
runs-on: ubuntu-22.04
61-
needs: [build]
62-
if: failure()
63-
steps:
64-
- name: Notify Slack
65-
continue-on-error: true
66-
env:
67-
GH_TOKEN: ${{ github.token }}
68-
SLACK_WEBHOOK_URL: ${{ secrets.OMOQ_SLACK_WEBHOOK_URL }}
69-
run: |
70-
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
71-
if [ "${{ github.event_name }}" = "pull_request" ]; then
72-
# First-failure-only: skip if previous run on this branch also failed
73-
PREV=$(gh api \
74-
"repos/${{ github.repository }}/actions/workflows/ci.yml/runs?branch=${{ github.head_ref }}&event=pull_request&per_page=2" \
75-
--jq '.workflow_runs[1].conclusion // "none"' 2>/dev/null) || PREV="none"
76-
if [ "$PREV" = "failure" ]; then
77-
echo "Previous run also failed — skipping"
78-
exit 0
79-
fi
80-
TEXT=":x: *${{ github.repository }}* \`${{ github.head_ref }}\` failed — <${{ github.event.pull_request.html_url }}|PR #${{ github.event.pull_request.number }}> · <${RUN_URL}|run> · <${{ github.event.pull_request.html_url }}/checks|tests>"
81-
else
82-
SHORT="${GITHUB_SHA:0:12}"
83-
TEXT=":x: *${{ github.repository }}* \`${{ github.ref_name }}\` \`${SHORT}\` — build failed · <${RUN_URL}|run>"
84-
fi
85-
curl -s -X POST "$SLACK_WEBHOOK_URL" \
86-
-H "Content-Type: application/json" \
87-
--data "{\"text\": \"${TEXT}\"}"
88-
89-
- name: Notify email (main only)
90-
if: github.event_name == 'push'
91-
continue-on-error: true
92-
env:
93-
AWS_ACCESS_KEY_ID: ${{ secrets.OMOQ_AWS_ACCESS_KEY_ID }}
94-
AWS_SECRET_ACCESS_KEY: ${{ secrets.OMOQ_AWS_SECRET_ACCESS_KEY }}
95-
AWS_DEFAULT_REGION: us-east-1
96-
run: |
97-
SHORT="${GITHUB_SHA:0:12}"
98-
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
99-
REPO_NAME="${{ github.event.repository.name }}"
100-
SUBJECT="[${REPO_NAME}] build FAILED ${{ github.ref_name }} ${SHORT}"
101-
BODY="${{ github.repository }} · ${{ github.ref_name }} · ${SHORT}\n${RUN_URL}"
102-
aws ses send-email \
103-
--from "noreply@ci.openmoq.org" \
104-
--destination '{"ToAddresses":["github-notifications@openmoq.org"]}' \
105-
--message "{
106-
\"Subject\": {\"Data\": \"$SUBJECT\"},
107-
\"Body\": {\"Text\": {\"Data\": \"$BODY\"}}
108-
}"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: notify ci failure
2+
3+
# Fires after the build workflow completes — invisible to PR checks.
4+
# Push-to-main failures are handled by the publish release workflow.
5+
6+
on:
7+
workflow_run:
8+
workflows: ["build"]
9+
types: [completed]
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
notify:
16+
if: |
17+
github.event.workflow_run.conclusion == 'failure' &&
18+
github.event.workflow_run.event == 'pull_request'
19+
runs-on: ubuntu-22.04
20+
steps:
21+
- name: Notify Slack (first failure only)
22+
continue-on-error: true
23+
env:
24+
GH_TOKEN: ${{ github.token }}
25+
SLACK_WEBHOOK_URL: ${{ secrets.OMOQ_SLACK_WEBHOOK_URL }}
26+
run: |
27+
BRANCH="${{ github.event.workflow_run.head_branch }}"
28+
RUN_URL="${{ github.event.workflow_run.html_url }}"
29+
PR_NUMBER=$(echo '${{ toJSON(github.event.workflow_run.pull_requests) }}' | jq -r '.[0].number // empty')
30+
PR_URL="${{ github.server_url }}/${{ github.repository }}/pull/${PR_NUMBER}"
31+
32+
# First-failure-only: skip if previous run on this branch also failed
33+
PREV=$(gh api \
34+
"repos/${{ github.repository }}/actions/workflows/ci.yml/runs?branch=${BRANCH}&event=pull_request&per_page=2" \
35+
--jq '.workflow_runs[1].conclusion // "none"' 2>/dev/null) || PREV="none"
36+
if [ "$PREV" = "failure" ]; then
37+
echo "Previous run also failed — skipping"
38+
exit 0
39+
fi
40+
41+
TEXT=":x: *${{ github.repository }}* \`${BRANCH}\` failed — <${PR_URL}|PR #${PR_NUMBER}> · <${RUN_URL}|run> · <${PR_URL}/checks|tests>"
42+
curl -s -X POST "$SLACK_WEBHOOK_URL" \
43+
-H "Content-Type: application/json" \
44+
--data "{\"text\": \"${TEXT}\"}"

0 commit comments

Comments
 (0)