From 8be757e7689b1c193fd6c575820c11c979903b2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 16 Aug 2021 15:47:54 +0200 Subject: [PATCH] Enhancement: Restore auto-merge of dependabot pull requests --- .github/CONTRIBUTING.md | 1 + .github/settings.yml | 4 -- .github/workflows/integrate.yaml | 94 -------------------------------- .github/workflows/merge.yaml | 93 +++++++++++++++++++++++++++++++ README.md | 1 + 5 files changed, 95 insertions(+), 98 deletions(-) create mode 100644 .github/workflows/merge.yaml diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index d0d33d0b..8186f37d 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -5,6 +5,7 @@ We are using [GitHub Actions](https://github.com/features/actions) as a continuo For details, take a look at the following workflow configuration files: - [`workflows/integrate.yaml`](workflows/integrate.yaml) +- [`workflows/merge.yaml`](workflows/merge.yaml) - [`workflows/prune.yaml`](workflows/prune.yaml) - [`workflows/release.yaml`](workflows/release.yaml) - [`workflows/renew.yaml`](workflows/renew.yaml) diff --git a/.github/settings.yml b/.github/settings.yml index 71c97f04..6ec4e20c 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -60,10 +60,6 @@ labels: color: "0e8a16" description: "" - - name: "merge" - color: "6f42c1" - description: "" - - name: "question" color: "cc317c" description: "" diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index 52625212..af1209cf 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -333,97 +333,3 @@ jobs: - name: "Run mutation tests with pcov and infection/infection" run: "vendor/bin/infection --ignore-msi-with-no-mutations --min-covered-msi=${{ env.MIN_COVERED_MSI }} --min-msi=${{ env.MIN_MSI }}" - - merge: - name: "Merge" - - runs-on: "ubuntu-latest" - - needs: - - "code-coverage" - - "coding-standards" - - "dependency-analysis" - - "mutation-tests" - - "static-code-analysis" - - "tests" - - if: > - github.event_name == 'pull_request' && - github.event.pull_request.draft == false && ( - github.event.action == 'opened' || - github.event.action == 'reopened' || - github.event.action == 'synchronize' - ) && ( - (github.actor == 'dependabot[bot]' && startsWith(github.event.pull_request.title, 'composer(deps-dev)')) || - (github.actor == 'dependabot[bot]' && startsWith(github.event.pull_request.title, 'github-actions(deps)')) || - (github.actor == 'localheinz' && contains(github.event.pull_request.labels.*.name, 'merge')) - ) - - steps: - - name: "Request review from @ergebnis-bot" - uses: "actions/github-script@v4.0.2" - with: - github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" - script: | - const pullRequest = context.payload.pull_request - const repository = context.repo - - const reviewers = [ - "ergebnis-bot", - ] - - await github.pulls.requestReviewers({ - owner: repository.owner, - pull_number: pullRequest.number, - repo: repository.repo, - reviewers: reviewers, - }) - - - name: "Assign @ergebnis-bot" - uses: "actions/github-script@v4.0.2" - with: - github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" - script: | - const pullRequest = context.payload.pull_request - const repository = context.repo - - const assignees = [ - "ergebnis-bot", - ] - - await github.issues.addAssignees({ - assignees: assignees, - issue_number: pullRequest.number, - owner: repository.owner, - repo: repository.repo, - }) - - - name: "Approve pull request" - uses: "actions/github-script@v4.0.2" - with: - github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" - script: | - const pullRequest = context.payload.pull_request - const repository = context.repo - - await github.pulls.createReview({ - event: "APPROVE", - owner: repository.owner, - pull_number: pullRequest.number, - repo: repository.repo, - }) - - - name: "Merge pull request" - uses: "actions/github-script@v4.0.2" - with: - github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" - script: | - const pullRequest = context.payload.pull_request - const repository = context.repo - - await github.pulls.merge({ - merge_method: "merge", - owner: repository.owner, - pull_number: pullRequest.number, - repo: repository.repo, - }) diff --git a/.github/workflows/merge.yaml b/.github/workflows/merge.yaml new file mode 100644 index 00000000..acb2eeba --- /dev/null +++ b/.github/workflows/merge.yaml @@ -0,0 +1,93 @@ +# https://docs.github.com/en/actions + +name: "Merge" + +on: # yamllint disable-line rule:truthy + workflow_run: + types: + - "completed" + workflows: + - "Integrate" + +jobs: + merge: + name: "Merge" + + runs-on: "ubuntu-latest" + + if: > + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' && + github.actor == 'dependabot[bot]' && ( + startsWith(github.event.workflow_run.head_commit.message, 'composer(deps-dev)') || + startsWith(github.event.workflow_run.head_commit.message, 'github-actions(deps)') + ) + + steps: + - name: "Request review from @ergebnis-bot" + uses: "actions/github-script@v4.0.2" + with: + github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" + script: | + const pullRequest = context.payload.workflow_run.pull_requests[0] + const repository = context.repo + + const reviewers = [ + "ergebnis-bot", + ] + + await github.pulls.requestReviewers({ + owner: repository.owner, + repo: repository.repo, + pull_number: pullRequest.number, + reviewers: reviewers, + }) + + - name: "Assign @ergebnis-bot" + uses: "actions/github-script@v4.0.2" + with: + github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" + script: | + const pullRequest = context.payload.workflow_run.pull_requests[0] + const repository = context.repo + + const assignees = [ + "ergebnis-bot", + ] + + await github.issues.addAssignees({ + owner: repository.owner, + repo: repository.repo, + assignees: assignees, + issue_number: pullRequest.number + }) + + - name: "Approve pull request" + uses: "actions/github-script@v4.0.2" + with: + github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" + script: | + const pullRequest = context.payload.workflow_run.pull_requests[0] + const repository = context.repo + + await github.pulls.createReview({ + event: "APPROVE", + owner: repository.owner, + repo: repository.repo, + pull_number: pullRequest.number, + }) + + - name: "Merge pull request" + uses: "actions/github-script@v4.0.2" + with: + github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" + script: | + const pullRequest = context.payload.workflow_run.pull_requests[0] + const repository = context.repo + + await github.pulls.merge({ + merge_method: "merge", + owner: repository.owner, + pull_number: pullRequest.number, + repo: repository.repo, + }) diff --git a/README.md b/README.md index beb2231c..1cecbc83 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # json-printer [![Integrate](https://github.com/ergebnis/json-printer/workflows/Integrate/badge.svg)](https://github.com/ergebnis/json-printer/actions) +[![Merge](https://github.com/ergebnis/json-printer/workflows/Merge/badge.svg)](https://github.com/ergebnis/json-printer/actions) [![Prune](https://github.com/ergebnis/json-printer/workflows/Prune/badge.svg)](https://github.com/ergebnis/json-printer/actions) [![Release](https://github.com/ergebnis/json-printer/workflows/Release/badge.svg)](https://github.com/ergebnis/json-printer/actions) [![Renew](https://github.com/ergebnis/json-printer/workflows/Renew/badge.svg)](https://github.com/ergebnis/json-printer/actions)