From 4a6af7076663c2c37b4e9a856aaee659a4df0e0a Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Thu, 11 Dec 2025 15:00:54 -0500 Subject: [PATCH 1/4] wip --- .github/workflows/pr-title.yml | 96 ++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml index b365d4342ea..d195789b213 100644 --- a/.github/workflows/pr-title.yml +++ b/.github/workflows/pr-title.yml @@ -8,6 +8,96 @@ jobs: pr-title: runs-on: ubuntu-latest steps: - - uses: deepakputhraya/action-pr-title@master - with: - regex: '^\[\d+\.x\]\s' + - name: Validate PR title matches target branch + env: + PR_TITLE: ${{ github.event.pull_request.title }} + BASE_BRANCH: ${{ github.event.pull_request.base.ref }} + DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} + run: | + # Validates PR title against target branch + # Returns error message if invalid, empty string if valid + validate_pr_title() { + local target_branch="$1" + local pr_title="$2" + local default_branch="$3" + + # Check if target branch is a version branch (e.g., 5.x, 4.x) + if [[ $target_branch =~ ^([0-9]+)\.x$ ]]; then + local version="${BASH_REMATCH[1]}" + if [[ ! $pr_title =~ ^\[$version\.x\][[:space:]] ]]; then + echo "PR targeting '$target_branch' must have title starting with '[$version.x] '" + return + fi + + # Check if target branch is master (next major version) + elif [[ $target_branch == "master" ]]; then + if [[ $default_branch =~ ^([0-9]+)\.x$ ]]; then + local current_version="${BASH_REMATCH[1]}" + local next_version=$((current_version + 1)) + if [[ ! $pr_title =~ ^\[$next_version\.x\][[:space:]] ]]; then + echo "PR targeting 'master' must have title starting with '[$next_version.x] '" + return + fi + else + # Fallback: just check for any version prefix + if [[ ! $pr_title =~ ^\[[0-9]+\.x\][[:space:]] ]]; then + echo "PR title must start with a version prefix like '[6.x] '" + return + fi + fi + + # For other branches, just enforce that there's a version prefix + else + if [[ ! $pr_title =~ ^\[[0-9]+\.x\][[:space:]] ]]; then + echo "PR title must start with a version prefix like '[5.x] '" + return + fi + fi + + echo "" + } + + echo "PR Title: $PR_TITLE" + echo "Base Branch: $BASE_BRANCH" + echo "Default Branch: $DEFAULT_BRANCH" + echo "" + echo "=== TESTING SCENARIOS ===" + + # Test cases + declare -a test_cases=( + "5.x|[5.x] Fix bug" + "5.x|[4.x] Fix bug" + "5.x|[6.x] Fix bug" + "master|[6.x] New feature" + "master|[5.x] New feature" + "master|[7.x] New feature" + "feature-branch|[5.x] Something" + "feature-branch|[99.x] Something" + "feature-branch|No prefix" + ) + + for test_case in "${test_cases[@]}"; do + IFS='|' read -r test_branch test_title <<< "$test_case" + error=$(validate_pr_title "$test_branch" "$test_title" "$DEFAULT_BRANCH") + + if [[ -z $error ]]; then + echo "✅ PASS: $test_branch -> '$test_title'" + else + echo "❌ FAIL: $test_branch -> '$test_title'" + echo " Error: $error" + fi + done + + echo "=========================" + echo "" + + # Actual validation + ERROR=$(validate_pr_title "$BASE_BRANCH" "$PR_TITLE" "$DEFAULT_BRANCH") + + if [[ -n $ERROR ]]; then + echo "❌ Error: $ERROR" + echo " Your title: $PR_TITLE" + exit 1 + fi + + echo "✅ PR title validation passed" From 1e8481357db90770d64490a281e4cbb4846cc14c Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Thu, 11 Dec 2025 15:20:43 -0500 Subject: [PATCH 2/4] wip --- .github/workflows/pr-title.yml | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml index d195789b213..ee887f96417 100644 --- a/.github/workflows/pr-title.yml +++ b/.github/workflows/pr-title.yml @@ -31,19 +31,11 @@ jobs: # Check if target branch is master (next major version) elif [[ $target_branch == "master" ]]; then - if [[ $default_branch =~ ^([0-9]+)\.x$ ]]; then - local current_version="${BASH_REMATCH[1]}" - local next_version=$((current_version + 1)) - if [[ ! $pr_title =~ ^\[$next_version\.x\][[:space:]] ]]; then - echo "PR targeting 'master' must have title starting with '[$next_version.x] '" - return - fi - else - # Fallback: just check for any version prefix - if [[ ! $pr_title =~ ^\[[0-9]+\.x\][[:space:]] ]]; then - echo "PR title must start with a version prefix like '[6.x] '" - return - fi + local current_version="${default_branch//\.x/}" + local next_version=$((current_version + 1)) + if [[ ! $pr_title =~ ^\[$next_version\.x\][[:space:]] ]]; then + echo "PR targeting 'master' must have title starting with '[$next_version.x] '" + return fi # For other branches, just enforce that there's a version prefix From 51c53e4524f3db87b056e5c04615d51ada5f5bf2 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Thu, 11 Dec 2025 15:22:43 -0500 Subject: [PATCH 3/4] wip --- .github/workflows/pr-title.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml index ee887f96417..971cdc49794 100644 --- a/.github/workflows/pr-title.yml +++ b/.github/workflows/pr-title.yml @@ -87,9 +87,6 @@ jobs: ERROR=$(validate_pr_title "$BASE_BRANCH" "$PR_TITLE" "$DEFAULT_BRANCH") if [[ -n $ERROR ]]; then - echo "❌ Error: $ERROR" - echo " Your title: $PR_TITLE" + echo $ERROR exit 1 fi - - echo "✅ PR title validation passed" From 30f1628d2002f9fbb42b19338809e7ca44bdc576 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Thu, 11 Dec 2025 15:24:06 -0500 Subject: [PATCH 4/4] wip --- .github/workflows/pr-title.yml | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml index 971cdc49794..a4ecda7248a 100644 --- a/.github/workflows/pr-title.yml +++ b/.github/workflows/pr-title.yml @@ -52,41 +52,12 @@ jobs: echo "PR Title: $PR_TITLE" echo "Base Branch: $BASE_BRANCH" echo "Default Branch: $DEFAULT_BRANCH" - echo "" - echo "=== TESTING SCENARIOS ===" - # Test cases - declare -a test_cases=( - "5.x|[5.x] Fix bug" - "5.x|[4.x] Fix bug" - "5.x|[6.x] Fix bug" - "master|[6.x] New feature" - "master|[5.x] New feature" - "master|[7.x] New feature" - "feature-branch|[5.x] Something" - "feature-branch|[99.x] Something" - "feature-branch|No prefix" - ) - - for test_case in "${test_cases[@]}"; do - IFS='|' read -r test_branch test_title <<< "$test_case" - error=$(validate_pr_title "$test_branch" "$test_title" "$DEFAULT_BRANCH") - - if [[ -z $error ]]; then - echo "✅ PASS: $test_branch -> '$test_title'" - else - echo "❌ FAIL: $test_branch -> '$test_title'" - echo " Error: $error" - fi - done - - echo "=========================" - echo "" - - # Actual validation ERROR=$(validate_pr_title "$BASE_BRANCH" "$PR_TITLE" "$DEFAULT_BRANCH") if [[ -n $ERROR ]]; then echo $ERROR exit 1 fi + + echo "PR title validation passed"