Marc Kupietz | 1074475 | 2020-11-24 12:10:55 +0100 | [diff] [blame^] | 1 | name: Re-run CI tests on open PRs |
| 2 | |
| 3 | on: |
| 4 | push: |
| 5 | branches: |
| 6 | - master |
| 7 | |
| 8 | jobs: |
| 9 | re-run-github-actions: |
| 10 | runs-on: ubuntu-latest |
| 11 | steps: |
| 12 | - name: (GET-&-PUT Github API) Push empty commit to PR branch |
| 13 | uses: actions/github-script@0.2.0 |
| 14 | with: |
| 15 | github-token: ${{secrets.PAT}} |
| 16 | script: | |
| 17 | const owner = context.repo.owner; |
| 18 | const repo = context.repo.repo; |
| 19 | const {data: pullRequests} = await github.pulls.list({ |
| 20 | owner, |
| 21 | repo, |
| 22 | base: "master", |
| 23 | state: "open", |
| 24 | }); |
| 25 | |
| 26 | for (pr of pullRequests) { |
| 27 | try { |
| 28 | let pullReq = {}; |
| 29 | while (pullReq.mergeable === undefined || pullReq.mergeable === null) { |
| 30 | pullReq = ( |
| 31 | await github.pulls.get({ |
| 32 | owner, |
| 33 | repo, |
| 34 | pull_number: pr.number, |
| 35 | }) |
| 36 | ).data; |
| 37 | } |
| 38 | if(pullReq.mergeable === false) continue; |
| 39 | |
| 40 | const {data: commitData} = await github.repos.getCommit({ |
| 41 | owner, |
| 42 | repo, |
| 43 | ref: pullReq.head.sha, |
| 44 | }); |
| 45 | |
| 46 | const {data: createdCommit} = await github.git.createCommit({ |
| 47 | owner, |
| 48 | repo, |
| 49 | message: "trigger github actions", |
| 50 | tree: commitData.commit.tree.sha, |
| 51 | parents: [commitData.sha], |
| 52 | commiter: context.payload.pusher, |
| 53 | author: context.payload.pusher, |
| 54 | }); |
| 55 | |
| 56 | await github.git.updateRef({ |
| 57 | owner, |
| 58 | repo, |
| 59 | ref: `heads/${pr.head.ref}`, |
| 60 | sha: createdCommit.sha, |
| 61 | }); |
| 62 | } catch (err) { |
| 63 | console.log(err); |
| 64 | } |
| 65 | } |