ci: label merged Dependabot security updates for backport (#32806)

## Problem

Dependabot security fixes merged to `main` are never backported. None of
the 388 Dependabot PRs since #24484 got the `backport` label. Three
defects cause this:

1. `fetch-metadata` reads only the oldest 100 of the repo's 596 alerts,
so `alert-state` is always empty.
2. It compares versions in a format that doesn't match the alert data
(`= v0.4.0` for Go).
3. `dependabot.yaml` enables auto-merge with `GITHUB_TOKEN`, and a merge
made with that token starts no workflows. Even a labeled PR wouldn't
reach `backport.yaml`.

The label step also runs in a Dependabot `pull_request` run, which can't
use the `main` environment or a KMS App token (the signing pool requires
a protected ref). `pull_request_target` is not an option because it is
being removed before 2026-12-02.

## Fix

- `backport.yaml`, `detect` job: also run for merged Dependabot PRs that
aren't labeled yet. Get the backporter App token (environment `main`,
same KMS key as the `backport` job) and run
`.github/scripts/dependabot-alert-match.sh`. If the PR fixed an alert,
add `backport` with the App token. That `labeled` event runs the normal
backport. The script runs from the base branch and never checks out PR
code.
- `dependabot-alert-match.sh`: matches the PR's updated dependencies
against open or fixed alerts by package, by manifest among the PR's
changed files, and by the update crossing the alert's first patched
version (old < patched <= new). Paginates, and normalizes a leading `v`.
- `dependabot.yaml`: remove `fetch-metadata`, the label step that never
ran, and auto-merge. The job now only sends the Slack notice. **A person
now merges Dependabot PRs**, as they already approve them since #32303.

## Verification

- `bash .github/scripts/dependabot-alert-match.test.sh` passes.
- Replaying the script against the last 120 merged Dependabot PRs
matches 12. That includes dompurify #31213, next #31217, storybook
#31215 and #31216, axios #30239, and moby/sys/user #30534. It doesn't
match grpc #31954 or cel-go #31959, whose alerts were fixed earlier.

## Before merging

The App needs the "Dependabot alerts: read" permission first (ENT-263,
coder/github-org-terraform manifest PR). Until then the token step fails
for unlabeled Dependabot PRs. Runs for manually labeled PRs are
unaffected.

Known limits: a prerelease version compares by `sort -V`, and a grouped
PR's alerts are matched per dependency.

Tracked in ENT-245. Not in this PR: the audit of past fixes (ENT-270)
and a fallback for lockfile conflicts (ENT-271).

---------

Co-authored-by: Lisa Fiander <lisa@coder.com>
This commit is contained in:
Dmitry MakoveyandLisa Fiander authored and GitHub committed 2026-12-04 11:09:11 -07:00
1 parent 9a33a25f14
commit 4a60d186f8
4 files changed
+485 -56

No files matched your search

+135
View File
@@ -0,0 +1,135 @@
#!/usr/bin/env bash
# Reports whether a merged Dependabot PR fixed a Dependabot alert, so
# backport.yaml can label it for backport.
#
# A PR fixes an alert when, for one of its updated dependencies:
# - the alert is for the same package,
# - the alert's manifest is one of the files the PR changed, and
# - the update crossed the alert's first patched version: the old version is
# below it and the new version is at or above it.
#
# Open alerts count too, because GitHub may not have closed the alert yet when
# the PR merges. Comparing against the first patched version avoids parsing
# vulnerable version ranges. Requiring the old version to be below it skips
# alerts that were already fixed before the PR.
#
# Inputs (environment):
# PR_NUMBER the merged pull request
# REPO owner/name, defaults to GITHUB_REPOSITORY
# GH_TOKEN token that can read pull requests and Dependabot alerts
#
# Writes matched=true|false and alerts=<comma-separated alert numbers> to
# GITHUB_OUTPUT when it is set. Outside Actions it also prints the matched
# alerts. Tests: dependabot-alert-match.test.sh.
#
# To see which alerts a PR matched, run it locally. The Actions log is public
# and intentionally doesn't say. You need a gh token that can read Dependabot
# alerts:
# PR_NUMBER=<n> REPO=coder/coder bash .github/scripts/dependabot-alert-match.sh
set -euo pipefail
: "${PR_NUMBER:?PR_NUMBER is required}"
REPO="${REPO:-${GITHUB_REPOSITORY:?REPO or GITHUB_REPOSITORY is required}}"
# log_local_only MESSAGE: prints only outside Actions. Actions logs are public,
# and these lines say which bump fixed which alert before release branches are
# patched, so in Actions the result goes to GITHUB_OUTPUT alone.
log_local_only() {
if [[ -z "${GITHUB_ACTIONS:-}" ]]; then
echo "$1"
fi
}
# version_le A B: succeeds when version A <= version B. A leading "v" is
# ignored, because Go alerts and Dependabot commit messages disagree on it.
version_le() {
local a="${1#v}" b="${2#v}"
printf '%s\n%s\n' "${a}" "${b}" | sort -V -C
}
# version_lt A B: succeeds when version A < B.
version_lt() {
[[ "${1#v}" != "${2#v}" ]] && version_le "$1" "$2"
}
# Dependabot's commit lists every updated dependency in a YAML trailer with
# the new version:
# - dependency-name: dompurify
# dependency-version: 3.4.17
# The old version is only in the body, as "Bumps [name](url) from A to B." or,
# in grouped PRs, "Updates `name` from A to B".
message=$(gh api "repos/${REPO}/pulls/${PR_NUMBER}/commits" --jq '.[0].commit.message')
deps=$(awk '
{ gsub(/["\047]/, "") }
/^- dependency-name: / { name = $3 }
/^ dependency-version: / && name != "" { print name "\t" $2; name = "" }
' <<<"${message}")
olds=$(awk '
/^Bumps \[/ {
name = $0; sub(/^Bumps \[/, "", name); sub(/\].*/, "", name)
if (match($0, /\) from [^ ]+ to /)) { split(substr($0, RSTART + 7), v, " "); print name "\t" v[1] }
}
/^Updates `/ {
name = $0; sub(/^Updates `/, "", name); sub(/`.*/, "", name)
if (match($0, /` from [^ ]+ to /)) { split(substr($0, RSTART + 7), v, " "); print name "\t" v[1] }
}
' <<<"${message}")
# An empty result below means the input was incomplete, not that nothing
# matched. Fail so the job is visibly red instead of reporting matched=false
# and skipping a backport.
if [[ -z "${deps}" ]]; then
echo "::error::No updated-dependencies metadata in the first commit of PR #${PR_NUMBER}."
exit 1
fi
files=$(gh api --paginate "repos/${REPO}/pulls/${PR_NUMBER}/files" --jq '.[].filename')
if [[ -z "${files}" ]]; then
echo "::error::PR #${PR_NUMBER} lists no changed files."
exit 1
fi
matched=()
while IFS=$'\t' read -r name version; do
[[ -z "${name}" ]] && continue
old=$(awk -F'\t' -v n="${name}" '$1 == n { print $2; exit }' <<<"${olds}")
if [[ -z "${old}" ]]; then
echo "::warning::No old version for ${name} in PR #${PR_NUMBER}; matching on the new version only."
fi
# Assigned first, not read through < <(...): set -e ignores a failure in a
# process substitution, and a 403 or rate limit would look like no alerts.
alert_rows=$(
gh api --paginate -X GET "repos/${REPO}/dependabot/alerts" \
-f state=open,fixed -f package="${name}" -f per_page=100 \
--jq '.[] | [.number, .dependency.manifest_path, (.security_vulnerability.first_patched_version.identifier // "")] | @tsv'
)
while IFS=$'\t' read -r number manifest patched; do
[[ -z "${number}" || -z "${patched}" ]] && continue
grep -qxF -- "${manifest}" <<<"${files}" || continue
version_le "${patched}" "${version}" || continue
if [[ -n "${old}" ]] && ! version_lt "${old}" "${patched}"; then
continue
fi
log_local_only "Alert #${number}: ${name} ${old:-?} to ${version} fixes ${manifest} (patched in ${patched})."
matched+=("${number}")
done <<<"${alert_rows}"
done <<<"${deps}"
result=false
if ((${#matched[@]} > 0)); then
result=true
fi
alerts=$(
IFS=,
echo "${matched[*]:-}"
)
log_local_only "matched=${result} alerts=${alerts}"
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
{
echo "matched=${result}"
echo "alerts=${alerts}"
} >>"${GITHUB_OUTPUT}"
fi
+270
View File
@@ -0,0 +1,270 @@
#!/usr/bin/env bash
# Tests for dependabot-alert-match.sh. No CI job runs this file.
#
# Run: bash .github/scripts/dependabot-alert-match.test.sh
set -euo pipefail
SCRIPT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/dependabot-alert-match.sh"
WORK=$(mktemp -d)
trap 'rm -rf "${WORK}"' EXIT
# A gh stub that serves fixtures from ${WORK}. The script passes --jq, so the
# fixtures are the already-filtered output:
# commit-message the first commit's message
# files the PR's changed files, one per line
# alerts.<package> number<TAB>manifest<TAB>first patched version
# alerts-fail when present, the alerts call fails like a 403
mkdir -p "${WORK}/bin"
cat >"${WORK}/bin/gh" <<'STUB'
#!/usr/bin/env bash
set -euo pipefail
args="$*"
case "${args}" in
*/commits*) cat "${FIXTURES}/commit-message" ;;
*/files*) cat "${FIXTURES}/files" ;;
*/dependabot/alerts*)
[[ -f "${FIXTURES}/alerts-fail" ]] && {
echo "gh: HTTP 403" >&2
exit 1
}
pkg=""
while (($#)); do
if [[ "$1" == "-f" && "$2" == package=* ]]; then
pkg="${2#package=}"
fi
shift
done
f="${FIXTURES}/alerts.${pkg//\//_}"
[[ -f "${f}" ]] && cat "${f}"
exit 0
;;
*)
echo "unexpected gh call: ${args}" >&2
exit 1
;;
esac
STUB
chmod +x "${WORK}/bin/gh"
failures=0
case_name=""
OUT=""
# begin <name>: starts a case with empty fixtures.
begin() {
case_name="$1"
rm -rf "${WORK}/fixtures"
mkdir -p "${WORK}/fixtures"
: >"${WORK}/fixtures/files"
}
# commit <name> <old> <new>...: sets a Dependabot commit message with one
# dependency per name/old/new triple.
commit() {
local args=("$@")
{
echo "chore: bump things"
echo
if ((${#args[@]} == 3)); then
echo "Bumps [${args[0]}](https://example.com) from ${args[1]} to ${args[2]}."
else
echo "Bumps the group with ${#args[@]} updates."
for ((i = 0; i < ${#args[@]}; i += 3)); do
echo "Updates \`${args[i]}\` from ${args[i + 1]} to ${args[i + 2]}"
done
fi
echo
echo "---"
echo "updated-dependencies:"
for ((i = 0; i < ${#args[@]}; i += 3)); do
echo "- dependency-name: ${args[i]}"
echo " dependency-version: ${args[i + 2]}"
echo " dependency-type: direct:production"
done
echo "..."
} >"${WORK}/fixtures/commit-message"
}
# run: runs the script and captures GITHUB_OUTPUT in OUT.
run() {
: >"${WORK}/output"
FIXTURES="${WORK}/fixtures" PATH="${WORK}/bin:${PATH}" \
PR_NUMBER=1 REPO=coder/coder GITHUB_OUTPUT="${WORK}/output" GITHUB_ACTIONS="${IN_ACTIONS:-}" \
bash "${SCRIPT}" >"${WORK}/stdout" 2>"${WORK}/stderr" || {
echo "FAIL: ${case_name}: script exited non-zero"
sed 's/^/ stderr: /' "${WORK}/stderr"
failures=$((failures + 1))
return
}
OUT=$(<"${WORK}/output")
}
# run_fails: runs the script and expects a non-zero exit and no output file
# content, so the job fails visibly instead of reporting matched=false.
run_fails() {
: >"${WORK}/output"
if FIXTURES="${WORK}/fixtures" PATH="${WORK}/bin:${PATH}" \
PR_NUMBER=1 REPO=coder/coder GITHUB_OUTPUT="${WORK}/output" GITHUB_ACTIONS="${IN_ACTIONS:-}" \
bash "${SCRIPT}" >"${WORK}/stdout" 2>"${WORK}/stderr"; then
failures=$((failures + 1))
echo "FAIL: ${case_name}: script exited zero"
elif [[ -s "${WORK}/output" ]]; then
failures=$((failures + 1))
echo "FAIL: ${case_name}: wrote output despite the failure: $(<"${WORK}/output")"
fi
}
# expect <matched> <alerts>
expect() {
local want
want=$(printf 'matched=%s\nalerts=%s' "$1" "$2")
if [[ "${OUT}" != "${want}" ]]; then
failures=$((failures + 1))
echo "FAIL: ${case_name}"
echo " want: ${want//$'\n'/ }"
echo " got: ${OUT//$'\n'/ }"
fi
}
begin "npm: alert patched in the new version"
commit dompurify 3.4.14 3.4.17
echo "site/package.json" >"${WORK}/fixtures/files"
printf '705\tsite/package.json\t3.4.17\n' >"${WORK}/fixtures/alerts.dompurify"
run
expect true 705
begin "go: v prefix on the patched version"
commit github.com/moby/sys/user 0.4.0 0.4.1
printf 'go.mod\ngo.sum\n' >"${WORK}/fixtures/files"
printf '683\tgo.mod\tv0.4.1\n' >"${WORK}/fixtures/alerts.github.com_moby_sys_user"
run
expect true 683
begin "new version is newer than the patched version"
commit next 15.0.0 15.10.0
echo "site/package.json" >"${WORK}/fixtures/files"
printf '9\tsite/package.json\t15.9.2\n' >"${WORK}/fixtures/alerts.next"
run
expect true 9
begin "new version is older than the patched version"
commit axios 1.7.0 1.8.0
echo "site/package.json" >"${WORK}/fixtures/files"
printf '10\tsite/package.json\t1.8.4\n' >"${WORK}/fixtures/alerts.axios"
run
expect false ""
begin "version compare is numeric, not lexical"
commit axios 1.8.0 1.10.0
echo "site/package.json" >"${WORK}/fixtures/files"
printf '10\tsite/package.json\t1.9.0\n' >"${WORK}/fixtures/alerts.axios"
run
expect true 10
begin "alert is for a manifest the PR did not change"
commit dompurify 3.4.14 3.4.17
echo "offlinedocs/package.json" >"${WORK}/fixtures/files"
printf '705\tsite/package.json\t3.4.17\n' >"${WORK}/fixtures/alerts.dompurify"
run
expect false ""
begin "alert was already patched before the PR"
commit google.golang.org/grpc 1.84.0 1.85.0
echo "go.mod" >"${WORK}/fixtures/files"
printf '554\tgo.mod\t1.82.1\n' >"${WORK}/fixtures/alerts.google.golang.org_grpc"
run
expect false ""
begin "old version equals the patched version"
commit dompurify 3.4.17 3.4.18
echo "site/package.json" >"${WORK}/fixtures/files"
printf '705\tsite/package.json\t3.4.17\n' >"${WORK}/fixtures/alerts.dompurify"
run
expect false ""
begin "old version unknown: match on the new version"
printf -- '---\nupdated-dependencies:\n- dependency-name: dompurify\n dependency-version: 3.4.17\n...\n' >"${WORK}/fixtures/commit-message"
echo "site/package.json" >"${WORK}/fixtures/files"
printf '705\tsite/package.json\t3.4.17\n' >"${WORK}/fixtures/alerts.dompurify"
run
expect true 705
begin "no alert for the package"
commit left-pad 1.3.0 1.3.1
echo "site/package.json" >"${WORK}/fixtures/files"
run
expect false ""
begin "alert has no patched version"
commit foo 1.0.0 2.0.0
echo "site/package.json" >"${WORK}/fixtures/files"
printf '11\tsite/package.json\t\n' >"${WORK}/fixtures/alerts.foo"
run
expect false ""
begin "grouped PR: one of two dependencies fixes an alert"
commit left-pad 1.3.0 1.3.1 dompurify 3.4.14 3.4.17
echo "site/package.json" >"${WORK}/fixtures/files"
printf '705\tsite/package.json\t3.4.17\n' >"${WORK}/fixtures/alerts.dompurify"
run
expect true 705
begin "several alerts for one package"
commit dompurify 3.4.14 3.4.17
echo "site/package.json" >"${WORK}/fixtures/files"
printf '705\tsite/package.json\t3.4.17\n706\tsite/package.json\t3.4.16\n' >"${WORK}/fixtures/alerts.dompurify"
run
expect true 705,706
begin "in Actions: result only in GITHUB_OUTPUT, nothing about alerts in the log"
commit dompurify 3.4.14 3.4.17
echo "site/package.json" >"${WORK}/fixtures/files"
printf '705\tsite/package.json\t3.4.17\n' >"${WORK}/fixtures/alerts.dompurify"
IN_ACTIONS=true run
unset IN_ACTIONS
expect true 705
if [[ -s "${WORK}/stdout" ]] || grep -qiE 'alert|matched|dompurify|3\.4\.17' "${WORK}/stderr"; then
failures=$((failures + 1))
echo "FAIL: ${case_name}: the log mentions the alert"
sed 's/^/ stdout: /' "${WORK}/stdout"
sed 's/^/ stderr: /' "${WORK}/stderr"
fi
begin "locally: matched alerts are printed"
commit dompurify 3.4.14 3.4.17
echo "site/package.json" >"${WORK}/fixtures/files"
printf '705\tsite/package.json\t3.4.17\n' >"${WORK}/fixtures/alerts.dompurify"
run
grep -q 'Alert #705' "${WORK}/stdout" || {
failures=$((failures + 1))
echo "FAIL: ${case_name}: no alert line on stdout"
}
begin "alerts API call fails"
commit dompurify 3.4.14 3.4.17
echo "site/package.json" >"${WORK}/fixtures/files"
printf '705\tsite/package.json\t3.4.17\n' >"${WORK}/fixtures/alerts.dompurify"
touch "${WORK}/fixtures/alerts-fail"
run_fails
begin "commit without Dependabot metadata"
echo "chore: manual change" >"${WORK}/fixtures/commit-message"
echo "go.mod" >"${WORK}/fixtures/files"
run_fails
begin "empty commit message"
: >"${WORK}/fixtures/commit-message"
echo "go.mod" >"${WORK}/fixtures/files"
run_fails
begin "no changed files"
commit dompurify 3.4.14 3.4.17
printf '705\tsite/package.json\t3.4.17\n' >"${WORK}/fixtures/alerts.dompurify"
run_fails
if ((failures > 0)); then
echo "${failures} failure(s)"
exit 1
fi
echo "ok"
+73 -7
View File
@@ -14,6 +14,10 @@
# 2. When the PR merges (or if already merged), the workflow detects the
# target release/* branches and opens one cherry-pick PR per branch.
#
# Dependabot PRs that fix a Dependabot alert are labeled automatically when
# they merge (.github/scripts/dependabot-alert-match.sh), which then starts the
# backport.
#
# The created backport PRs follow existing repo conventions:
# - Branch: backport/<pr>-to-<version>
# - Title: <original PR title> (#<pr>)
@@ -41,12 +45,23 @@ jobs:
name: Detect target branches
permissions:
contents: read
id-token: write # Cloud KMS signs the backporter App's JWT
# A merged PR is backported when it has the backport label. A merged
# Dependabot PR is also checked against Dependabot alerts and labeled when
# it fixed one. Adding the label with the App token starts a new run of
# this workflow, which does the backport.
if: >
github.event.pull_request.merged == true &&
contains(github.event.pull_request.labels.*.name, 'backport')
github.event.pull_request.merged == true && (
contains(github.event.pull_request.labels.*.name, 'backport') ||
(
github.event.pull_request.user.login == 'dependabot[bot]' &&
github.event.pull_request.user.id == 49699333
)
)
runs-on: ubuntu-latest
environment: main
outputs:
branches: ${{ steps.find.outputs.branches }}
branches: ${{ steps.find.outputs.branches || '[]' }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
@@ -54,8 +69,45 @@ jobs:
fetch-depth: 0
persist-credentials: false
# GITHUB_TOKEN can't read Dependabot alerts, and a label added with it
# doesn't start the backport run. This only runs for Dependabot PRs that
# aren't labeled yet. The App's key is a non-exportable Cloud KMS key;
# only this workflow, in this environment, may sign with it.
- name: Generate alert App token
id: alert-token
if: ${{ !contains(github.event.pull_request.labels.*.name, 'backport') }}
uses: coder/github-app-token-action@00eaec58ee1bfea9c8b48655b7ab7470b07739e5 # main 2026-11-17
with:
client-id: ${{ secrets.BACKPORT_APP_ID }}
kms-key: ${{ secrets.BACKPORT_APP_KMS_KEY }}
workload-identity-provider: ${{ secrets.APP_KEYS_WORKLOAD_ID_PROVIDER }}
owner: coder
repositories: coder
permissions: |
pull_requests: write
issues: write
vulnerability_alerts: read
- name: Check Dependabot PR for backport
id: match
if: ${{ !contains(github.event.pull_request.labels.*.name, 'backport') }}
env:
GH_TOKEN: ${{ steps.alert-token.outputs.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
# The script comes from the checked-out base branch, never from the PR.
run: bash .github/scripts/dependabot-alert-match.sh
- name: Label Dependabot PR for backport
if: ${{ steps.match.outputs.matched == 'true' }}
env:
GH_TOKEN: ${{ steps.alert-token.outputs.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
# Output is discarded because logs are public. To see the matched alerts, run dependabot-alert-match.sh locally (read-only).
run: gh api -X POST "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/labels" -f 'labels[]=backport' >/dev/null
- name: Find target release branches
id: find
if: ${{ contains(github.event.pull_request.labels.*.name, 'backport') }}
env:
ESR_VERSIONS_FILE: scripts/release_channels/esr_versions.txt
run: |
@@ -123,7 +175,13 @@ jobs:
PR_TITLE: ${{ github.event.pull_request.title }}
PR_URL: ${{ github.event.pull_request.html_url }}
MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }}
SENDER: ${{ github.event.sender.login }}
# Who owns the backport PRs: the person who added the label. In the Dependabot
# path the label comes from the backporter App, so use the person who merged
# the PR. Empty when both are bots.
# Unverified: that merged_by is set in the pull_request_target "labeled"
# payload. The API returns it, but no Dependabot run has used this path yet.
# If it's missing, OWNER is empty and the job warns that the PR has no assignee.
OWNER: ${{ (github.event.sender.type != 'Bot' && github.event.sender.login) || (github.event.pull_request.merged_by.type != 'Bot' && github.event.pull_request.merged_by.login) || '' }}
BRANCH: ${{ matrix.branch }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -226,12 +284,16 @@ jobs:
fi
TITLE="${PR_TITLE} (#${PR_NUMBER})"
REQUESTED_BY=""
if [ -n "$OWNER" ]; then
REQUESTED_BY="Requested by: @${OWNER}"
fi
BODY=$(cat <<EOF
Backport of ${PR_URL}
Original PR: #${PR_NUMBER} — ${PR_TITLE}
Merge commit: ${MERGE_SHA}
Requested by: @${SENDER}
${REQUESTED_BY}
EOF
)
@@ -273,8 +335,12 @@ jobs:
)
gh pr edit "$NEW_PR_URL" --add-label "$BACKPORT_LABEL" || echo "::warning::Could not add label ${BACKPORT_LABEL} to ${NEW_PR_URL}."
gh pr edit "$NEW_PR_URL" --add-assignee "$SENDER" || echo "::warning::Could not assign @${SENDER} to ${NEW_PR_URL}."
gh pr edit "$NEW_PR_URL" --add-reviewer "$SENDER" || echo "::warning::Could not request review from @${SENDER} on ${NEW_PR_URL}."
if [ -n "$OWNER" ]; then
gh pr edit "$NEW_PR_URL" --add-assignee "$OWNER" || echo "::warning::Could not assign @${OWNER} to ${NEW_PR_URL}."
gh pr edit "$NEW_PR_URL" --add-reviewer "$OWNER" || echo "::warning::Could not request review from @${OWNER} on ${NEW_PR_URL}."
else
echo "::warning::Neither the label sender nor the merger of #${PR_NUMBER} is a person; ${NEW_PR_URL} has no assignee."
fi
# Notify the requester on the original PR which backport was opened,
# flagging conflicts that still need manual resolution. Best-effort:
+7 -49
View File
@@ -9,7 +9,7 @@ permissions:
contents: read
jobs:
dependabot-automerge:
dependabot-notify:
runs-on: ubuntu-latest
if: >
github.event_name == 'pull_request' &&
@@ -17,55 +17,15 @@ jobs:
github.event.pull_request.user.login == 'dependabot[bot]' &&
github.event.pull_request.user.id == 49699333 &&
github.repository == 'coder/coder'
permissions:
pull-requests: write
contents: write
permissions: {}
# Merging and security backports are handled elsewhere: a person merges
# Dependabot PRs, and backport.yaml labels the ones that fix a Dependabot
# alert after they merge. Merges and labels made with GITHUB_TOKEN don't
# start other workflows, so this job doesn't make either.
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
alert-lookup: true
- name: Add backport label to security updates
id: security_backport
if: >-
${{
steps.metadata.outputs.alert-state != '' &&
!contains(github.event.pull_request.labels.*.name, 'backport')
}}
run: |
set -euo pipefail
echo "Adding backport label to security update PR $PR_URL"
gh pr edit "$PR_URL" --add-label backport
echo "added=true" >> "$GITHUB_OUTPUT"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# fetch-metadata reports `github_actions`, not `github-actions`.
- name: Enable auto-merge
if: steps.metadata.outputs.package-ecosystem != 'github_actions'
run: |
echo "Enabling auto-merge for $PR_URL"
gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Send Slack notification
run: |
if [ "$SECURITY_BACKPORT" = "true" ] && [ "$PACKAGE_ECOSYSTEM" = "github_actions" ]; then
STATUS_TEXT=":rotating_light: Dependabot opened security PR #${PR_NUMBER} and added the backport label (GitHub Actions changes are not auto-merged)"
elif [ "$SECURITY_BACKPORT" = "true" ]; then
STATUS_TEXT=":rotating_light: Auto merge enabled for Dependabot security PR #${PR_NUMBER}; backport label added"
elif [ "$PACKAGE_ECOSYSTEM" = "github_actions" ]; then
STATUS_TEXT=":pr-opened: Dependabot opened PR #${PR_NUMBER} (GitHub Actions changes are not auto-merged)"
else
STATUS_TEXT=":pr-merged: Auto merge enabled for Dependabot PR #${PR_NUMBER}"
fi
STATUS_TEXT=":pr-opened: Dependabot opened PR #${PR_NUMBER}"
curl -X POST -H 'Content-type: application/json' \
--data '{
"username": "dependabot",
@@ -105,8 +65,6 @@ jobs:
}' "${{ secrets.DEPENDABOT_PRS_SLACK_WEBHOOK }}"
env:
SLACK_WEBHOOK: ${{ secrets.DEPENDABOT_PRS_SLACK_WEBHOOK }}
PACKAGE_ECOSYSTEM: ${{ steps.metadata.outputs.package-ecosystem }}
SECURITY_BACKPORT: ${{ steps.security_backport.outputs.added || 'false' }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
PR_URL: ${{ github.event.pull_request.html_url }}