Skip to content

Commit

Permalink
Fail the action if triggering workflow run has been cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Dorner committed Feb 20, 2021
1 parent 577cc33 commit 4e1eb73
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ jobs:
Workflows triggered by pull requests from forked repositories are executed with read-only token and therefore can't create check runs.
To workaround this security restriction it's required to use two separate workflows:
- `CI` runs in the context of PR head branch with read-only token. It executes the tests and uploads test results as build artifact
- `Test Report` runs in the context of repository main branch with read/write token. It will download test results and create reports
1. `CI` runs in the context of PR head branch with read-only token. It executes the tests and uploads test results as build artifact
2. `Test Report` runs in the context of repository main branch with read/write token. It will download test results and create reports

**PR head branch:** *.github/workflows/ci.yml*
```yaml
Expand All @@ -70,6 +70,7 @@ jobs:
- run: npm ci # install packages
- run: npm test # run tests (configured to use jest-junit reporter)
- uses: actions/upload-artifact@v2 # upload test results
if: success() || failure() # run this step even if previous step failed
with:
name: test-results
path: jest-junit.xml
Expand Down
3 changes: 3 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/utils/github-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export function getCheckRunContext(): {sha: string; runId: number} {
if (!event.workflow_run) {
throw new Error("Event of type 'workflow_run' is missing 'workflow_run' field")
}
if (event.workflow_run.conclusion === 'cancelled') {
throw new Error(`Workflow run ${event.workflow_run.id} has been cancelled`)
}
return {
sha: event.workflow_run.head_commit.id,
runId: event.workflow_run.id
Expand Down

0 comments on commit 4e1eb73

Please sign in to comment.