From 4539207668903080776bb6048c106ab756fbb0da Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 16 Sep 2021 10:46:14 +0300 Subject: [PATCH] enable automerge Signed-off-by: Vasiliy Tolstov --- .github/renovate.json | 20 ------- .github/workflows/dependabot-automerge.yml | 65 ++++++++++++++++++++++ 2 files changed, 65 insertions(+), 20 deletions(-) delete mode 100644 .github/renovate.json create mode 100644 .github/workflows/dependabot-automerge.yml diff --git a/.github/renovate.json b/.github/renovate.json deleted file mode 100644 index c597bf3..0000000 --- a/.github/renovate.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "extends": [ - "config:base" - ], - "postUpdateOptions": ["gomodTidy"], - "packageRules": [ - { - "matchUpdateTypes": ["minor", "patch", "pin", "digest"], - "automerge": true - }, - { - "groupName": "all deps", - "separateMajorMinor": true, - "groupSlug": "all", - "packagePatterns": [ - "*" - ] - } - ] -} diff --git a/.github/workflows/dependabot-automerge.yml b/.github/workflows/dependabot-automerge.yml new file mode 100644 index 0000000..b9628e7 --- /dev/null +++ b/.github/workflows/dependabot-automerge.yml @@ -0,0 +1,65 @@ +name: "Pull Request Auto Merge" + +on: + workflow_run: + workflows: ["prbuild", "CodeQL"] + types: + - completed + +permissions: + contents: write + pull-requests: write + +jobs: + Dependabot-Automerge: + runs-on: ubuntu-latest + # Contains workaround to execute if dependabot updates the PR by checking for the base branch in the linked PR + # The the github.event.workflow_run.event value is 'push' and not 'pull_request' + if: >- + github.event.workflow_run.conclusion == 'success' + && github.actor == 'dependabot[bot]' + && github.event.sender.login == 'dependabot[bot]' + && github.event.sender.type == 'Bot' + && (github.event.workflow_run.event == 'pull_request' + || (github.event.workflow_run.event == 'push' && github.event.workflow_run.pull_requests[0].base.ref == github.event.repository.default_branch )) + steps: + - name: Approve Changes and Merge changes if label 'dependencies' is set + uses: actions/github-script@v4 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + console.log(context.payload.workflow_run); + + var labelNames = await github.paginate( + github.issues.listLabelsOnIssue, + { + repo: context.repo.repo, + owner: context.repo.owner, + issue_number: context.payload.workflow_run.pull_requests[0].number, + }, + (response) => response.data.map( + (label) => label.name + ) + ); + + console.log(labelNames); + + if (labelNames.includes('dependencies')) { + console.log('Found label'); + + await github.pulls.createReview({ + repo: context.repo.repo, + owner: context.repo.owner, + pull_number: context.payload.workflow_run.pull_requests[0].number, + event: 'APPROVE' + }); + console.log('Approved PR'); + + await github.pulls.merge({ + repo: context.repo.repo, + owner: context.repo.owner, + pull_number: context.payload.workflow_run.pull_requests[0].number, + }); + + console.log('Merged PR'); + }