Skip to content

Commit 118d6ba

Browse files
authored
Merge pull request #4981 from vvoland/ci-validate-pr
ci: Require changelog description
2 parents 4eeb776 + c3243a8 commit 118d6ba

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ Please provide the following information:
2222
**- Description for the changelog**
2323
<!--
2424
Write a short (one line) summary that describes the changes in this
25-
pull request for inclusion in the changelog:
25+
pull request for inclusion in the changelog.
26+
It must be placed inside the below triple backticks section:
2627
-->
28+
```markdown changelog
2729

2830

31+
```
32+
2933
**- A picture of a cute animal (not mandatory but encouraged)**
3034

.github/workflows/validate-pr.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: validate-pr
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, labeled, unlabeled]
6+
7+
jobs:
8+
check-area-label:
9+
runs-on: ubuntu-20.04
10+
steps:
11+
- name: Missing `area/` label
12+
if: contains(join(github.event.pull_request.labels.*.name, ','), 'impact/') && !contains(join(github.event.pull_request.labels.*.name, ','), 'area/')
13+
run: |
14+
echo "::error::Every PR with an 'impact/*' label should also have an 'area/*' label"
15+
exit 1
16+
- name: OK
17+
run: exit 0
18+
19+
check-changelog:
20+
if: contains(join(github.event.pull_request.labels.*.name, ','), 'impact/')
21+
runs-on: ubuntu-20.04
22+
env:
23+
PR_BODY: |
24+
${{ github.event.pull_request.body }}
25+
steps:
26+
- name: Check changelog description
27+
run: |
28+
# Extract the `markdown changelog` note code block
29+
block=$(echo -n "$PR_BODY" | tr -d '\r' | awk '/^```markdown changelog$/{flag=1;next}/^```$/{flag=0}flag')
30+
31+
# Strip empty lines
32+
desc=$(echo "$block" | awk NF)
33+
34+
if [ -z "$desc" ]; then
35+
echo "::error::Changelog section is empty. Please provide a description for the changelog."
36+
exit 1
37+
fi
38+
39+
len=$(echo -n "$desc" | wc -c)
40+
if [[ $len -le 6 ]]; then
41+
echo "::error::Description looks too short: $desc"
42+
exit 1
43+
fi
44+
45+
echo "This PR will be included in the release notes with the following note:"
46+
echo "$desc"
47+
48+
check-pr-branch:
49+
runs-on: ubuntu-20.04
50+
env:
51+
PR_TITLE: ${{ github.event.pull_request.title }}
52+
steps:
53+
# Backports or PR that target a release branch directly should mention the target branch in the title, for example:
54+
# [X.Y backport] Some change that needs backporting to X.Y
55+
# [X.Y] Change directly targeting the X.Y branch
56+
- name: Get branch from PR title
57+
id: title_branch
58+
run: echo "$PR_TITLE" | sed -n 's/^\[\([0-9]*\.[0-9]*\)[^]]*\].*/branch=\1/p' >> $GITHUB_OUTPUT
59+
60+
- name: Check release branch
61+
if: github.event.pull_request.base.ref != steps.title_branch.outputs.branch && !(github.event.pull_request.base.ref == 'master' && steps.title_branch.outputs.branch == '')
62+
run: echo "::error::PR title suggests targetting the ${{ steps.title_branch.outputs.branch }} branch, but is opened against ${{ github.event.pull_request.base.ref }}" && exit 1

0 commit comments

Comments
 (0)