From e9470c8d3288f9384ebf2c76f34f8f558ec204ce Mon Sep 17 00:00:00 2001 From: Jack Spagnoli <114365987+JackSpagnoliNHS@users.noreply.github.com> Date: Tue, 23 Jan 2024 15:55:56 +0000 Subject: [PATCH] renames, updates pr title access --- ...bot-prs.yml => combine_dependabot_prs.yml} | 22 +++++++++---------- ... => dependabot_auto_approve_and_merge.yml} | 2 +- .../workflows/{pr-link.yml => pr_link.yml} | 0 .github/workflows/pr_title_check.yml | 15 +++++++++++-- .github/workflows/pull_request.yml | 6 ++++- ...abot-prs.yml => rename_dependabot_prs.yml} | 15 ++++++++----- 6 files changed, 40 insertions(+), 20 deletions(-) rename .github/workflows/{combine-dependabot-prs.yml => combine_dependabot_prs.yml} (93%) rename .github/workflows/{dependabot-auto-approve_and_merge.yml => dependabot_auto_approve_and_merge.yml} (99%) rename .github/workflows/{pr-link.yml => pr_link.yml} (100%) rename .github/workflows/{rename-dependabot-prs.yml => rename_dependabot_prs.yml} (77%) diff --git a/.github/workflows/combine-dependabot-prs.yml b/.github/workflows/combine_dependabot_prs.yml similarity index 93% rename from .github/workflows/combine-dependabot-prs.yml rename to .github/workflows/combine_dependabot_prs.yml index 1cd74d1..284ede2 100644 --- a/.github/workflows/combine-dependabot-prs.yml +++ b/.github/workflows/combine_dependabot_prs.yml @@ -1,25 +1,25 @@ -name: 'Combine PRs' +name: "Combine PRs" # Controls when the action will run - in this case triggered manually on: workflow_dispatch: inputs: branchPrefix: - description: 'Branch prefix to find combinable PRs based on' + description: "Branch prefix to find combinable PRs based on" required: true - default: 'dependabot' + default: "dependabot" mustBeGreen: - description: 'Only combine PRs that are green (status is success)' + description: "Only combine PRs that are green (status is success)" required: true default: "true" combineBranchName: - description: 'Name of the branch to combine PRs into' + description: "Name of the branch to combine PRs into" required: true - default: 'combine-dependabot-PRs' + default: "combine-dependabot-PRs" ignoreLabel: - description: 'Exclude PRs with this label' + description: "Exclude PRs with this label" required: true - default: 'nocombine' + default: "nocombine" # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: @@ -115,7 +115,7 @@ jobs: core.setFailed('Failed to create combined branch - maybe a branch by that name already exists?'); return; } - + let combinedPRs = []; let mergeFailedPRs = []; for(const { branch, prString } of branchesAndPRStrings) { @@ -133,7 +133,7 @@ jobs: mergeFailedPRs.push(prString); } } - + console.log('Creating combined PR'); const combinedPRsString = combinedPRs.join('\n'); let body = '✅ This PR was created by the Combine PRs action by combining the following PRs:\n' + combinedPRsString; @@ -148,4 +148,4 @@ jobs: head: '${{ github.event.inputs.combineBranchName }}', base: baseBranch, body: body - }); \ No newline at end of file + }); diff --git a/.github/workflows/dependabot-auto-approve_and_merge.yml b/.github/workflows/dependabot_auto_approve_and_merge.yml similarity index 99% rename from .github/workflows/dependabot-auto-approve_and_merge.yml rename to .github/workflows/dependabot_auto_approve_and_merge.yml index b980a68..9e4b62f 100644 --- a/.github/workflows/dependabot-auto-approve_and_merge.yml +++ b/.github/workflows/dependabot_auto_approve_and_merge.yml @@ -47,4 +47,4 @@ jobs: env: PR_URL: ${{github.event.pull_request.html_url}} GITHUB_TOKEN: ${{ steps.get_app_token.outputs.token }} - \ No newline at end of file + diff --git a/.github/workflows/pr-link.yml b/.github/workflows/pr_link.yml similarity index 100% rename from .github/workflows/pr-link.yml rename to .github/workflows/pr_link.yml diff --git a/.github/workflows/pr_title_check.yml b/.github/workflows/pr_title_check.yml index bdf87a7..cbcd4d1 100644 --- a/.github/workflows/pr_title_check.yml +++ b/.github/workflows/pr_title_check.yml @@ -1,15 +1,26 @@ name: Quality Checks on: + # Will be null if PR title was not updated workflow_call: + inputs: + PR_TITLE: + required: true + type: string jobs: pr_title_format_check: runs-on: ubuntu-latest steps: + # If PR title was not updated by the dependabot prefixer, set PR_TITLE variable to PR title + - name: Set Up-to-date PR Title + if: ${{ !env.PR_TITLE }} + run: | + echo "PR_TITLE=${{ github.event.pull_request.title }}" >> $GITHUB_ENV + - name: Check PR Title is Prefixed with Change Type run: | - if [[ "${{ github.event.pull_request.title }}" =~ ^(Fix|Update|New|Breaking|Docs|Build|Upgrade|Chore):.*$ ]]; then + if [[ "${{ env.PR_TITLE }}" =~ ^(Fix|Update|New|Breaking|Docs|Build|Upgrade|Chore):.*$ ]]; then echo "PR title is prefixed with change type." else echo "PR title is not prefixed with change type." @@ -21,7 +32,7 @@ jobs: - name: Check PR Title contains Ticket/Dependabot Reference run: | - if [[ "${{ github.event.pull_request.title }}" =~ ^.*:.*\[(AEA-[0-9]{4}|dependabot)\].*-.*$ ]]; then + if [[ "${{ env.PR_TITLE }}" =~ ^.*:.*\[(AEA-[0-9]{4}|dependabot)\].*-.*$ ]]; then echo "PR title contains ticket or dependabot reference." else echo "PR title does not contain ticket or dependabot reference." diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 520a657..3fc5f1b 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -6,9 +6,10 @@ on: jobs: dependabot_prefix_title: - uses: ./.github/workflows/rename-dependabot-prs.yml + uses: ./.github/workflows/rename_dependabot_prs.yml quality_checks: + needs: dependabot_prefix_title uses: ./.github/workflows/quality_checks.yml with: BRANCH_NAME: ${{ github.event.pull_request.head.ref }} @@ -18,3 +19,6 @@ jobs: pr_title_format_check: needs: dependabot_prefix_title uses: ./.github/workflows/pr_title_check.yml + with: + # Will be null if PR title was not updated + PR_TITLE: ${{ needs.dependabot_prefix_title.outputs.updated_pr_title }} diff --git a/.github/workflows/rename-dependabot-prs.yml b/.github/workflows/rename_dependabot_prs.yml similarity index 77% rename from .github/workflows/rename-dependabot-prs.yml rename to .github/workflows/rename_dependabot_prs.yml index ab27e42..24e3931 100644 --- a/.github/workflows/rename-dependabot-prs.yml +++ b/.github/workflows/rename_dependabot_prs.yml @@ -34,24 +34,29 @@ jobs: run: | if [[ "${{ env.PR_IS_DEPENDABOT }}" == "true" && "${{ env.PR_IS_PREFIXED }}" == "false" ]]; then echo "PR title should be updated." - echo "PR_TITLE_SHOULD_BE_UPDATED=true" >> $GITHUB_ENV + echo "PR_UPDATED_TITLE=Chore: [dependabot] - ${{ github.event.pull_request.title }}" >> $GITHUB_ENV else echo "PR title should not be updated." echo "No change to PR title." fi - name: Update PR title with Prefix - if: env.PR_TITLE_SHOULD_BE_UPDATED == 'true' + if: env.PR_UPDATED_TITLE uses: actions/github-script@v7.0.1 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const new_title = `Chore: [dependabot] - ${{ github.event.pull_request.title }}` - console.log(`Updating PR title to: ${new_title}`) + console.log(`Updating PR title to: ${{ env.PR_UPDATED_TITLE }}`) github.rest.pulls.update({ owner: context.repo.owner, repo: context.repo.repo, pull_number: context.issue.number, - title: new_title + title: ${{ env.PR_UPDATED_TITLE }} }) + + - name: Set Updated PR Title as Output + if: env.PR_UPDATED_TITLE + id: set_updated_pr_title_output + run: | + echo "::set-output name=updated_pr_title::${{ env.PR_UPDATED_TITLE }}"