From 72615b19dbe7635d99914c044e03debf61fe70ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Thu, 28 Mar 2024 10:27:26 +0100 Subject: [PATCH] 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 Signed-off-by: Paweł Gronowski (cherry picked from commit 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 491d15c349c38..b39317005c1b3 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