Skip to content
66 changes: 51 additions & 15 deletions .github/workflows/validatePR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,45 @@ jobs:
if: ${{ !contains(github.event.pull_request.body, '[skip-validate-pr]') && !contains(github.event.pull_request.title, '[skip-validate-pr]') }}
runs-on: "ubuntu-latest"
steps:
- name: Find GUS Work Item in Title
uses: kaisugi/action-regex-match@45cc5bacf016a4c0d2c3c9d0f8b7c2f1b79687b8
id: regex-match-gus-wi-title
- name: Validate Overall PR Shape
uses: kaisugi/action-regex-match@main
id: pr-title-shape-regex
with:
text: ${{ github.event.pull_request.title }}
regex: 'W-\d{7,8}'
regex: '^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)\s?(\(.+\))?: .+ \((W-\d{7,})\)$'
flags: gmi

- name: Find GUS Work Item in Body
uses: kaisugi/action-regex-match@45cc5bacf016a4c0d2c3c9d0f8b7c2f1b79687b8
id: regex-match-gus-wi-body
- name: Check Title for type
uses: kaisugi/action-regex-match@main
id: pr-title-type-subportion-regex
with:
text: ${{ github.event.pull_request.title }}
regex: '^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)'
flags: gmi

- name: Check Title for Work Item
uses: kaisugi/action-regex-match@main
id: pr-title-work-item-subportion-regex
with:
text: ${{ github.event.pull_request.title }}
regex: ' \((W-\d{7,})\)$'
flags: gmi

- name: Validate Pull Request Body
uses: kaisugi/action-regex-match@main
id: pr-body-work-item-subportion-regex
with:
text: ${{ github.event.pull_request.body }}
regex: '@W-\d{7,8}@'
regex: '@(${{ steps.pr-title-work-item-subportion-regex.outputs.match }})@'
flags: gmi

- name: echo match parts to double-check expectations
run: |
echo "title shape match: '${{ steps.pr-title-shape-regex.outputs.match }}'"
echo "title type match: '${{ steps.pr-title-type-subportion-regex.outputs.match }}'"
echo "title work item match: '${{ steps.pr-title-work-item-subportion-regex.outputs.match }}'"
echo "body work item match: '${{ steps.pr-body-work-item-subportion-regex.outputs.match }}'"

# Disabling GHA Run and Github Issue (for now) due to E360 lookup

# - name: Find Github Action Run
Expand All @@ -39,15 +62,28 @@ jobs:
# regex: 'forcedotcom\/cli\/issues\/[0-9]+|forcedotcom\/salesforcedx-vscode\/issues\/[0-9]+'
# flags: gm

- name: Fail if no Work Item references
- name: Fail if format requirements not met
if: |
github.event.pull_request.user.login != 'dependabot[bot]' &&
(github.event.pull_request.user.login != 'SF-CLI-BOT' || github.event.pull_request.user.login != 'svc-cli-bot') &&
(steps.regex-match-gus-wi-title.outputs.match == '' || steps.regex-match-gus-wi-body.outputs.match == '')
(steps.pr-title-shape-regex.outputs.match == '' || steps.pr-body-work-item-subportion-regex.outputs.match == '')
run: |
echo "::warning::PRs need to reference a GUS Work Item in both the PR title AND body. More details in the logs above.
- PR titles should start with a Work Item followed by a description, ex: W-12345678: My PR title
- PR bodies must include a Work Item wrapped in @s, ex: @W-12345678@ or [@W-12345678@](https://some-url)
- If you absolutely must skip this validation, add [skip-validate-pr] to the PR title or body"
# Define a checkmark and an x-mark as variables.
PASS=$'\u2714'
FAIL=$'\u2715'

# Determine which criteria were and were not met based on the outputs we captured
[[ '${{ steps.pr-title-shape-regex.outputs.match }}' == '' ]] && TITLE_SHAPE=$FAIL || TITLE_SHAPE=$PASS
[[ '${{ steps.pr-title-type-subportion-regex.outputs.match }}' == '' ]] && TITLE_TYPE=$FAIL || TITLE_TYPE=$PASS
[[ '${{ steps.pr-title-work-item-subportion-regex.outputs.match }}' == '' ]] && TITLE_WORK_ITEM=$FAIL || TITLE_WORK_ITEM=$PASS
[[ '${{ steps.pr-body-work-item-subportion-regex.outputs.match }}' == '' ]] && BODY_WORK_ITEM=$FAIL || BODY_WORK_ITEM=$PASS

# Output the criteria summary
echo "::warning::PR titles and bodies must meet the specified criteria.
- [$TITLE_SHAPE] PR title must be well-formed (i.e., match '<type>(<optional-scope>): <description> (W-XXXXXXX)')
(example: feat: add Angular template support (W-12345678); fix(auth): resolve token refresh issue (W-12345678)
- [$TITLE_TYPE] <type> subportion must be one of: feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert
- [$TITLE_WORK_ITEM] Must end with work item number wrapped in parentheses
- [$BODY_WORK_ITEM] PR body must include work item from title, wrapped in '@'s, ex: @W-1234567@ or [@W-1234567](https://some-url)
If you ABSOLUTELY MUST bypass these validations, include '[skip-validate-pr]' in the PR title or body"
exit 1