Repository: paritytech/polkadot-sdk
Pull request #8435: [CI] Adjust `check-semver` job so that it uses original PR number to check prdoc for the backports PRs
Author: login: EgorPopelyaev
Labels: name: R0-no-crate-publish-required
description: The change does not require any crates to be re-published.
Created: 2025-05-06T07:07:01Z | Merged: 2025-05-06T08:45:43Z

This PR makes the same adjustment, that was done for the `check-prdoc` job:
- In the backports PRs will be used original PR number to check the prdoc and introduced changes


Diff:
diff --git a/.github/scripts/common/lib.sh b/.github/scripts/common/lib.sh
index 97530bfdc905c..6de936c6a5b34 100755
--- a/.github/scripts/common/lib.sh
+++ b/.github/scripts/common/lib.sh
@@ -539,3 +539,18 @@ parse_branch_names_from_backport_labels() {
   BRANCHES=$(echo "$BRANCHES" | sed 's/^ *//')
   echo "$BRANCHES"
 }
+
+# Extract the PR number from the PR title
+#
+# input: PR_TITLE
+# output: PR_NUMBER or exit 1 if the PR title does not contain the PR number
+extract_pr_number_from_pr_title() {
+  PR_TITLE=$1
+  if [[ "$PR_TITLE" =~ \#([0-9]+) ]]; then
+    PR_NUMBER="${BASH_REMATCH[1]}"
+  else
+    echo "⚠️ The PR title does not contain original PR number. PR title should be in form: [stableBranchName] Backport #originalPRNumber"
+    exit 1
+  fi
+  echo $PR_NUMBER
+}
diff --git a/.github/workflows/check-prdoc.yml b/.github/workflows/check-prdoc.yml
index 8efcb44b83b55..803d096d8f4c7 100644
--- a/.github/workflows/check-prdoc.yml
+++ b/.github/workflows/check-prdoc.yml
@@ -47,24 +47,21 @@ jobs:
           echo "Labels: ${labels}"
           echo "labels=${labels}" >> "$GITHUB_OUTPUT"
 
-      - name: Get PR number
+      - name: Get Original PR number
         if: ${{ github.event.pull_request.number != '' && !contains(steps.get-labels.outputs.labels, 'R0') }}
+        shell: bash
         env:
           PR_TITLE: ${{ github.event.pull_request.title }}
         run: |
+          . ./.github/scripts/common/lib.sh
           original_pr_number=''
 
           echo "Checking PR title: $PR_TITLE"
 
           if [[ "$PR_TITLE" =~ 'Backport' ]]; then
             # Extracting the original PR number from the backport's PR title
-            if [[ "$PR_TITLE" =~ \#([0-9]+) ]]; then
-              original_pr_number="${BASH_REMATCH[1]}"
-              echo "Extracted PR number: $original_pr_number"
-            else
-              echo "⚠️ The PR title does not contain original PR number. PR title should be in form: [stableBranchName] Backport #originalPRNumber"
-              exit 1
-            fi
+            original_pr_number=$(extract_pr_number_from_pr_title "$PR_TITLE")
+            echo "Extracted PR number: $original_pr_number"
           else
             original_pr_number=${{ github.event.pull_request.number }}
           fi
diff --git a/.github/workflows/check-semver.yml b/.github/workflows/check-semver.yml
index 958a1590bd248..e7876880b6fb5 100644
--- a/.github/workflows/check-semver.yml
+++ b/.github/workflows/check-semver.yml
@@ -82,13 +82,36 @@ jobs:
           rustup target add wasm32-unknown-unknown --toolchain $TOOLCHAIN
           rustup component add rust-src --toolchain $TOOLCHAIN
 
-      - name: install parity-publish
+      - name: Install parity-publish
         if: ${{ !contains(github.event.pull_request.labels.*.name, 'R0-silent') }}
         # Set the target dir to cache the build.
         run: CARGO_TARGET_DIR=./target/ cargo install parity-publish@0.10.4 --locked -q
 
-      - name: check semver
+      - name: Get original PR number
         if: ${{ !contains(github.event.pull_request.labels.*.name, 'R0-silent') }}
+        shell: bash
+        env:
+          PR_TITLE: ${{ github.event.pull_request.title }}
+        run: |
+          . ./.github/scripts/common/lib.sh
+          original_pr_number=''
+
+          echo "Checking PR title: $PR_TITLE"
+
+          if [[ "$PR_TITLE" =~ 'Backport' ]]; then
+            # Extracting the original PR number from the backport's PR title
+            original_pr_number=$(extract_pr_number_from_pr_title "$PR_TITLE")
+            echo "Extracted PR number: $original_pr_number"
+          else
+            original_pr_number=${{ github.event.pull_request.number }}
+          fi
+          echo "PR_NUMBER=$original_pr_number" >> $GITHUB_ENV
+
+      - name: Check semver
+        if: ${{ !contains(github.event.pull_request.labels.*.name, 'R0-silent') }}
+        env:
+          PRDOC_EXTRA_ARGS: ${{ env.PRDOC_EXTRA_ARGS }}
+          PR: ${{ env.PR_NUMBER }}
         run: |
           if [ -z "$PR" ]; then
             echo "Skipping master/merge queue"
@@ -113,6 +136,3 @@ jobs:
 
             exit 1
           fi
-        env:
-          PR: ${{ github.event.pull_request.number }}
-          PRDOC_EXTRA_ARGS: ${{ env.PRDOC_EXTRA_ARGS }}


Reviews:
user: login: BulatSaif
state: COMMENTED
author_association: NONE
submitted_at: 2025-05-06T07:14:40Z
user: login: BulatSaif
state: COMMENTED
author_association: NONE
submitted_at: 2025-05-06T07:20:05Z
user: login: BulatSaif
state: APPROVED
author_association: NONE
submitted_at: 2025-05-06T07:20:09Z
user: login: EgorPopelyaev
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-06T07:27:34Z
user: login: alvicsam
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-05-06T08:09:24Z

Review comments:
diff_hunk: @@ -539,3 +539,18 @@ parse_branch_names_from_backport_labels() {
   BRANCHES=$(echo "$BRANCHES" | sed 's/^ *//')
   echo "$BRANCHES"
 }
+
+# Extract the PR number from the PR title
+#
+# input: PR_TITLE
+# output: PR_NUMBER or exit 1 if the PR title does not contain the PR number
+extract_pr_number_from_pr_title() {
+  PR_TITLE=$1
+  if [[ "$PR_TITLE" =~ \#([0-9]+) ]]; then
path: .github/scripts/common/lib.sh
user: login: BulatSaif
body: Your script is written with a `#!/bin/sh` shebang, but you're using Bash-specific syntax `[[ ... =~ ... ]]` and `BASH_REMATCH`, which is not supported by `/bin/sh` on many systems
created_at: 2025-05-06T07:14:40Z
author_association: NONE
diff_hunk: @@ -539,3 +539,18 @@ parse_branch_names_from_backport_labels() {
   BRANCHES=$(echo "$BRANCHES" | sed 's/^ *//')
   echo "$BRANCHES"
 }
+
+# Extract the PR number from the PR title
+#
+# input: PR_TITLE
+# output: PR_NUMBER or exit 1 if the PR title does not contain the PR number
+extract_pr_number_from_pr_title() {
+  PR_TITLE=$1
+  if [[ "$PR_TITLE" =~ \#([0-9]+) ]]; then
path: .github/scripts/common/lib.sh
user: login: BulatSaif
body: False alarm, I saw that you source this file with `. ./.github/scripts/common/lib.sh`, so the shebang won’t have any effect. But I still recommend considering an update to the shebangs.
created_at: 2025-05-06T07:20:05Z
author_association: NONE
diff_hunk: @@ -539,3 +539,18 @@ parse_branch_names_from_backport_labels() {
   BRANCHES=$(echo "$BRANCHES" | sed 's/^ *//')
   echo "$BRANCHES"
 }
+
+# Extract the PR number from the PR title
+#
+# input: PR_TITLE
+# output: PR_NUMBER or exit 1 if the PR title does not contain the PR number
+extract_pr_number_from_pr_title() {
+  PR_TITLE=$1
+  if [[ "$PR_TITLE" =~ \#([0-9]+) ]]; then
path: .github/scripts/common/lib.sh
user: login: EgorPopelyaev
body: Yeah, I was thinking about it, will do it in the follow-up PR, as it will need extended testing, cause this script is used in different CI flows
created_at: 2025-05-06T07:27:33Z
author_association: CONTRIBUTOR

PR comments:
user: login: paritytech-release-backport-bot[bot]
created_at: 2025-05-06T08:46:33Z
body: Created backport PR for `stable2409`:
- #8437 with remaining conflicts!

Please cherry-pick the changes locally and resolve any conflicts.
```bash
git fetch origin backport-8435-to-stable2409
git worktree add --checkout .worktree/backport-8435-to-stable2409 backport-8435-to-stable2409
cd .worktree/backport-8435-to-stable2409
git reset --hard HEAD^
git cherry-pick -x bf1ca6f537a996d27a2261562d774ba3a8ce3e04
git push --force-with-lease
```
author_association: NONE
user: login: paritytech-release-backport-bot[bot]
created_at: 2025-05-06T08:46:40Z
body: Created backport PR for `stable2412`:
- #8438 with remaining conflicts!

Please cherry-pick the changes locally and resolve any conflicts.
```bash
git fetch origin backport-8435-to-stable2412
git worktree add --checkout .worktree/backport-8435-to-stable2412 backport-8435-to-stable2412
cd .worktree/backport-8435-to-stable2412
git reset --hard HEAD^
git cherry-pick -x bf1ca6f537a996d27a2261562d774ba3a8ce3e04
git push --force-with-lease
```
author_association: NONE
user: login: paritytech-release-backport-bot[bot]
created_at: 2025-05-06T08:46:46Z
body: Created backport PR for `stable2503`:
- #8439 with remaining conflicts!

Please cherry-pick the changes locally and resolve any conflicts.
```bash
git fetch origin backport-8435-to-stable2503
git worktree add --checkout .worktree/backport-8435-to-stable2503 backport-8435-to-stable2503
cd .worktree/backport-8435-to-stable2503
git reset --hard HEAD^
git cherry-pick -x bf1ca6f537a996d27a2261562d774ba3a8ce3e04
git push --force-with-lease
```
author_association: NONE