Skip to content

Commit 06f8544

Browse files
authored
Merge pull request #7850 from plotly/cam/7849/add-ci-check-draftlog
ci: Add CI step to check for draftlog
2 parents 81f20cc + 4133f7b commit 06f8544

4 files changed

Lines changed: 91 additions & 2 deletions

File tree

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ Before opening a pull request, developer should:
1818
7. select the _Allow edits from maintainers_ option (see this [article](https://help.github.com/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork/) for more details).
1919

2020
After opening a pull request, developer:
21-
- should create a new small markdown log file using the PR number e.g. `1010_fix.md` or `1010_add.md` inside `draftlogs` folder as described in this [README](https://github.com/plotly/plotly.js/blob/master/draftlogs/README.md), commit it and push.
21+
- should create a new small markdown log file using the PR number e.g. `1010_fix.md` or `1010_add.md` inside `draftlogs` folder as described in this [README](https://github.com/plotly/plotly.js/blob/master/draftlogs/README.md), commit it and push. A CI check enforces this; PRs that don't warrant a CHANGELOG entry can opt out by applying the `no-draftlog` label.
2222
- should **not** force push (i.e. `git push -f`) to remote branches associated with opened pull requests. Force pushes make it hard for maintainers to keep track of updates. Therefore, if required, please fetch `upstream/master` and "merge" with master instead of "rebase".
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@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
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/[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/^/ - /'

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ We use the following [labels](https://github.com/plotly/plotly.js/labels) to tra
7171
| `status: in progress` | PRs that required some initial feedback but not ready to merge |
7272
| `status: reviewable` | PRs that are completed from the author's perspective |
7373
| `status: on hold` | PRs that are put on hold |
74+
| `no-draftlog` | PR opted out of the [draftlog](./draftlogs/README.md) check |
7475

7576
## Development
7677

draftlogs/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,15 @@ If your PR falls into more than one category - for example adding a new feature
1919
which would render
2020
- Add `icicle` trace type [[#5546](https://github.com/plotly/plotly.js/pull/5546)]
2121

22-
> Please start your single-line or multiple lined message with a verb. You could basically use the PR description while providing a link to the PR similar to the above example is appreciated too.
22+
> Please start your single-line or multiple lined message with a verb.
23+
24+
Each entry must include a link back to the PR in the form shown above:
25+
`[[#1234](https://github.com/plotly/plotly.js/pull/1234)]` (a link to
26+
`/issues/1234` is also accepted, since GitHub redirects between the two).
27+
28+
### Skipping the draftlog
29+
30+
A CI check enforces that every pull request adds a new file under
31+
`draftlogs/`. If your PR genuinely does not warrant a CHANGELOG entry
32+
(e.g. a CI-only change, internal refactor, or docs typo), add the
33+
`no-draftlog` label to the PR to opt out.

0 commit comments

Comments
 (0)