summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2023-04-07 16:37:06 +1000
committerGitHub <noreply@github.com>2023-04-07 16:37:06 +1000
commit2e766a9c7a0888a96ed9108f09a085f4298af0b3 (patch)
treed86e18bb456c656a2578b9afa98fa11fe4109de3
parent4ba3fdfad2bd52e2807d18606db1c12192304fd5 (diff)
Add Discord webhook at end of each CI run. (#20355)
-rw-r--r--.github/workflows/ci_builds.yml12
-rwxr-xr-xlib/python/qmk/cli/format/python.py2
-rwxr-xr-xutil/ci/discord-results.py49
-rw-r--r--util/ci/requirements.txt1
4 files changed, 61 insertions, 3 deletions
diff --git a/.github/workflows/ci_builds.yml b/.github/workflows/ci_builds.yml
index ce2d0b509e..366b5e0dde 100644
--- a/.github/workflows/ci_builds.yml
+++ b/.github/workflows/ci_builds.yml
@@ -10,12 +10,11 @@ on:
jobs:
ci_builds:
+ if: github.repository == 'qmk/qmk_firmware'
name: "CI Build"
runs-on: self-hosted
timeout-minutes: 1380
- if: github.repository == 'qmk/qmk_firmware'
-
strategy:
fail-fast: false
matrix:
@@ -58,3 +57,12 @@ jobs:
*.hex
*.uf2
.build/failed.*
+
+ - name: 'CI Discord Notification'
+ if: always()
+ working-directory: util/ci/
+ env:
+ DISCORD_WEBHOOK: ${{ secrets.CI_DISCORD_WEBHOOK }}
+ run: |
+ python3 -m pip install -r requirements.txt
+ python3 ./discord-results.py --branch ${{ matrix.branch }} --keymap ${{ matrix.keymap }} --url ${{ env.GITHUB_SERVER_URL }}/${{ env.GITHUB_REPOSITORY }}/actions/runs/${{ env.GITHUB_RUN_ID }}
diff --git a/lib/python/qmk/cli/format/python.py b/lib/python/qmk/cli/format/python.py
index 008622cac1..e7b545109f 100755
--- a/lib/python/qmk/cli/format/python.py
+++ b/lib/python/qmk/cli/format/python.py
@@ -7,7 +7,7 @@ from milc import cli
from qmk.path import normpath
py_file_suffixes = ('py',)
-py_dirs = ['lib/python']
+py_dirs = ['lib/python', 'util/ci']
def yapf_run(files):
diff --git a/util/ci/discord-results.py b/util/ci/discord-results.py
new file mode 100755
index 0000000000..0c09a4213a
--- /dev/null
+++ b/util/ci/discord-results.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+
+import argparse
+import os
+import re
+import sys
+from pathlib import Path
+from discord_webhook import DiscordWebhook, DiscordEmbed
+
+parser = argparse.ArgumentParser(prog='discord-results.py', description='Sends a Discord webhook notification at the end of a CI run.')
+parser.add_argument('-b', '--branch')
+parser.add_argument('-k', '--keymap')
+parser.add_argument('-u', '--url')
+args = parser.parse_args()
+
+qmk_dir = Path(__file__).resolve().parents[2].resolve()
+
+keyboard_re = re.compile(r'CI Metadata: KEYBOARD=(.*)$', re.MULTILINE)
+keymap_re = re.compile(r'CI Metadata: KEYMAP=(.*)$', re.MULTILINE)
+
+successful_builds = sum([len(list(qmk_dir.glob(f'*.{extension}'))) for extension in ['uf2', 'bin', 'hex']])
+failures = list(sorted([f.resolve() for f in (qmk_dir / '.build/').glob('failed.log.*')]))
+failed_builds = []
+for f in failures:
+ with open(f) as fh:
+ data = fh.read()
+ kb = keyboard_re.search(data).group(1)
+ km = keymap_re.search(data).group(1)
+ failed_builds.append(f'{kb}:{km}')
+
+webhook = DiscordWebhook(url=os.getenv('DISCORD_WEBHOOK'), username="QMK GitHub CI")
+if len(failed_builds) > 0:
+ failstr = ''
+ for f in failed_builds:
+ if len(failstr) >= 1800:
+ failstr += '<<snip>>'
+ break
+ failstr += f'{f}\n'
+
+ embed = DiscordEmbed(title=f':infinity: CI Build Failure ({args.branch}, {args.keymap})', description=f'**{successful_builds}** builds succeeded, **{len(failed_builds)}** builds failed:```{failstr}```', color='ff9999')
+else:
+ embed = DiscordEmbed(title=f':infinity: CI Build Success ({args.branch}, {args.keymap})', description=f'**{successful_builds}** builds succeeded.', color='99ff99')
+
+embed.add_embed_field(name='Build Target', value=f'[**{args.branch}**](https://github.com/qmk/qmk_firmware/tree/{args.branch}) / **{args.keymap}** keymap')
+embed.add_embed_field(name='Workflow Run', value=f'[**Link**]({args.url})')
+embed.set_timestamp()
+
+webhook.add_embed(embed)
+webhook.execute()
diff --git a/util/ci/requirements.txt b/util/ci/requirements.txt
new file mode 100644
index 0000000000..3196568e1a
--- /dev/null
+++ b/util/ci/requirements.txt
@@ -0,0 +1 @@
+discord-webhook