Skip to content

Commit 0f52144

Browse files
authored
[misc] Add docs acknowledgement check (#4310)
adds a GitHub Actions workflow to enforce documentation requirements for pull requests, ensuring contributors acknowledge whether their changes need documentation updates or provide a link to a corresponding docs PR. - Adds a new GitHub Actions workflow that validates documentation acknowledgement in PR descriptions - Updates the PR template to include mandatory documentation checkboxes and URL field - Implements validation logic to ensure exactly one documentation option is selected and verifies docs PR URLs when provided
1 parent 0926400 commit 0f52144

File tree

2 files changed

+105
-1
lines changed

2 files changed

+105
-1
lines changed

.github/pull_request_template.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
- [ ] Is a feature enhancement
1313
- [ ] It is a refactor
1414
- [ ] Created tests that fail without the change (if possible)
15-
- [ ] Extended the README / documentation, if necessary
1615

1716
> By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md).
17+
18+
## Documentation
19+
Select exactly one:
20+
21+
- [ ] I added/updated documentation for this change
22+
- [ ] Documentation is **not needed** for this change (explain why)
23+
24+
### Docs PR URL (required if "docs added" is checked)
25+
Paste the PR link from https://github.com/netbirdio/docs here:
26+
27+
https://github.com/netbirdio/docs/pull/__

.github/workflows/docs-ack.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Docs Acknowledgement
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize]
6+
7+
permissions:
8+
contents: read
9+
pull-requests: read
10+
11+
jobs:
12+
docs-ack:
13+
name: Require docs PR URL or explicit "not needed"
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Read PR body
18+
id: body
19+
run: |
20+
BODY=$(jq -r '.pull_request.body // ""' "$GITHUB_EVENT_PATH")
21+
echo "body<<EOF" >> $GITHUB_OUTPUT
22+
echo "$BODY" >> $GITHUB_OUTPUT
23+
echo "EOF" >> $GITHUB_OUTPUT
24+
25+
- name: Validate checkbox selection
26+
id: validate
27+
run: |
28+
body='${{ steps.body.outputs.body }}'
29+
30+
added_checked=$(printf "%s" "$body" | grep -E '^- \[x\] I added/updated documentation' -i | wc -l | tr -d ' ')
31+
noneed_checked=$(printf "%s" "$body" | grep -E '^- \[x\] Documentation is \*\*not needed\*\*' -i | wc -l | tr -d ' ')
32+
33+
if [ "$added_checked" -eq 1 ] && [ "$noneed_checked" -eq 1 ]; then
34+
echo "::error::Choose exactly one: either 'docs added' OR 'not needed'."
35+
exit 1
36+
fi
37+
38+
if [ "$added_checked" -eq 0 ] && [ "$noneed_checked" -eq 0 ]; then
39+
echo "::error::You must check exactly one docs option in the PR template."
40+
exit 1
41+
fi
42+
43+
if [ "$added_checked" -eq 1 ]; then
44+
echo "mode=added" >> $GITHUB_OUTPUT
45+
else
46+
echo "mode=noneed" >> $GITHUB_OUTPUT
47+
fi
48+
49+
- name: Extract docs PR URL (when 'docs added')
50+
if: steps.validate.outputs.mode == 'added'
51+
id: extract
52+
run: |
53+
body='${{ steps.body.outputs.body }}'
54+
55+
# Strictly require HTTPS and that it's a PR in netbirdio/docs
56+
# Examples accepted:
57+
# https://github.com/netbirdio/docs/pull/1234
58+
url=$(printf "%s" "$body" | grep -Eo 'https://github\.com/netbirdio/docs/pull/[0-9]+' | head -n1 || true)
59+
60+
if [ -z "$url" ]; then
61+
echo "::error::You checked 'docs added' but didn't include a valid HTTPS PR link to netbirdio/docs (e.g., https://github.com/netbirdio/docs/pull/1234)."
62+
exit 1
63+
fi
64+
65+
pr_number=$(echo "$url" | sed -E 's#.*/pull/([0-9]+)$#\1#')
66+
echo "url=$url" >> $GITHUB_OUTPUT
67+
echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
68+
69+
- name: Verify docs PR exists (and is open or merged)
70+
if: steps.validate.outputs.mode == 'added'
71+
uses: actions/github-script@v7
72+
id: verify
73+
with:
74+
pr_number: ${{ steps.extract.outputs.pr_number }}
75+
script: |
76+
const prNumber = parseInt(core.getInput('pr_number'), 10);
77+
const { data } = await github.rest.pulls.get({
78+
owner: 'netbirdio',
79+
repo: 'docs',
80+
pull_number: prNumber
81+
});
82+
83+
// Allow open or merged PRs
84+
const ok = data.state === 'open' || data.merged === true;
85+
core.setOutput('state', data.state);
86+
core.setOutput('merged', String(!!data.merged));
87+
if (!ok) {
88+
core.setFailed(`Docs PR #${prNumber} exists but is neither open nor merged (state=${data.state}, merged=${data.merged}).`);
89+
}
90+
result-encoding: string
91+
github-token: ${{ secrets.GITHUB_TOKEN }}
92+
93+
- name: All good
94+
run: echo "Documentation requirement satisfied ✅"

0 commit comments

Comments
 (0)