From ead02a1f8d1a58e3105697de9639cee76baeb410 Mon Sep 17 00:00:00 2001 From: Steve Hipwell Date: Tue, 17 Jan 2023 16:45:40 +0000 Subject: [PATCH] Added automation to run GH actions on PRs with ok-to-test Signed-off-by: Steve Hipwell --- .github/workflows/gh-workflow-approve.yaml | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/gh-workflow-approve.yaml diff --git a/.github/workflows/gh-workflow-approve.yaml b/.github/workflows/gh-workflow-approve.yaml new file mode 100644 index 0000000000..99fa279b84 --- /dev/null +++ b/.github/workflows/gh-workflow-approve.yaml @@ -0,0 +1,40 @@ +name: Approve GH Workflows + +on: + pull_request_target: + types: + - labeled + - synchronize + branches: + - master + +jobs: + approve: + name: Approve ok-to-test + if: contains(github.event.pull_request.labels.*.name, 'ok-to-test') + runs-on: ubuntu-latest + permissions: + actions: write + steps: + - name: Update PR + uses: actions/github-script@d556feaca394842dc55e4734bf3bb9f685482fa0 # v6.3.3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + debug: ${{ secrets.ACTIONS_RUNNER_DEBUG }} + script: | + const workflowRuns = await octokit.rest.actions.listWorkflowRunsForRepo({ + owner: context.repo.owner, + repo: context.repo.repo, + event: "pull_request", + status: "action_required", + head_sha: context.sha, + per_page: 100 + }).data.workflow_runs; + + for (var run of workflowRuns) { + await github.rest.actions.approveWorkflowRun({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: run.id + }); + }