From 745704d7b4ec55c93b84db5372e0369850434207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Thu, 4 Apr 2024 15:24:25 +0200 Subject: [PATCH 1/3] ci: Require changelog description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Any PR that is labeled with any `impact/*` label should have a description for the changelog and an `area/*` label. (copied from moby/moby 1d473549e865ef6b90ee936c280f4bda677de39b) Signed-off-by: Paweł Gronowski --- .github/PULL_REQUEST_TEMPLATE.md | 6 +++- .github/workflows/validate-pr.yml | 46 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/validate-pr.yml diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 4e48d5f880..51141a5b00 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -22,9 +22,13 @@ Please provide the following information: **- Description for the changelog** +```markdown changelog +``` + **- A picture of a cute animal (not mandatory but encouraged)** diff --git a/.github/workflows/validate-pr.yml b/.github/workflows/validate-pr.yml new file mode 100644 index 0000000000..fb21f9bf5a --- /dev/null +++ b/.github/workflows/validate-pr.yml @@ -0,0 +1,46 @@ +name: validate-pr + +on: + pull_request: + types: [opened, edited, labeled, unlabeled] + +jobs: + check-area-label: + runs-on: ubuntu-20.04 + steps: + - name: Missing `area/` label + if: contains(join(github.event.pull_request.labels.*.name, ','), 'impact/') && !contains(join(github.event.pull_request.labels.*.name, ','), 'area/') + run: | + echo "Every PR with an \`impact/*\` label should also have an \`area/*\` label" + exit 1 + - name: OK + run: exit 0 + + check-changelog: + if: contains(join(github.event.pull_request.labels.*.name, ','), 'impact/') + runs-on: ubuntu-20.04 + env: + PR_BODY: | + ${{ github.event.pull_request.body }} + steps: + - name: Check changelog description + run: | + # Extract the `markdown changelog` note code block + block=$(echo -n "$PR_BODY" | tr -d '\r' | awk '/^```markdown changelog$/{flag=1;next}/^```$/{flag=0}flag') + + # Strip empty lines + desc=$(echo "$block" | awk NF) + + if [ -z "$desc" ]; then + echo "Changelog section is empty. Please provide a description for the changelog." + exit 1 + fi + + len=$(echo -n "$desc" | wc -c) + if [[ $len -le 6 ]]; then + echo "Description looks too short: $desc" + exit 1 + fi + + echo "This PR will be included in the release notes with the following note:" + echo "$desc" From f92fcdef1b5f801c2fe359eee1833473caeabb5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Fri, 19 Apr 2024 14:01:04 +0200 Subject: [PATCH 2/3] github/ci: Check if backport is opened against the expected branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (copied from moby/moby 61269e718fbdbbad397b0089105ec910fc0e62ca) Signed-off-by: Paweł Gronowski --- .github/workflows/validate-pr.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/validate-pr.yml b/.github/workflows/validate-pr.yml index fb21f9bf5a..f7b43170d7 100644 --- a/.github/workflows/validate-pr.yml +++ b/.github/workflows/validate-pr.yml @@ -44,3 +44,19 @@ jobs: echo "This PR will be included in the release notes with the following note:" echo "$desc" + + check-pr-branch: + runs-on: ubuntu-20.04 + env: + PR_TITLE: ${{ github.event.pull_request.title }} + steps: + # Backports or PR that target a release branch directly should mention the target branch in the title, for example: + # [X.Y backport] Some change that needs backporting to X.Y + # [X.Y] Change directly targeting the X.Y branch + - name: Get branch from PR title + id: title_branch + run: echo "$PR_TITLE" | sed -n 's/^\[\([0-9]*\.[0-9]*\)[^]]*\].*/branch=\1/p' >> $GITHUB_OUTPUT + + - name: Check release branch + if: github.event.pull_request.base.ref != steps.title_branch.outputs.branch && !(github.event.pull_request.base.ref == 'master' && steps.title_branch.outputs.branch == '') + 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 From c3243a8cc3da6bafc9e363d3d09550e558cd529f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Fri, 19 Apr 2024 13:59:40 +0200 Subject: [PATCH 3/3] ci/validate-pr: Use `::error::` command to print errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will make Github render the log line as an error. (copied from moby/moby fb92caf2aa6cf3664e11dc06ee10d114af300826) Signed-off-by: Paweł Gronowski --- .github/workflows/validate-pr.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/validate-pr.yml b/.github/workflows/validate-pr.yml index f7b43170d7..b39317005c 100644 --- a/.github/workflows/validate-pr.yml +++ b/.github/workflows/validate-pr.yml @@ -11,7 +11,7 @@ jobs: - name: Missing `area/` label if: contains(join(github.event.pull_request.labels.*.name, ','), 'impact/') && !contains(join(github.event.pull_request.labels.*.name, ','), 'area/') run: | - echo "Every PR with an \`impact/*\` label should also have an \`area/*\` label" + echo "::error::Every PR with an 'impact/*' label should also have an 'area/*' label" exit 1 - name: OK run: exit 0 @@ -32,13 +32,13 @@ jobs: desc=$(echo "$block" | awk NF) if [ -z "$desc" ]; then - echo "Changelog section is empty. Please provide a description for the changelog." + echo "::error::Changelog section is empty. Please provide a description for the changelog." exit 1 fi len=$(echo -n "$desc" | wc -c) if [[ $len -le 6 ]]; then - echo "Description looks too short: $desc" + echo "::error::Description looks too short: $desc" exit 1 fi