Skip to content

Commit 14eed27

Browse files
authored
PR Hygiene checks
- rename `semver.yml` workflow to a more general `pr-checks.yml` - add a check that if the `breaking change` label is applied, the job must contain a section called "Breaking change(s)"
1 parent 07b2633 commit 14eed27

File tree

2 files changed

+97
-42
lines changed

2 files changed

+97
-42
lines changed

.github/workflows/pr-checks.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: PR Hygiene
2+
3+
on:
4+
pull_request:
5+
branches: [ "main", "feature/*" ]
6+
7+
jobs:
8+
semver:
9+
permissions:
10+
contents: read
11+
runs-on: ubuntu-latest
12+
outputs:
13+
has-breaking-change-label: ${{ steps.check-breaking-label.outputs.has-label }}
14+
steps:
15+
16+
- name: Check out repo
17+
uses: actions/checkout@v4
18+
19+
- name: Also fetch target branch
20+
run: git fetch origin "$GITHUB_BASE_REF"
21+
22+
- name: Install semver-checks
23+
run: |
24+
set -euo pipefail
25+
cd "$RUNNER_TEMP"
26+
gh release -R obi1kenobi/cargo-semver-checks download -p cargo-semver-checks-x86_64-unknown-linux-gnu.tar.gz -O - | tar xz
27+
working-directory: ${{ env.RUNNER_TEMP }}
28+
env:
29+
GH_TOKEN: ${{ github.token }}
30+
31+
- name: 'Check for "breaking change" label'
32+
id: check-breaking-label
33+
run: |
34+
breaking_change_label_count="$(gh pr view ${{ github.event.number }} --json labels | jq '.labels | map(select(.name == "breaking change")) | length')"
35+
if [[ "$breaking_change_label_count" == 1 ]]; then
36+
echo "has-label=true" >> "$GITHUB_OUTPUT"
37+
else
38+
echo "has-label=false" >> "$GITHUB_OUTPUT"
39+
fi
40+
env:
41+
GH_TOKEN: ${{ github.token }}
42+
43+
- name: Run semver-checks
44+
run: |
45+
if ! "$RUNNER_TEMP/cargo-semver-checks" semver-checks --baseline-rev "origin/$GITHUB_BASE_REF" ; then
46+
# There were breaking changes. Make sure we have the appropriate label!
47+
if [[ "${{ steps.check-breaking-label.outputs.has-label }}" != "true" ]]; then
48+
echo "::error title=semver-checks::semver-checks found breaking changes, but the 'breaking change' label isn't applied. Please add that label."
49+
exit 1
50+
else
51+
echo "::warning title=semver-checks::semver-checks found breaking changes. The 'breaking change' label is applied, so no action needed if this is an acceptable change."
52+
fi
53+
fi
54+
55+
breaking-change-docs:
56+
needs: semver
57+
permissions:
58+
contents: read
59+
runs-on: ubuntu-latest
60+
steps:
61+
- name: Fetch PR description
62+
id: pr-description
63+
run: |
64+
pr_description="$(gh pr view ${{ github.event.number }} --repo ${{ github.repository }} --json body -q '.body')"
65+
delimiter="$(uuidgen | tr -d -)"
66+
echo "description<<$delimiter" >> "$GITHUB_OUTPUT"
67+
echo "$pr_description" >> "$GITHUB_OUTPUT"
68+
echo "$delimiter" >> "$GITHUB_OUTPUT"
69+
env:
70+
GH_TOKEN: ${{ github.token }}
71+
72+
- name: Pull mdq Docker image
73+
run: docker pull yshavit/mdq
74+
75+
- name: 'Check for `# Breaking change` section'
76+
id: check-breaking-section
77+
run: |
78+
if <<<"$PR_DESCRIPTION" docker run --rm -i yshavit/mdq -q '# Breaking change' >/dev/null 2>&1; then
79+
echo "has-section=true" >> "$GITHUB_OUTPUT"
80+
else
81+
echo "has-section=false" >> "$GITHUB_OUTPUT"
82+
fi
83+
env:
84+
PR_DESCRIPTION: ${{ steps.pr-description.outputs.description }}
85+
86+
- name: Check breaking change label and section consistency
87+
run: |
88+
has_label="${{ needs.semver.outputs.has-breaking-change-label }}"
89+
has_section="${{ steps.check-breaking-section.outputs.has-section }}"
90+
91+
if [[ "$has_label" == "true" && "$has_section" == "false" ]]; then
92+
echo "::error title=breaking-change-docs::PR has 'breaking change' label but is missing '# Breaking change' section in description."
93+
exit 1
94+
elif [[ "$has_label" == "false" && "$has_section" == "true" ]]; then
95+
echo "::error title=breaking-change-docs::PR has '# Breaking change' section in description but is missing 'breaking change' label."
96+
exit 1
97+
fi

.github/workflows/semver.yml

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)