From b2548157c63142da3affb422c9cdc04f9b22b33e Mon Sep 17 00:00:00 2001 From: Parth Patel Date: Sat, 25 May 2024 12:20:49 +1200 Subject: [PATCH] Update pr-validation.yml --- .github/workflows/pr-validation.yml | 80 ++++++++++++++--------------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index a9ab5da..39d6765 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -2,7 +2,7 @@ name: "pr-validation" on: pull_request: - types: [opened, edited, reopened, synchronize] + types: [opened, edited, reopened, synchronize] jobs: validate: @@ -10,43 +10,41 @@ jobs: runs-on: ubuntu-latest steps: - name: Validate PR title - id: . - env: - REGEX: '^(fix|feat|chore)(!)?:\ .+' - run: | - PR_TITLE=$(jq -r .pull_request.title "$GITHUB_EVENT_PATH") - REGEX=$REGEX - DEPENDABOT_REGEX="^Bump\\s.+" - if [[ ! "$PR_TITLE" =~ $REGEX && ! "$PR_TITLE" =~ $DEPENDABOT_REGEX ]]; then - echo "Invalid PR title" - echo "PR_STATUS=false" >> $GITHUB_OUTPUT - exit 1 - else - echo "Valid PR title" - echo "PR_STATUS=true" >> $GITHUB_OUTPUT - fi - - - name: Update Status and Comment on PR - if: always() # Ensure this step runs regardless of previous success or failure - uses: actions/github-script@v6 - env: - REGEX: '^(fix|feat|chore)(!)?:\ .+' - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const regex = process.env.REGEX; - const context = "PR Title Validation"; - const state = ${{ steps.validation.output.PR_STATUS }} ? "success" : "failure"; - const description = ${{ steps.validation.output.PR_STATUS }} ? "PR title is valid." : `PR title is invalid. Ensure it matches the pattern: ${regex}`; - const prNumber = context.payload.pull_request.number; - const commitSha = context.payload.pull_request.head.sha; - - // Create a status check - await github.rest.repos.createCommitStatus({ - owner: context.repo.owner, - repo: context.repo.repo, - sha: commitSha, - state: state, - context: validate, - description: description - }); \ No newline at end of file + id: validation + env: + REGEX: '^(fix|feat|chore)(!)?:\ .+' + run: | + PR_TITLE=$(jq -r .pull_request.title "$GITHUB_EVENT_PATH") + REGEX=$REGEX + DEPENDABOT_REGEX="^Bump\\s.+" + if [[ ! "$PR_TITLE" =~ $REGEX && ! "$PR_TITLE" =~ $DEPENDABOT_REGEX ]]; then + echo "Invalid PR title" + echo "PR_STATUS=false" >> $GITHUB_OUTPUT + exit 1 + else + echo "Valid PR title" + echo "PR_STATUS=true" >> $GITHUB_OUTPUT + fi + - name: Update Status and Comment on PR + uses: actions/github-script@v6 + env: + REGEX: '^(fix|feat|chore)(!)?:\ .+' + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const regex = process.env.REGEX; + const context = "PR Title Validation"; + const state = ${{ steps.validation.output.PR_STATUS }} ? "success" : "failure"; + const description = ${{ steps.validation.output.PR_STATUS }} ? "PR title is valid." : `PR title is invalid. Ensure it matches the pattern: ${regex}`; + const prNumber = context.payload.pull_request.number; + const commitSha = context.payload.pull_request.head.sha; + + // Create a status check + await github.rest.repos.createCommitStatus({ + owner: context.repo.owner, + repo: context.repo.repo, + sha: commitSha, + state: state, + context: validate, + description: description + });