mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-16 06:17:10 +01:00
Fail the action if triggering workflow run has been cancelled
This commit is contained in:
parent
577cc333e8
commit
4e1eb73eb5
4 changed files with 10 additions and 3 deletions
|
|
@ -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.
|
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:
|
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
|
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
|
||||||
- `Test Report` runs in the context of repository main branch with read/write token. It will download test results and create reports
|
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*
|
**PR head branch:** *.github/workflows/ci.yml*
|
||||||
```yaml
|
```yaml
|
||||||
|
|
@ -70,6 +70,7 @@ jobs:
|
||||||
- run: npm ci # install packages
|
- run: npm ci # install packages
|
||||||
- run: npm test # run tests (configured to use jest-junit reporter)
|
- run: npm test # run tests (configured to use jest-junit reporter)
|
||||||
- uses: actions/upload-artifact@v2 # upload test results
|
- uses: actions/upload-artifact@v2 # upload test results
|
||||||
|
if: success() || failure() # run this step even if previous step failed
|
||||||
with:
|
with:
|
||||||
name: test-results
|
name: test-results
|
||||||
path: jest-junit.xml
|
path: jest-junit.xml
|
||||||
|
|
|
||||||
3
dist/index.js
generated
vendored
3
dist/index.js
generated
vendored
|
|
@ -1389,6 +1389,9 @@ function getCheckRunContext() {
|
||||||
if (!event.workflow_run) {
|
if (!event.workflow_run) {
|
||||||
throw new Error("Event of type 'workflow_run' is missing 'workflow_run' field");
|
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 {
|
return {
|
||||||
sha: event.workflow_run.head_commit.id,
|
sha: event.workflow_run.head_commit.id,
|
||||||
runId: event.workflow_run.id
|
runId: event.workflow_run.id
|
||||||
|
|
|
||||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
|
|
@ -15,6 +15,9 @@ export function getCheckRunContext(): {sha: string; runId: number} {
|
||||||
if (!event.workflow_run) {
|
if (!event.workflow_run) {
|
||||||
throw new Error("Event of type 'workflow_run' is missing 'workflow_run' field")
|
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 {
|
return {
|
||||||
sha: event.workflow_run.head_commit.id,
|
sha: event.workflow_run.head_commit.id,
|
||||||
runId: event.workflow_run.id
|
runId: event.workflow_run.id
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue