Skip to content

Commit 18d7144

Browse files
authored
ci: daily dependabot critical-severity slack alerts (#3701)
Sibling to the weekly summary, focused on critical alerts only. Pings Slack daily while any critical alerts are open; skips the post entirely when zero, so no daily "all clear" noise. - Daily 08:00 UTC cron + `workflow_dispatch` with `severity` input (default `critical`, override to `high`/`medium`/`low` for manual checks) - Reuses the existing `dependabot-summary` environment (token, channel, bot) - Alerts link at the end is severity-filtered
1 parent c0b9fdf commit 18d7144

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Dependabot Critical Alerts
2+
3+
on:
4+
schedule:
5+
- cron: "0 8 * * *" # Daily 08:00 UTC
6+
workflow_dispatch:
7+
inputs:
8+
severity:
9+
description: "Severity to alert on"
10+
type: choice
11+
options:
12+
- critical
13+
- high
14+
- medium
15+
- low
16+
default: critical
17+
18+
concurrency:
19+
group: ${{ github.workflow }}
20+
cancel-in-progress: false
21+
22+
permissions:
23+
contents: read
24+
25+
jobs:
26+
alert:
27+
name: Post critical alerts
28+
runs-on: ubuntu-latest
29+
environment: dependabot-summary
30+
env:
31+
SEVERITY: ${{ inputs.severity || 'critical' }}
32+
steps:
33+
- name: Fetch alerts
34+
id: alerts
35+
env:
36+
GH_TOKEN: ${{ secrets.DEPENDABOT_ALERTS_TOKEN }}
37+
REPO: ${{ github.repository }}
38+
run: |
39+
set -euo pipefail
40+
gh api -X GET "/repos/$REPO/dependabot/alerts" \
41+
-F state=open -F severity="$SEVERITY" --paginate > pages.json
42+
jq -s 'add' pages.json > alerts.json
43+
TOTAL=$(jq 'length' alerts.json)
44+
echo "total=$TOTAL" >> "$GITHUB_OUTPUT"
45+
if [ "$TOTAL" = "0" ]; then
46+
exit 0
47+
fi
48+
LIST=$(jq -r '
49+
map("• <\(.html_url)|#\(.number)> *\(.dependency.package.name)* - \(.security_advisory.summary)")
50+
| join("\n")
51+
' alerts.json)
52+
{
53+
echo "list<<EOF"
54+
echo "$LIST"
55+
echo "EOF"
56+
} >> "$GITHUB_OUTPUT"
57+
58+
- name: Build Slack payload
59+
if: steps.alerts.outputs.total != '0'
60+
env:
61+
REPO: ${{ github.repository }}
62+
CHANNEL: ${{ vars.SLACK_CHANNEL_ID }}
63+
TOTAL: ${{ steps.alerts.outputs.total }}
64+
LIST: ${{ steps.alerts.outputs.list }}
65+
run: |
66+
jq -n \
67+
--arg channel "$CHANNEL" \
68+
--arg repo "$REPO" \
69+
--arg total "$TOTAL" \
70+
--arg list "$LIST" \
71+
--arg severity "$SEVERITY" \
72+
'{
73+
channel: $channel,
74+
text: ":bufo-alarma: `\($repo)` - *\($total) open \($severity) alert(s)*\n\($list)\n\n<https://github.com/\($repo)/security/dependabot?q=is%3Aopen+severity%3A\($severity)|View \($severity) alerts>"
75+
}' > payload.json
76+
77+
- name: Post Slack alert
78+
if: steps.alerts.outputs.total != '0'
79+
uses: slackapi/slack-github-action@45a88b9581bfab2566dc881e2cd66d334e621e2c # v3.0.3
80+
with:
81+
method: chat.postMessage
82+
token: ${{ secrets.SLACK_BOT_TOKEN }}
83+
payload-file-path: payload.json

0 commit comments

Comments
 (0)