Skip to content

Commit

Permalink
Merge pull request #3354 from stevehipwell/fix-workflow-approval
Browse files Browse the repository at this point in the history
chore: Fixed GH action workflow approval
  • Loading branch information
k8s-ci-robot committed Feb 9, 2023
2 parents 9df0f4a + bda730c commit f64ffeb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/gh-workflow-approve-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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
continue-on-error: true
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
debug: ${{ secrets.ACTIONS_RUNNER_DEBUG }}
script: |
const workflowRuns = await github.rest.actions.listWorkflowRunsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
event: "pull_request",
status: "action_required",
head_sha: context.payload.pull_request.head.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
});
}
10 changes: 8 additions & 2 deletions .github/workflows/gh-workflow-approve.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
debug: ${{ secrets.ACTIONS_RUNNER_DEBUG }}
script: |
const workflowRuns = await github.rest.actions.listWorkflowRunsForRepo({
const config = {
owner: context.repo.owner,
repo: context.repo.repo,
event: "pull_request",
status: "action_required",
head_sha: context.sha,
per_page: 100
}).data.workflow_runs;
};
console.log(config);
const result = await github.rest.actions.listWorkflowRunsForRepo(config);
console.log(result);
const workflowRuns = result.data.workflow_runs;
for (var run of workflowRuns) {
await github.rest.actions.approveWorkflowRun({
Expand Down

0 comments on commit f64ffeb

Please sign in to comment.