Skip to content

Commit

Permalink
feat: add auto cancel after failures flag (#772)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Paul Jaffre <[email protected]>
  • Loading branch information
elylucas and jaffrepaul authored Feb 27, 2023
1 parent 63a7518 commit cdbbcd6
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
- [Explicit version](#explicit-version)
- Run tests in a given [browser](#browser)
- using [Firefox](#firefox)
- using [Edge](#edge)
- using [Edge](#edge)
- using [headed mode](#headed)
- Using [Docker image](#docker-image)
- Specify [environment variables](#env)
- Run only some [spec files](#specs)
- Test [project in subfolder](#project)
- [Record results](#record-test-results-on-cypress-cloud) on Cypress Cloud
- Specify [auto cancel](#specify-auto-cancel-after-failures) after failures
- Tag [recordings](#tag-recordings)
- [Quiet output](#quiet-flag)
- Store [test artifacts](#artifacts) on GitHub
- [Quiet output](#quiet-flag)
- Set Cypress [config values](#config)
- Use specific [config file](#config-file)
- Run tests in [parallel](#parallel)
Expand Down Expand Up @@ -404,6 +405,39 @@ The recording will have tags as labels on the run.
You can pass multiple tags using commas like `tag: node-10,nightly,staging`.

### Specify auto cancel after failures

Specify the number of failed tests that will cancel a run when using the [Cypress Cloud Auto Cancellation](https://docs.cypress.io/guides/cloud/smart-orchestration#Auto-Cancellation) feature.

This feature requires Cypress 12.6.0 or later and a [Cypress Cloud Business or Enterprise](https://www.cypress.io/cloud/) account.

```yml
name: Cypress E2E Tests
on: [push]
jobs:
cypress-run:
runs-on: ubuntu-22.04
name: E2E
steps:
- name: Setup Node
uses: actions/setup-node@v3
- name: Checkout
uses: actions/checkout@v3
- name: Cypress run
uses: cypress-io/github-action@v5
with:
record: true
# Cancel the run after 2 failed tests
auto-cancel-after-failures: 2
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

See [Auto Cancellation](https://docs.cypress.io/guides/cloud/smart-orchestration#Auto-Cancellation) for more information.

### Artifacts

If you don't record the test run on Cypress Cloud, you can still store generated videos and screenshots as CI artifacts. See [cypress-gh-action-example](https://github.com/bahmutov/cypress-gh-action-example) and the workflow example below
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ inputs:
description: 'Sends test results to Cypress Dashboard'
required: false
default: false
auto-cancel-after-failures:
description: 'Overrides the global Cloud configuration to set the failed test threshold for auto cancellation or to disable auto cancellation when recording to the Cloud (requires Cypress 12.x or later)'
required: false
config:
description: 'Set configuration values. Separate multiple values with a comma. The values set here override any values set in your configuration file.'
required: false
Expand Down
13 changes: 13 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79017,6 +79017,13 @@ const runTestsUsingCommandLine = async () => {
cmd.push('--config-file')
cmd.push(quoteArgument(configFileInput))
}
const autoCancelAfterFailures = core.getInput(
'auto-cancel-after-failures'
)
if (autoCancelAfterFailures) {
cmd.push('--auto-cancel-after-failures')
cmd.push(quoteArgument(autoCancelAfterFailures))
}

if (parallel || group) {
let buildIdVar = null
Expand Down Expand Up @@ -79145,6 +79152,12 @@ const runTests = async () => {
cypressOptions.browser = core.getInput('browser')
}

if (core.getInput('auto-cancel-after-failures')) {
cypressOptions.autoCancelAfterFailures = core.getInput(
'auto-cancel-after-failures'
)
}

if (core.getInput('env')) {
cypressOptions.env = core.getInput('env')
}
Expand Down
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,13 @@ const runTestsUsingCommandLine = async () => {
cmd.push('--config-file')
cmd.push(quoteArgument(configFileInput))
}
const autoCancelAfterFailures = core.getInput(
'auto-cancel-after-failures'
)
if (autoCancelAfterFailures) {
cmd.push('--auto-cancel-after-failures')
cmd.push(quoteArgument(autoCancelAfterFailures))
}

if (parallel || group) {
let buildIdVar = null
Expand Down Expand Up @@ -699,6 +706,12 @@ const runTests = async () => {
cypressOptions.browser = core.getInput('browser')
}

if (core.getInput('auto-cancel-after-failures')) {
cypressOptions.autoCancelAfterFailures = core.getInput(
'auto-cancel-after-failures'
)
}

if (core.getInput('env')) {
cypressOptions.env = core.getInput('env')
}
Expand Down

0 comments on commit cdbbcd6

Please sign in to comment.