From dddfabebd4f10f0f21e14d58d0adfb3ab42f7700 Mon Sep 17 00:00:00 2001 From: Mike Odnis Date: Fri, 15 Dec 2023 01:48:56 -0500 Subject: [PATCH] Create auto-merge.yml --- .github/workflows/auto-merge.yml | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .github/workflows/auto-merge.yml diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml new file mode 100644 index 0000000..174050e --- /dev/null +++ b/.github/workflows/auto-merge.yml @@ -0,0 +1,54 @@ +name: Dependabot Approve and Merge + +on: pull_request_target + +permissions: + pull-requests: write + contents: write + issues: write + +jobs: + dependabot: + name: Auto approve and merge + runs-on: ubuntu-latest + + if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }} + steps: + - name: Fetch update types + id: update-types + env: + UPDATE_TYPES: ${{ secrets.UPDATE_TYPES }} + run: | + arr=(${UPDATE_TYPES//;/ }) + count=${#arr[@]} + echo "Types: ${arr[*]}" + echo "Count: ${count}" + echo "types=${arr[*]}" >> $GITHUB_OUTPUT + echo "count=${count}" >> $GITHUB_OUTPUT + + - name: Fetch Dependabot metadata + if: ${{ fromJson(steps.update-types.outputs.count) > 0 }} + id: dependabot-metadata + uses: dependabot/fetch-metadata@v1.3.5 + + - name: Approve and merge + id: auto-merge + if: ${{ fromJson(steps.update-types.outputs.count) > 0 && contains(steps.update-types.outputs.types, steps.dependabot-metadata.outputs.update-type) }} + run: | + gh pr edit "$PR_URL" --add-label "auto-merged" + gh pr review --approve "$PR_URL" + gh pr merge --auto --squash "$PR_URL" + echo "STATUS=true" >> $GITHUB_OUTPUT + env: + PR_URL: ${{ github.event.pull_request.html_url }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Write summary + run: | + result="skip. :x:" + if [ "${STATUS}" == "true" ]; then + result=" auto-merge! :white_check_mark:" + fi + echo "### Done with ${result}" >> $GITHUB_STEP_SUMMARY + env: + STATUS: ${{ steps.auto-merge.outputs.STATUS }}