-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (64 loc) · 2.17 KB
/
update-summary-buttons.yml
File metadata and controls
79 lines (64 loc) · 2.17 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
name: Update Summary Buttons
on:
push:
branches:
- main
paths:
- '_includes/summary-buttons.md'
- '**/summary*.md'
pull_request:
branches:
- main
paths:
- '_includes/summary-buttons.md'
- '**/summary*.md'
workflow_dispatch:
permissions:
contents: write
jobs:
update-buttons:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine diff range
id: diff-range
run: |
BEFORE_SHA="${{ github.event.before }}"
AFTER_SHA="${{ github.sha }}"
if [ -z "$BEFORE_SHA" ]; then
BEFORE_SHA="$(git rev-list --max-parents=0 HEAD)"
fi
echo "before_sha=$BEFORE_SHA" >> "$GITHUB_OUTPUT"
echo "after_sha=$AFTER_SHA" >> "$GITHUB_OUTPUT"
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- name: Replace buttons
env:
BEFORE_SHA: ${{ steps.diff-range.outputs.before_sha }}
AFTER_SHA: ${{ steps.diff-range.outputs.after_sha }}
run: |
TEMPLATE_CHANGED=$(git diff --name-only "$BEFORE_SHA" "$AFTER_SHA" -- '_includes/summary-buttons.md' | wc -l | tr -d '[:space:]')
mapfile -t FILES < <(git diff --name-only "$BEFORE_SHA" "$AFTER_SHA" -- '**/summary*.md')
if [ "${#FILES[@]}" -eq 0 ] && [ "$TEMPLATE_CHANGED" -eq 0 ]; then
echo "No changed summaries or template; skipping."
exit 0
fi
echo "Template changed: $TEMPLATE_CHANGED"
printf 'Changed summary files:\n%s\n' "${FILES[@]}"
node scripts/replace-buttons.mjs "$TEMPLATE_CHANGED" "${FILES[@]}"
- name: Commit & Push if changed
run: |
if [ -n "$(git status --porcelain)" ]; then
if git log -1 --pretty=%an | grep -q "github-actions"; then
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "chore: update summary action buttons"
git push
fi