diff --git a/.github/workflows/.common-pr-check.yml b/.github/workflows/.common-pr-check.yml deleted file mode 100644 index 8c4fbe2..0000000 --- a/.github/workflows/.common-pr-check.yml +++ /dev/null @@ -1,73 +0,0 @@ -on: - workflow_call: - -jobs: - check-pr: - if: ${{ vars.PR_POLICY_TITLE_PATTERN && vars.PR_POLICY_TITLE_PATTERN != '' }} - runs-on: ubuntu-latest - permissions: - pull-requests: write - - steps: - - name: Match Title - uses: actions-ecosystem/action-regex-match@v2 - id: title-pattern - with: - text: ${{ github.event.pull_request.title }} - regex: '${{ vars.PR_POLICY_TITLE_PATTERN }}' - - - name: Validate Title - id: title-pattern-check - shell: bash - run: | - if [[ "${{ steps.title-pattern.outputs.match }}" == "" ]]; then - exit 1 - fi - - - name: Report Invalid Title - if: failure() && steps.title-pattern-check.outcome == 'failure' - uses: actions/github-script@v7 - with: - script: | - const prComments = await github.rest.issues.listComments({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo - }); - - let existingCommentId = null; - - for (const comment of prComments.data) { - if ((comment.user.type == "Bot") && (comment.body.indexOf("ref: policy-pr-title") >= 0)) { - existingCommentId = comment.id; - break; - } - } - - let commentBody = `Please update your pull request title to the required format: - - **RegEx** - \`\`\` - ${{ vars.PR_POLICY_TITLE_PATTERN }} - \`\`\` - - --- - - ref: policy-pr-title - `; - - if (existingCommentId) { - github.rest.issues.updateComment({ - comment_id: existingCommentId, - owner: context.repo.owner, - repo: context.repo.repo, - body: commentBody - }); - } else { - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: commentBody - }); - } diff --git a/.github/workflows/policy-check.yml b/.github/workflows/policy-check.yml new file mode 100644 index 0000000..4d035d8 --- /dev/null +++ b/.github/workflows/policy-check.yml @@ -0,0 +1,79 @@ + +name: Policy Check + +on: + workflow_call: + +jobs: + + pr-title-check: + if: ${{ vars.PR_POLICY_TITLE_PATTERN && vars.PR_POLICY_TITLE_PATTERN != '' }} + runs-on: ubuntu-latest + permissions: + pull-requests: write + + steps: + - name: Match Title + uses: actions-ecosystem/action-regex-match@v2 + id: title-pattern + with: + text: ${{ github.event.pull_request.title }} + regex: '${{ vars.PR_POLICY_TITLE_PATTERN }}' + + - name: Validate Title + id: title-pattern-check + shell: bash + run: | + if [[ "${{ steps.title-pattern.outputs.match }}" == "" ]]; then + exit 1 + fi + + - name: Report Invalid Title + if: failure() && steps.title-pattern-check.outcome == 'failure' + uses: actions/github-script@v7 + with: + script: | + const prComments = await github.rest.issues.listComments({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo + }); + + let existingCommentId = null; + + for (const comment of prComments.data) { + if ((comment.user.type == "Bot") && (comment.body.indexOf("ref: policy-pr-title") >= 0)) { + existingCommentId = comment.id; + break; + } + } + + let commentBody = `Please update your pull request title to the required format: + + **RegEx Format** + \`\`\` + ${{ vars.PR_POLICY_TITLE_PATTERN }} + \`\`\` + + **Simplified explanation** + \`\`\` + {the 7 digit issue number}: {a short one line summary of the PR} + \`\`\` + --- + `; + + if (existingCommentId) { + github.rest.issues.updateComment({ + comment_id: existingCommentId, + owner: context.repo.owner, + repo: context.repo.repo, + body: commentBody + }); + } else { + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: commentBody + }); + } diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index c35bac3..5baf877 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -4,19 +4,16 @@ on: branches: - 'main' types: [ opened, reopened, edited, synchronize ] - push: - branches: - - 'main' jobs: - # TODO: remove check-pr job once template no longer enforces job. - check-pr: - uses: ./.github/workflows/.common-pr-check.yml - permissions: - pull-requests: write - + build: uses: ./.github/workflows/build.yml test: uses: ./.github/workflows/test.yml + + policy-check: + uses: ./.github/workflows/policy-check.yml + permissions: + pull-requests: write