generated from ExpediaGroup/new-project
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: rerun-pr-checks * docs: rerun-pr-checks * chore: tests * chore: workflow name * chore: updates based on pr comments * chore: remove label after test * chore: run test on PR instead of PR_target * chore: use ref from api query instead of context * fix: typo in test * chore: grab head ref instead * use bluebird map * use octokit request library * authenticate * console.log error * catch error for workflows already running * stop * rerun pr target workflows too and fix test * fix workflow * chore: comitting generated dist Co-authored-by: dadajian <[email protected]> Co-authored-by: danadajian <[email protected]>
- Loading branch information
1 parent
13a6b94
commit 8ed8eb5
Showing
12 changed files
with
399 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Rerun PR Checks | ||
|
||
on: | ||
pull_request: | ||
types: [ labeled ] | ||
|
||
jobs: | ||
test: | ||
if: ${{ github.event.label.name == 'RE-RUN PR CHECKS' }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.event.pull_request.head.ref }} | ||
repository: ${{ github.event.pull_request.head.repo.full_name }} | ||
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} | ||
|
||
- uses: ./ | ||
with: | ||
helper: rerun-pr-checks | ||
github_token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} | ||
|
||
- uses: ./ | ||
with: | ||
helper: remove-label | ||
label: RE-RUN PR CHECKS | ||
github_token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Copyright 2021 Expedia, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import * as core from '@actions/core'; | ||
import { context } from '@actions/github'; | ||
import { map } from 'bluebird'; | ||
import { octokit } from '../octokit'; | ||
import { request } from '@octokit/request'; | ||
|
||
export const rerunPrChecks = async () => { | ||
/** grab owner in case of fork branch */ | ||
const { | ||
data: { | ||
head: { | ||
user: { login: owner }, | ||
sha: latestHash, | ||
ref: branch | ||
} | ||
} | ||
} = await octokit.pulls.get({ | ||
pull_number: context.issue.number, | ||
...context.repo | ||
}); | ||
const workflowRunResponses = await map(['pull_request', 'pull_request_target'], event => | ||
octokit.actions.listWorkflowRunsForRepo({ | ||
branch, | ||
...context.repo, | ||
owner, | ||
event, | ||
per_page: 100 | ||
}) | ||
); | ||
const workflowRuns = workflowRunResponses.map(response => response.data.workflow_runs).flat(); | ||
if (!workflowRuns.length) { | ||
core.info(`No workflow runs found on branch ${branch} on ${owner}/${context.repo.repo}`); | ||
return; | ||
} | ||
const latestWorkflowRuns = workflowRuns.filter(({ head_sha }) => head_sha === latestHash); | ||
core.info(`The latest runs on this branch are ${latestWorkflowRuns.map(run => run.name)}, triggering reruns...`); | ||
|
||
return map(latestWorkflowRuns, async ({ id, name }) => { | ||
core.info(`- Rerunning ${name}`); | ||
await request('POST /repos/{owner}/{repo}/actions/runs/{run_id}/rerun', { | ||
owner, | ||
repo: context.repo.repo, | ||
run_id: id, | ||
headers: { | ||
authorization: `token ${core.getInput('github_token')}` | ||
} | ||
}).catch(error => { | ||
if (error.status === 403) { | ||
core.info(`${name} is already running.`); | ||
} | ||
}); | ||
}); | ||
}; |
Oops, something went wrong.