Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 90 additions & 10 deletions .github/workflows/dependabot-failure-watcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,77 @@ name: Dependabot Failure Watcher

# Dependabot version updates run as GitHub Actions workflow runs named
# "Dependabot Updates". This scheduled job looks back over the past week for any
# of those runs that failed and fails itself if it finds one, so a silently-broken
# ecosystem surfaces as a red scheduled run instead of only a red triangle in the
# Dependabot tab that nobody checks.
# version-update run that failed and fails itself if it finds one, so a
# silently-broken ecosystem surfaces as a red scheduled run instead of only a red
# triangle in the Dependabot tab that nobody checks. Security-update runs share
# that workflow name and are deliberately excluded -- see below.
#
# GitHub reuses the "Dependabot Updates" name for three different kinds of run:
#
# 1. A version update's scheduled scan: one run per .github/dependabot.yml
# entry, on the schedule set there. It works out what is out of date and
# opens or updates pull requests. This is the kind this watcher primarily
# exists to catch -- when a scan breaks, the whole ecosystem quietly stops
# being updated and nothing else tells anyone.
# 2. A version update's per-pull-request refresh: one run per already-open
# Dependabot pull request, rebasing or re-checking it. These are not driven
# by the schedule at all -- a push to the base branch, a rebase, or an
# "@dependabot recreate" comment triggers them, so they arrive in bursts
# after merges rather than at the scheduled time. A failure here means one
# open pull request has gone stale, which is worth knowing but is much
# narrower than a broken scan.
# 3. A security update: one ad-hoc job per vulnerable package, triggered by a
# Dependabot alert rather than by dependabot.yml at all.
#
# Kind 3 routinely fails for reasons no pull request can fix: the advisory is
# against a dependency this project does not declare directly, or no patched
# version is reachable. Counting those would keep this workflow permanently red
# and train everyone to ignore it, so they are filtered out below.
#
# Of the fields "gh run list --json" exposes, only the title separates the three
# -- event, headBranch and actor are identical. Titles come in these shapes:
#
# - "<eco> in /." -- kind 1 at the repo root, which
# has no " for " suffix
# - "<eco> in <configured-dir>" -- kind 1 elsewhere, path verbatim
# - "<eco> in / for <deps>" -- kind 2 at the repo root
# - "<eco> in <configured-dir> for <deps>" -- kind 2 elsewhere
# - "<eco> in /. for <one-dep>" -- kind 3 at the repo root
# - "<eco> in <manifest-dir> for <one-dep>" -- kind 3 elsewhere, where
# <manifest-dir> is wherever the vulnerable manifest was discovered
#
# At the root, then, kind 3 is marked by "/." AND a " for " suffix together, and
# BOTH HALVES of " in /. for " are load-bearing -- do not shorten it. Matching on
# " in /." alone would also discard every kind 1 run, which is most of the runs
# here and the shape both failures this watcher was written for actually took.
#
# Outside the root, kinds 2 and 3 cannot be told apart by title, so the filter
# has to name directories instead. e2e/js and e2e/ts (in the Node repos this
# workflow is shared with) are consumer smoke tests carrying committed
# lockfiles, so their transitive dev dependencies attract advisories that no
# pull request can fix, and nothing in them is shipped code.
#
# Be clear about the cost, because it is not zero: both Node repos configure npm
# with directories: ["/", "**/*"], and that glob does match e2e/js and e2e/ts,
# so those directories DO get version updates. Dropping the pattern therefore
# discards their kind 2 failures as well as their kind 3 ones -- there is an
# open version-update pull request under e2e/ts in both repos as this is
# written. The npm ecosystem label does not rescue the distinction either:
# Dependabot writes "npm_and_yarn" for both kinds, so "npm_and_yarn in /e2e/ts
# for js-yaml" could be either a security job or the refresh of a
# version-update pull request.
#
# Accepted deliberately anyway. Kind 1 is what this watcher primarily exists to
# catch and is still reported for those directories, so what is given up is the
# narrower "one open pull request has gone stale" signal, for two directories of
# test scaffolding, in exchange for dropping 16 unactionable failures in each of
# the two Node repos over retained history.
#
# Reading the directories out of dependabot.yml instead looks more general but is
# worse: entries may use globs (directories: ["**/*"]), which never match a title
# literally, so genuine failures would be dropped without a word. Prefer a
# denylist: when it goes stale it re-introduces noise, which is loud, whereas a
# stale allowlist hides failures, which is silent.
#
# Runs entirely within this repo (no external service). A failed scheduled run
# emails the person who last edited the cron below. Note: GitHub auto-disables
Expand All @@ -22,22 +90,34 @@ jobs:
check-dependabot-runs:
runs-on: ubuntu-latest
steps:
- name: Fail if any Dependabot update failed in the last 8 days
- name: Fail if any Dependabot version update failed in the last 8 days
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
run: |
since=$(date -u -d '8 days ago' +%Y-%m-%dT%H:%M:%SZ)
failures=$(gh run list \
# --created filters server-side, so --limit applies to runs already
# narrowed to the window rather than to all of history. Runs come back
# newest-first, so reaching the limit would drop the oldest in-window
# runs and this step would report all-clear without them -- hence a
# limit far above any plausible week's worth of runs.
runs=$(gh run list \
--repo "$REPO" \
--workflow "Dependabot Updates" \
--limit 100 \
--json conclusion,createdAt,displayTitle,url \
--jq "[.[] | select((.conclusion == \"failure\" or .conclusion == \"startup_failure\" or .conclusion == \"timed_out\") and .createdAt >= \"$since\")]")
--created ">=$since" \
--limit 500 \
--json conclusion,createdAt,displayTitle,url)
Comment on lines +99 to +109

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

repo="${1:?usage: $0 OWNER/REPO}"
since="$(date -u -d '8 days ago' +%Y-%m-%dT%H:%M:%SZ)"

workflow_id="$(
  gh api --paginate --slurp "repos/$repo/actions/workflows?per_page=100" |
    jq -r '[.[] | .workflows[] | select(.name == "Dependabot Updates") | .id] | first // empty'
)"

count="$(
  gh api --paginate --slurp \
    "repos/$repo/actions/workflows/$workflow_id/runs?created=>=$since&exclude_pull_requests=true&per_page=100" |
    jq '[.[] | .workflow_runs[]] | length'
)"

echo "Runs in window: $count"
test "$count" -le 500

Repository: maxmind/ipfeed-draft

Length of output: 198


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "tracked workflow:"
git ls-files .github/workflows | grep -F 'dependabot-failure-watcher.yml' || true

echo
echo "relevant workflow excerpt:"
wc -l .github/workflows/dependabot-failure-watcher.yml
sed -n '1,180p' .github/workflows/dependabot-failure-watcher.yml | cat -n

echo
echo "github cli availability/version:"
(gh --version 2>&1 || true)

echo
echo "github CLI help snippets for run list workflow/created/limit:"
(gh run list --help | sed -n '/Workflow run/,/2>/p' || true)

Repository: maxmind/ipfeed-draft

Length of output: 7270


🌐 Web query:

GitHub REST API list workflow runs created parameter per_page default 25 limit 1000

💡 Result:

For the GitHub REST API "List workflow runs" endpoints, the per_page parameter has a default value of 30, with a maximum allowed value of 100 per page [1][2][3]. While you can retrieve up to 1,000 total results when using specific filtering parameters (such as created, actor, or status), this limit applies to the total number of results accessible via pagination, not the per_page parameter itself [1][2][3]. To retrieve more than the per_page limit in a single request, you must iterate through subsequent pages using the Link header provided in the API response [4].

Citations:


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "gh run list help:"
(gh run list --help | sed -n '/usage:/,/Options:/p' || true)

echo
echo "search for gh CLI invocation semantics around --limit/per-page:"
rg -n "run list|--limit|per page|workflow_runs|Workflow runs|created" --glob '*.md' . || true

echo
echo "repository workflow run counts in the default 8-day window:"
repo="$(gh repo view --json nameWithOwner -q .nameWithOwner 2>/dev/null || true)"
if [ -z "$repo" ]; then
  echo "could not identify repository"
  exit 0
fi
echo "repo=$repo"

workflow_id="$(
  gh api --paginate --slurp "repos/$repo/actions/workflows?per_page=100" |
    jq -r '[.[] | select(.name == "Dependabot Updates")] | .[0].id // empty'
)"
if [ -z "$workflow_id" ]; then
  echo "Dependabot Updates workflow id not found"
fi

since="$(date -u -d '8 days ago' +%Y-%m-%dT%H:%M:%SZ)"
echo "since=$since"
echo "workflow_id=$workflow_id"

# Use pagination explicitly; per_page max is 100 for this endpoint.
total=0
first_count=0
latest=$(gh api "repos/$repo/actions/workflows/$workflow_id/runs?per_page=1&created=$since" 2>/dev/null | jq '.workflow_runs[0].id // empty' || true)
latest_name=$(gh api "repos/$repo/actions/workflows/$workflow_id/runs?per_page=1&created=$since" 2>/dev/null | jq '.workflow_runs[0].display_title // empty' || true)
for page in $(seq 1 12); do
  page_runs="$(
    gh api \
      "repos/$repo/actions/workflows/$workflow_id/runs?perPage=100&created=$since&page=$page" \
      2>/dev/null | jq '.workflow_runs | length'
  )" || break
  [ -n "$page_runs" ] || break
  total=$((total + page_runs))
  [ $page -eq 1 ] && first_count=$page_runs
  [ "$page_runs" -lt 100 ] && break
done

echo "first_page_runs=$first_count"
echo "paginated_total_window_runs=$total"
echo "latest_id=$latest"
echo "latest_display_title=$latest_name"

# Simulate current gh limit behavior under a 100-per-request assumption and
# identify which failed in-window runs would be dropped with current/recommended limits.
python3 - <<'PY' "$workflow_id" "$since" "$total" "$first_count" "$latest"
import json, sys
# This probe only uses the counts fetched from the public API; it does not execute repo code.
workflow_id, since, total, first_count, latest = sys.argv[1:5]
print("probe_total", total)
print("dropped_above_current_500", max(0, total - 500))
print("dropped_above_suggested_1000", max(0, total - 1000))
PY

Repository: maxmind/ipfeed-draft

Length of output: 661


Fail closed when the run scan is truncated.

Reaching the --limit discards older in-window runs because results are newest-first, but the script still exits successfully. Paginate through the action runs API and mark this window as truncated/failed, or keep the limit at the maximum supported window size and fail closed when truncated.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/dependabot-failure-watcher.yml around lines 88 - 98, The
run scan in the workflow currently treats the fixed --limit 500 result as
complete even when older in-window runs are omitted. Update the run-listing
logic around the runs command to paginate through all matching action runs, or
detect that the configured limit was reached and mark the scan as truncated so
the workflow fails closed instead of reporting all-clear.

failures=$(echo "$runs" | jq '
[.[]
| select((.displayTitle | contains(" in /. for ")) | not)
| select((.displayTitle | test(" in /e2e/(js|ts) for ")) | not)
| select(.conclusion == "failure"
or .conclusion == "startup_failure"
or .conclusion == "timed_out")]')
count=$(echo "$failures" | jq 'length')
if [ "$count" -gt 0 ]; then
echo "::error::$count failed Dependabot update run(s) in the last 8 days:"
echo "::error::$count failed Dependabot version update run(s) in the last 8 days:"
echo "$failures" | jq -r '.[] | "- \(.displayTitle) (\(.createdAt))\n \(.url)"'
exit 1
fi
echo "No failed Dependabot update runs in the last 8 days."
echo "No failed Dependabot version update runs in the last 8 days."