Skip to content

Commit d8ece3b

Browse files
committed
ci: Add CI step to check for draftlog
1 parent 81f20cc commit d8ece3b

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Check Draftlog
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize, labeled, unlabeled, ready_for_review]
6+
7+
concurrency:
8+
group: check-draftlog-${{ github.event.pull_request.number }}
9+
cancel-in-progress: true
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
check-draftlog:
16+
if: github.event.pull_request.draft == false
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Check for a new draftlog entry
24+
env:
25+
PR_LABELS: ${{ toJson(github.event.pull_request.labels.*.name) }}
26+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
27+
run: |
28+
set -euo pipefail
29+
30+
if echo "$PR_LABELS" | grep -q '"no-draftlog"'; then
31+
echo "Skipping draftlog check: 'no-draftlog' label is set."
32+
exit 0
33+
fi
34+
35+
ADDED=$(git diff --name-only --diff-filter=A "$BASE_SHA"...HEAD -- 'draftlogs/*.md' | grep -v '^draftlogs/README\.md$' || true)
36+
37+
if [ -z "$ADDED" ]; then
38+
echo "::error::No new draftlog entry was added under draftlogs/."
39+
echo ""
40+
echo "Most PRs should add a markdown file under draftlogs/ for the next CHANGELOG."
41+
echo "See draftlogs/README.md for the filename convention."
42+
echo ""
43+
echo "If this PR genuinely does not need a changelog entry (e.g. CI-only,"
44+
echo "internal refactor, docs typo), add the 'no-draftlog' label to this PR."
45+
exit 1
46+
fi
47+
48+
INVALID_NAMES=$(echo "$ADDED" | grep -vE '^draftlogs/[0-9]+_(fix|add|remove|change|deprecate)\.md$' || true)
49+
if [ -n "$INVALID_NAMES" ]; then
50+
echo "::error::Invalid draftlog filename(s):"
51+
echo "$INVALID_NAMES" | sed 's/^/ - /'
52+
echo ""
53+
echo "Expected pattern: draftlogs/<number>_(fix|add|remove|change|deprecate).md"
54+
echo "See draftlogs/README.md for details."
55+
exit 1
56+
fi
57+
58+
MISSING_LINK=""
59+
while IFS= read -r f; do
60+
[ -z "$f" ] && continue
61+
if ! grep -qE '\[\[#[0-9]+\]\(https://github\.com/plotly/plotly\.js/(pull|issues)/[0-9]+\)\]' "$f"; then
62+
MISSING_LINK="$MISSING_LINK$f"$'\n'
63+
fi
64+
done <<< "$ADDED"
65+
66+
if [ -n "$MISSING_LINK" ]; then
67+
echo "::error::Draftlog entry(ies) missing a PR link:"
68+
printf '%s' "$MISSING_LINK" | sed 's/^/ - /'
69+
echo ""
70+
echo "Each entry must include a link in the form:"
71+
echo " [[#1234](https://github.com/plotly/plotly.js/pull/1234)]"
72+
echo "See draftlogs/README.md for an example."
73+
exit 1
74+
fi
75+
76+
echo "Found new draftlog entry(ies):"
77+
echo "$ADDED" | sed 's/^/ - /'

0 commit comments

Comments
 (0)