From 9c58310e2a78d2ff33014b34b07af190f78cde47 Mon Sep 17 00:00:00 2001 From: "James M. Greene" Date: Mon, 8 Mar 2021 23:14:02 -0600 Subject: [PATCH] Use official auto-merge for repo-sync PRs (#17815) * Remove automerge label from repo-sync PRs to prevent automerge workflow from kicking in * Add github-script step to enable GitHub's official auto-merge on repo-sync PRs * Remove unused variable --- .github/workflows/repo-sync.yml | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/repo-sync.yml b/.github/workflows/repo-sync.yml index cbc20bbc53..6f33a620be 100644 --- a/.github/workflows/repo-sync.yml +++ b/.github/workflows/repo-sync.yml @@ -40,7 +40,7 @@ jobs: destination_branch: main pr_title: 'repo sync' pr_body: "This is an automated pull request to sync changes between the public and private repos.\n\n:robot: This pull request should be merged (not squashed) to preserve continuity across repos, so please let a bot do the merging!" - pr_label: automerge,autoupdate,automated-reposync-pr + pr_label: autoupdate,automated-reposync-pr github_token: ${{ secrets.OCTOMERGER_PAT_WITH_REPO_AND_WORKFLOW_SCOPE }} - name: Find pull request @@ -88,6 +88,32 @@ jobs: console.log(`Branch is already up-to-date`) } + - name: Enable GitHub auto-merge + if: ${{ steps.find-pull-request.outputs.number }} + uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const pull = await github.pulls.get({ + ...context.repo, + pull_number: parseInt(${{ steps.find-pull-request.outputs.number }}) + }) + + const pullNodeId = pull.data.node_id + console.log(`Pull request GraphQL Node ID: ${pullNodeId}`) + + const mutation = `mutation (id: String!) { + enablePullRequestAutoMerge (input: { + pullRequestId: $id, + mergeMethod: MERGE + }) + }`; + const variables = { + id: pullNodeId + } + await github.graphql(mutation, variables) + console.log('Auto-merge enabled!') + - name: Send Slack notification if workflow fails uses: someimportantcompany/github-actions-slack-message@0b470c14b39da4260ed9e3f9a4f1298a74ccdefd if: failure()