-
Notifications
You must be signed in to change notification settings - Fork 84
CI status watch #2091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
CI status watch #2091
Changes from all commits
18f2678
d27c73a
862b485
60bfafb
70434a8
0d36b2d
a613459
f05d69d
163bc41
980739c
a9080ce
67999a2
ce0c647
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,87 @@ | ||||||
| name: CI status watch | ||||||
|
|
||||||
| # Posts a Teams message listing the README badge workflows that are currently red on the | ||||||
| # default branch. A workflow stays in the list until it is green again, so the reminder | ||||||
| # repeats every weekday morning until somebody fixes it. Creates no issues, read-only. | ||||||
| # Requires the repository secret TEAMS_WEBHOOK_URL. | ||||||
|
|
||||||
| on: | ||||||
| workflow_dispatch: | ||||||
| schedule: | ||||||
| - cron: '0 7 * * 1-5' # 07:00 UTC, Mon-Fri (= 09:00 CEST / 08:00 CET) | ||||||
|
|
||||||
| permissions: | ||||||
| actions: read | ||||||
|
|
||||||
| jobs: | ||||||
| watch: | ||||||
| runs-on: ubuntu-latest | ||||||
| env: | ||||||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||||
| WEBHOOK: ${{ secrets.TEAMS_WEBHOOK_URL }} | ||||||
| REPO: ${{ github.repository }} | ||||||
| BRANCH: ${{ github.ref_name }} | ||||||
| steps: | ||||||
| - name: Detect newly red badge workflows and notify Teams | ||||||
| run: | | ||||||
| set -euo pipefail | ||||||
|
|
||||||
| # The workflows backing the README badges. Add a line here if a badge is added. | ||||||
| WORKFLOWS=" | ||||||
| .github/workflows/build.yml | ||||||
| .github/workflows/update-urls.yml | ||||||
| .github/workflows/nightly-build.yml | ||||||
| .github/workflows/integration-tests.yml | ||||||
| " | ||||||
|
|
||||||
| echo "Checking badge workflows on branch $BRANCH" | ||||||
|
|
||||||
| # A workflow counts as red if its newest completed run that produced a real result | ||||||
| # failed; cancelled/skipped runs say nothing about the code and are ignored. This is | ||||||
| # exactly what the README badge shows. There is no look-back window on purpose: as | ||||||
| # long as it stays red it is reported every morning, so nobody can miss it. | ||||||
| RED=$(for WF_PATH in $WORKFLOWS; do | ||||||
| gh run list --repo "$REPO" --workflow "$WF_PATH" --branch "$BRANCH" \ | ||||||
| --status completed --limit 5 --json conclusion,url,updatedAt,workflowName \ | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you increased the limit from 2 to 5. However, we only take the first result
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Real streaks on It is also free: That it reads the other way means the line needs a comment. A suggestion in this thread would only replace this line, so I put it on the comment block above (lines 39 to 42) as a separate comment. |
||||||
| --jq '[ .[] | select(.conclusion != "cancelled" and .conclusion != "skipped") ][0] | ||||||
| | select(. != null) | ||||||
| | select(.conclusion == "failure" or .conclusion == "timed_out" or .conclusion == "startup_failure") | ||||||
| | {name: .workflowName, url: .url, since: .updatedAt}' || true | ||||||
| done | jq -s '.') | ||||||
|
|
||||||
| COUNT=$(echo "$RED" | jq 'length') | ||||||
| if [ "$COUNT" -eq 0 ]; then | ||||||
| echo "No badge workflow is red. Skipping Teams notification." | ||||||
| exit 0 | ||||||
| fi | ||||||
| echo "$COUNT badge workflow(s) currently red." | ||||||
|
|
||||||
| if [ -z "${WEBHOOK:-}" ]; then | ||||||
| echo "No Teams webhook set, skipping notification."; exit 0 | ||||||
| fi | ||||||
|
|
||||||
| CARD=$(echo "$RED" | jq --argjson count "$COUNT" '{ | ||||||
| type: "AdaptiveCard", | ||||||
| "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", | ||||||
| version: "1.4", | ||||||
| body: ( | ||||||
| [ | ||||||
| { type: "TextBlock", size: "Large", weight: "Bolder", wrap: true, color: "attention", | ||||||
| text: "🔴 CI ist rot" }, | ||||||
| { type: "TextBlock", spacing: "None", isSubtle: true, wrap: true, | ||||||
| text: (if $count == 1 then "1 Workflow ist rot" else "\($count) Workflows sind rot" end) } | ||||||
| ] | ||||||
| + [ .[] | { | ||||||
| type: "Container", | ||||||
| separator: true, | ||||||
| spacing: "Medium", | ||||||
| items: [ | ||||||
| { type: "TextBlock", weight: "Bolder", wrap: true, text: "🔴 \(.name)" }, | ||||||
| { type: "TextBlock", spacing: "None", isSubtle: true, size: "Small", wrap: true, | ||||||
| text: "rot seit \(.since) · [Run-Log öffnen](\(.url))" } | ||||||
| ] | ||||||
| } ] | ||||||
| ) | ||||||
| }') | ||||||
|
|
||||||
| curl -sS --fail -X POST -H "Content-Type: application/json" -d "$CARD" "$WEBHOOK" | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow-up to the
--limitthread: documenting why the limit is what it is, so the next reader does not read it as dead weight either.