-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
ci: add dependabot weekly summary workflow #3616
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ce74771
ci: add dependabot weekly summary workflow
nicktrn 82b82f3
fix(ci): handle null run id and json-encode slack payload
nicktrn 54f48e1
fix(ci): use real newlines so slack renders line breaks
nicktrn a53192c
Merge branch 'main' into ci/dependabot-weekly-summary
nicktrn 41083a0
ci(dependabot-summary): make action threshold configurable
nicktrn ff57d2b
ci(dependabot-summary): handle repos without a Dependabot Updates wor…
nicktrn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| name: Dependabot Weekly Summary | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: "0 8 * * 1" # Mon 08:00 UTC | ||
| workflow_dispatch: | ||
|
|
||
| # Single-purpose monitoring workflow; serialise on workflow name only - we never | ||
| # want two concurrent summary runs racing to post the same digest. | ||
| concurrency: | ||
| group: ${{ github.workflow }} | ||
| cancel-in-progress: false | ||
|
|
||
| permissions: | ||
| contents: read # gh CLI baseline | ||
| pull-requests: read # gh pr list (open dependabot PRs) | ||
| actions: read # gh run list / view (parse latest dependabot run logs) | ||
|
|
||
| jobs: | ||
| summary: | ||
| name: Post weekly Dependabot summary | ||
| runs-on: ubuntu-latest | ||
| environment: dependabot-summary | ||
| steps: | ||
| - name: Fetch alerts and compute summaries | ||
| id: alerts | ||
| env: | ||
| GH_TOKEN: ${{ secrets.DEPENDABOT_ALERTS_TOKEN }} | ||
| REPO: ${{ github.repository }} | ||
| run: | | ||
| if ! gh api -X GET "/repos/$REPO/dependabot/alerts" --paginate > pages.json 2> err.txt; then | ||
| echo "total=?" >> "$GITHUB_OUTPUT" | ||
| ERR=$(head -c 200 err.txt | tr '\n' ' ') | ||
| echo "by_severity=:x: _failed to fetch alerts: ${ERR}_" >> "$GITHUB_OUTPUT" | ||
| echo "actions=:x: _alerts unavailable_" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
| jq -s '[.[][] | select(.state == "open")]' pages.json > open.json | ||
|
|
||
| TOTAL=$(jq 'length' open.json) | ||
| echo "total=$TOTAL" >> "$GITHUB_OUTPUT" | ||
|
|
||
| if [ "$TOTAL" = "0" ]; then | ||
| echo "by_severity=:white_check_mark: No open alerts." >> "$GITHUB_OUTPUT" | ||
| echo "actions=_None_" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Severity breakdown - single-line output with \n escapes for JSON safety | ||
| BY_SEV=$(jq -r ' | ||
| group_by(.security_advisory.severity) | ||
| | map({sev: .[0].security_advisory.severity, | ||
| count: length, | ||
| weight: ({"critical":0,"high":1,"medium":2,"low":3}[.[0].security_advisory.severity])}) | ||
| | sort_by(.weight) | ||
| | map("• *\(.count)* \(.sev)") | ||
| | join("\\n") | ||
| ' open.json) | ||
|
nicktrn marked this conversation as resolved.
|
||
| echo "by_severity=$BY_SEV" >> "$GITHUB_OUTPUT" | ||
|
|
||
| # Actions: alerts with <7d to TTR (P0=7d, P1=30d, P2=90d, P3=no deadline) | ||
| # Grouped by (package, severity); shows earliest deadline per group. | ||
| ACTIONS=$(jq -r ' | ||
| [.[] | ||
| | (.security_advisory.severity) as $sev | ||
| | ({"critical":7,"high":30,"medium":90,"low":null}[$sev]) as $ttr | ||
| | select($ttr != null) | ||
| | ((now - (.created_at | fromdateiso8601)) / 86400 | floor) as $age | ||
| | {pkg: .dependency.package.name, sev: $sev, remaining: ($ttr - $age)} | ||
| ] | ||
| | group_by([.pkg, .sev]) | ||
| | map({pkg: .[0].pkg, sev: .[0].sev, count: length, min_remaining: ([.[].remaining] | min)}) | ||
| | map(select(.min_remaining < 7)) | ||
| | sort_by(.min_remaining) | ||
| | if length == 0 then "_None_" | ||
| else (map( | ||
| "• *\(.pkg)* (\(.sev))" + | ||
| (if .count > 1 then " ×\(.count)" else "" end) + " - " + | ||
| (if .min_remaining < 0 then "*OVERDUE* by \(-.min_remaining)d" | ||
| else "\(.min_remaining)d remaining" end) | ||
| ) | join("\\n")) | ||
| end | ||
| ' open.json) | ||
| echo "actions=$ACTIONS" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Fetch open dependabot PRs | ||
| id: prs | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| REPO: ${{ github.repository }} | ||
| REPO_URL: https://github.com/${{ github.repository }} | ||
| run: | | ||
| if ! PR_JSON=$(gh pr list --repo "$REPO" --state open --author "app/dependabot" --json number,title 2> err.txt); then | ||
| ERR=$(head -c 200 err.txt | tr '\n' ' ') | ||
| echo "list=:x: _failed to fetch PRs: ${ERR}_" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
| LIST=$(echo "$PR_JSON" | jq -r --arg url "$REPO_URL" ' | ||
| if length == 0 then "_None_" | ||
| else (map("• <\($url)/pull/\(.number)|#\(.number)> \(.title)") | join("\\n")) | ||
| end | ||
| ') | ||
| echo "list=$LIST" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Find latest npm dependabot run | ||
| id: latest | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| REPO: ${{ github.repository }} | ||
| run: | | ||
| RUN_ID=$(gh run list --repo "$REPO" --workflow "Dependabot Updates" --status success --limit 30 --json databaseId,name --jq '[.[] | select(.name | startswith("npm_and_yarn"))][0].databaseId') | ||
| echo "run_id=$RUN_ID" >> "$GITHUB_OUTPUT" | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| - name: Extract stuck deps (only if actions pending) | ||
| id: stuck | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| REPO: ${{ github.repository }} | ||
| RUN_ID: ${{ steps.latest.outputs.run_id }} | ||
| ACTIONS: ${{ steps.alerts.outputs.actions }} | ||
| run: | | ||
| # Skip the stuck section entirely when nothing in the actions list | ||
| # - keeps the digest tidy when there's nothing to actually act on. | ||
| if [ "$ACTIONS" = "_None_" ]; then | ||
| echo "section=" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|
nicktrn marked this conversation as resolved.
|
||
| HEADER="\\n\\n*Couldn't auto-fix (need manual \`pnpm.overrides\`):*\\n" | ||
| if [ -z "$RUN_ID" ]; then | ||
| echo "section=${HEADER}_(no recent npm run found)_" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
| gh run view "$RUN_ID" --repo "$REPO" --log > log.txt 2>&1 || true | ||
| STUCK=$(grep -oE "No update possible for [^[:space:]]+ [0-9][^[:space:]]*" log.txt | sed 's/No update possible for //' | sort -u || true) | ||
| if [ -z "$STUCK" ]; then | ||
| echo "section=${HEADER}_None_" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
| LIST=$(echo "$STUCK" | awk 'NR>1{printf "\\n"} {printf "• *%s* %s", $1, $2}') | ||
| echo "section=${HEADER}${LIST}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Post Slack summary | ||
| uses: slackapi/slack-github-action@45a88b9581bfab2566dc881e2cd66d334e621e2c # v3.0.3 | ||
| with: | ||
| method: chat.postMessage | ||
| token: ${{ secrets.SLACK_BOT_TOKEN }} | ||
| payload: | | ||
| { | ||
| "channel": "${{ vars.SLACK_CHANNEL_ID }}", | ||
| "text": ":calendar: *Weekly Dependabot summary* - `${{ github.repository }}`\n\n*Open alerts (${{ steps.alerts.outputs.total }}):*\n${{ steps.alerts.outputs.by_severity }}\n\n*Open Dependabot PRs:*\n${{ steps.prs.outputs.list }}\n\n*Actions needed (<7d remaining):*\n${{ steps.alerts.outputs.actions }}${{ steps.stuck.outputs.section }}\n\n<https://github.com/${{ github.repository }}/security/dependabot|Dependabot alerts>" | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
devin-ai-integration[bot] marked this conversation as resolved.
Outdated
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.