-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdependabot-news-md-autofill.yaml
More file actions
114 lines (92 loc) · 2.97 KB
/
dependabot-news-md-autofill.yaml
File metadata and controls
114 lines (92 loc) · 2.97 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
104
105
106
107
108
109
110
111
112
113
114
name: Dependabot NEWS.md autofill
on:
pull_request:
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 base branch
uses: actions/checkout@v6
with:
ref: main
fetch-depth: 0
- name: Compute NEWS.md entry from Dependabot title
id: news
shell: bash
env:
TITLE: ${{ github.event.pull_request.title }}
run: |
set -euo pipefail
sanitize() {
printf '%s' "$1" \
| tr -d '\r\n' \
| tr -cd '[:alnum:][:space:].,_@%:/+-' \
| sed 's/[[:space:]]\+/ /g'
}
if [[ "$TITLE" =~ ^Bump[[:space:]]+(.+)[[:space:]]+from[[:space:]]+([^[:space:]]+)[[:space:]]+to[[:space:]]+([^[:space:]]+)$ ]]; then
RAW_PKG="${BASH_REMATCH[1]}"
RAW_FROM="${BASH_REMATCH[2]}"
RAW_TO="${BASH_REMATCH[3]}"
PKG="$(sanitize "$RAW_PKG")"
FROM="$(sanitize "$RAW_FROM")"
TO="$(sanitize "$RAW_TO")"
ENTRY="* dependabot updating package ${PKG} from version ${FROM} to version ${TO} new"
else
ENTRY="* dependabot updating dependencies new"
fi
{
echo "entry<<EOF"
echo "$ENTRY"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Update NEWS.md
id: update
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 grep -Fqx "$ENTRY" NEWS.md; then
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
tmp="$(mktemp)"
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
echo "changed=true" >> "$GITHUB_OUTPUT"
- name: Commit and push to PR branch
if: steps.update.outputs.changed == 'true'
shell: bash
run: |
set -euo pipefail
git fetch origin "${{ github.event.pull_request.head.ref }}"
git checkout "${{ github.event.pull_request.head.ref }}"
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 origin HEAD