Skip to content

Commit 34cc63c

Browse files
committed
Post CI health reports to Slack
1 parent bee3e3c commit 34cc63c

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

.github/workflows/reports.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,31 @@ jobs:
4747
if: always()
4848
run: |
4949
docker logs trino
50+
- name: Generate Slack message
51+
id: message
52+
run: |
53+
for name in health failing-jobs; do
54+
output=$(docker exec trino \
55+
java -Dorg.jline.terminal.dumb=true -jar /usr/bin/trino \
56+
trino://localhost:8080/trinocicd/v2 \
57+
-f /sql/cic-cd/$name.sql \
58+
--output-format=MARKDOWN)
59+
echo "$name=$output\n" >> $GITHUB_OUTPUT
60+
done
61+
- name: Post to a Slack channel
62+
id: slack
63+
uses: slackapi/[email protected]
64+
with:
65+
channel-id: 'core-dev'
66+
slack-message: |
67+
CI Health:
68+
```
69+
${{ steps.message.outputs.health }}
70+
```
71+
72+
Failing jobs:
73+
```
74+
${{ steps.message.outputs.failing-jobs }}
75+
```
76+
env:
77+
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

sql/ci-cd/failing-jobs.sql

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
-- Recently failing jobs
22
-- Lists failed jobs on master branch in last 24h
3+
WITH
4+
-- bar() function renders colored output, and uses one character rendering (boxes), so has less precision within same width
5+
FUNCTION ascii_bar(value double)
6+
RETURNS varchar
7+
DETERMINISTIC
8+
BEGIN
9+
DECLARE max_width double DEFAULT 20;
10+
DECLARE clamped_value double;
11+
SET clamped_value = greatest(0, least(1, value));
12+
RETURN array_join(
13+
repeat('',
14+
greatest(0, CAST(floor(max_width * clamped_value) AS integer) - 1)), '')
15+
|| ARRAY[' ', '', '', '', '', '', '', '', ''][cast((clamped_value % (1e0 / max_width)) * max_width * 8 + 1 as int)];
16+
END
317
WITH
418
recent_master_runs AS (
519
SELECT
@@ -34,7 +48,7 @@ recent_master_runs AS (
3448

3549
SELECT
3650
name AS "Job name"
37-
, bar(1e0 * num_failed_runs / (SELECT count(*) FROM recent_master_runs), 20, rgb(0, 155, 0), rgb(255, 0, 0)) AS "Failure ratio chart"
51+
, ascii_bar(1e0 * num_failed_runs / (SELECT count(*) FROM recent_master_runs)) AS "Failure ratio chart"
3852
, round(100e0 * num_failed_runs / (SELECT count(*) FROM recent_master_runs), 1) AS "Failure percent"
3953
, num_failed_runs AS "Number of failed runs"
4054
, errors AS "Error messages"

sql/ci-cd/health.sql

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
-- CI workflow health
2+
WITH
3+
-- bar() function renders colored output, and uses one character rendering (boxes), so has less precision within same width
4+
FUNCTION ascii_bar(value double)
5+
RETURNS varchar
6+
DETERMINISTIC
7+
BEGIN
8+
DECLARE max_width double DEFAULT 20;
9+
DECLARE clamped_value double;
10+
SET clamped_value = greatest(0, least(1, value));
11+
RETURN array_join(
12+
repeat('',
13+
greatest(0, CAST(floor(max_width * clamped_value) AS integer) - 1)), '')
14+
|| ARRAY[' ', '', '', '', '', '', '', '', ''][cast((clamped_value % (1e0 / max_width)) * max_width * 8 + 1 as int)];
15+
END
216
WITH
317
runs AS (
418
SELECT
@@ -22,11 +36,11 @@ runs AS (
2236
SELECT
2337
branch AS "Branch"
2438
, intervals.label AS "Interval"
25-
, bar(1e0 * count(1) FILTER (WHERE conclusion = 'success') / count(1), 20, rgb(255, 0, 0), rgb(0, 155, 0)) AS "Success ratio chart"
39+
, ascii_bar(1e0 * count(1) FILTER (WHERE conclusion = 'success') / count(1)) AS "Success ratio chart"
2640
, round(100e0 * count(1) FILTER (WHERE conclusion = 'success') / count(1), 1) AS "Success percent"
2741
, count(1) FILTER (WHERE created_at > now() - intervals.days) AS "Number of runs"
2842
FROM intervals
2943
JOIN runs ON runs.created_at > now() - intervals.days
3044
GROUP BY branch, intervals.days, intervals.label
31-
ORDER BY 1 DESC, intervals.days
45+
ORDER BY branch DESC, intervals.days
3246
;

0 commit comments

Comments
 (0)