|
20 | 20 | # Private actions must check out repo first. |
21 | 21 | - name: Checkout |
22 | 22 | uses: actions/checkout@v4 |
23 | | - - name: Verify PR title |
24 | | - uses: ./github-actions/verify-pr-title |
25 | | - id: verify_pr_title |
| 23 | + - name: Verify PR Title |
| 24 | + run: | |
| 25 | + title="${{ github.event.pull_request.title }}" |
| 26 | + title_upper=$(echo "$title" | tr '[:lower:]' '[:upper:]') |
| 27 | + base_ref="${{ github.base_ref }}" |
| 28 | +
|
| 29 | + # Define regex patterns for different types of PR titles |
| 30 | + MAIN2DEV_REGEX="^MAIN2DEV[[:space:]]*:?[[:space:]]*@W-[[:digit:]]{8,9}@.*MERGING.+[[:digit:]]{1,2}\.[[:digit:]]{1,2}\.[[:digit:]]{1,2}.*" |
| 31 | + RELEASE2MAIN_REGEX="^RELEASE[[:space:]]*:?[[:space:]]*@W-[[:digit:]]{8,9}@.+" |
| 32 | + PR_INTO_DEV_OR_RELEASE_REGEX="^(FIX|CHANGE|NEW)([[:space:]]*\([^)]+\))?[[:space:]]*:?[[:space:]]*@W-[[:digit:]]{8,9}@.+" |
| 33 | +
|
| 34 | + # Validate PR title based on base_ref and head_ref |
| 35 | + if [[ "$base_ref" == "dev" && "${{ startsWith(github.head_ref, 'm2d/') }}" == "true" ]]; then |
| 36 | + if [[ ! "$title_upper" =~ $MAIN2DEV_REGEX ]]; then |
| 37 | + echo "::error::Invalid PR title: '$title'. Please follow the format: Main2Dev @W-XXXXXXXX@ Merging.*\d+\.\d+\.\d+" |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | + elif [[ "$base_ref" == "main" ]]; then |
| 41 | + if [[ ! "$title_upper" =~ $RELEASE2MAIN_REGEX ]]; then |
| 42 | + echo "::error::Invalid PR title: '$title'. Please follow the format: RELEASE @W-XXXXXXXX@ Summary" |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | + elif [[ "$base_ref" == "dev" || "${{ startsWith(github.base_ref, 'release-') }}" == "true" ]]; then |
| 46 | + if [[ ! "$title_upper" =~ $PR_INTO_DEV_OR_RELEASE_REGEX ]]; then |
| 47 | + echo "::error::Invalid PR title: '$title'. Please follow the format: FIX|CHANGE|NEW (__) @W-XXXXXXXX@ Summary" |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | + else |
| 51 | + echo "PR title '$title' automatically accepted for $base_ref branch." |
| 52 | + fi |
| 53 | +
|
| 54 | + # If no errors, print success |
| 55 | + echo "Valid PR title: '$title'" |
26 | 56 | # Separately, we also need to run all of our tests. |
27 | 57 | run_tests: |
28 | 58 | uses: ./.github/workflows/run-tests.yml |
0 commit comments