-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdependabot-news-md-autofill.yaml
More file actions
103 lines (85 loc) · 2.94 KB
/
dependabot-news-md-autofill.yaml
File metadata and controls
103 lines (85 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Dependabot NEWS.md autofill
on:
pull_request_target:
branches: [main]
types: [opened, synchronize, reopened, edited]
permissions:
contents: write
pull-requests: read
jobs:
add-news-entry:
if: github.actor == 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- name: Checkout PR head
uses: actions/checkout@v6
with:
# IMPORTANT: checkout the PR branch, not main
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
persist-credentials: true
- name: Compute NEWS.md entry from Dependabot title
id: news
shell: bash
run: |
set -euo pipefail
TITLE="${{ github.event.pull_request.title }}"
# Typical Dependabot titles:
# "Bump <package> from <old> to <new>"
if [[ "$TITLE" =~ ^Bump[[:space:]]+(.+)[[:space:]]+from[[:space:]]+([^[:space:]]+)[[:space:]]+to[[:space:]]+([^[:space:]]+)$ ]]; then
PKG="${BASH_REMATCH[1]}"
FROM="${BASH_REMATCH[2]}"
TO="${BASH_REMATCH[3]}"
ENTRY="* dependabot updating package ${PKG} from version ${FROM} to version ${TO} new"
else
# Fallback if title format differs (rare, but happens)
ENTRY="* dependabot updating dependencies new"
fi
echo "entry=$ENTRY" >> "$GITHUB_OUTPUT"
- name: Insert Dependabot entry under latest Features section
shell: bash
run: |
set -euo pipefail
ENTRY="${{ steps.news.outputs.entry }}"
if [[ ! -f NEWS.md ]]; then
echo "::error file=NEWS.md,line=1,col=1::NEWS.md not found."
exit 1
fi
# If entry already exists anywhere, do nothing
if grep -Fqx "$ENTRY" NEWS.md; then
echo "NEWS.md already contains the entry. Skipping."
exit 0
fi
tmp="$(mktemp)"
# Insert directly after the first "## Features" header
awk -v entry="$ENTRY" '
BEGIN { inserted=0 }
{
print $0
if ($0 ~ /^##[[:space:]]+Features[[:space:]]*$/ && inserted == 0) {
print entry
inserted=1
}
}
END {
if (inserted == 0) {
print ""
print entry
}
}
' NEWS.md > "$tmp"
mv "$tmp" NEWS.md
- name: Commit and push (only if changed)
shell: bash
run: |
set -euo pipefail
if git diff --quiet; then
echo "No changes to commit."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add NEWS.md
git commit -m "Update NEWS.md for Dependabot PR"
git push