|
| 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