From c11da405450b912595b85ec40ae6a131f3c1c600 Mon Sep 17 00:00:00 2001 From: Jack Lynch Date: Thu, 5 Mar 2026 15:59:17 +0000 Subject: [PATCH] FDN-4581 Centralize github workflow definitions --- .github/workflows/auto-merge.yml | 54 +++++------------------------- .github/workflows/pr-validator.yml | 32 ++---------------- 2 files changed, 11 insertions(+), 75 deletions(-) diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml index b7c6c9b..c08b149 100644 --- a/.github/workflows/auto-merge.yml +++ b/.github/workflows/auto-merge.yml @@ -8,49 +8,13 @@ permissions: pull-requests: write jobs: - approve-and-merge: - runs-on: ubuntu-latest - if: ${{ github.event.state == 'success' && github.event.context == 'continuous-integration/jenkins/pr-merge' }} - steps: - - name: log jenkins context - run: | - echo "Context is: ${{ github.event.context }}" + auto-merge: + if: >- + ${{ github.event.state == 'success' && + (github.event.context == 'continuous-integration/jenkins/pr-head' || + github.event.context == 'continuous-integration/jenkins/pr-merge') }} + uses: flowcommerce/code-steward/.github/workflows/auto-merge.yml@main + with: + sha: ${{ github.event.sha }} + secrets: inherit - - name: find pull request for this commit - id: find_pr - run: | - REPO="${{ github.repository }}" - SHA="${{ github.event.sha }}" - - # find the PR associated with this commit - PR_JSON=$(gh pr list --repo "$REPO" --state open --json number,headRefName,labels,headRefOid) - PR_NUMBER=$(echo "$PR_JSON" | jq -r --arg sha "$SHA" '.[] | select(.headRefOid == $sha) | .number') - - if [ -z "$PR_NUMBER" ]; then - echo "No open PR found for commit $SHA, exiting.." - exit 0 - fi - - # check for auto-merge label - HAS_LABEL=$(echo "$PR_JSON" | jq -r --arg sha "$SHA" '.[] | select(.headRefOid == $sha) | .labels[].name' | grep -i '^auto-merge$' || true) - - if [ -z "$HAS_LABEL" ]; then - echo "PR #$PR_NUMBER has no 'auto-merge' label, exiting.." - exit 0 - fi - - echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: approve PR - if: ${{ steps.find_pr.outputs.pr_number != '' }} - run: gh pr review --approve "${{ steps.find_pr.outputs.pr_number }}" --repo "${{ github.repository }}" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: merge PR - if: ${{ steps.find_pr.outputs.pr_number != '' }} - run: gh pr merge --auto --squash "${{ steps.find_pr.outputs.pr_number }}" --repo "${{ github.repository }}" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pr-validator.yml b/.github/workflows/pr-validator.yml index f759c23..6879a59 100644 --- a/.github/workflows/pr-validator.yml +++ b/.github/workflows/pr-validator.yml @@ -2,35 +2,7 @@ name: "PR Title and Description Check" on: pull_request: types: [opened, edited, synchronize] - jobs: - check-title-and-description: - runs-on: ubuntu-latest - steps: - - name: Check PR title and description - uses: actions/github-script@v4 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const payload = context.payload; - const prTitle = payload.pull_request.title; - - // The pattern for JIRA ticket format - // Must be at the beginning of the PR title - // Prefix must be at least 3 uppercase letters - // Excludes tickets with only zeros after the prefix (e.g., XXX-000, XXX-0000) - // Number must be 3 to 6 digits - const jiraPattern = /^[A-Z]{3,}-(?!0+\b)\d{3,6}\b/; - - // Check PR title - const hasJiraTitle = jiraPattern.test(prTitle); - console.log(`PR title: ${hasJiraTitle ? 'Valid' : 'Invalid'}`); - - if (hasJiraTitle) { - console.log('PR title format is correct.'); - } else { - const errorMessage = 'The PR title must start with a valid JIRA ticket with 3-6 digits (e.g., ABC-123, DATAPLATFORM-12345). The ticket must be at the start, use at least 3 uppercase letters, and the number must not be all zeros.'; - console.log(errorMessage); + validate: + uses: flowcommerce/code-steward/.github/workflows/pr-validator.yml@main - core.setFailed(errorMessage); - }