Reusable Cypress GitHub Actions Workflows
Advent day 6: The simplest CI setup for running Cypress tests
Writing CI scripts is hard. You need to know what the tool (like Cypress) needs to run, how to install and cache it, how to pass various CLI arguments, where the results are, etc. The custom GH Actions help the authors of the tool abstract the details away and publish a user-friendly CI abstraction like my cypress-io/github-action work. Well, the user still needed to check out the code, configure the parallel test containers, etc. An individual step was easy, while the overall workflow had its gotchas.
Until now. GitHub Actions has introduced reusable workflows which are 🤯 I already wrote a little public repo bahmutov/cypress-workflows with my most common Cypress testing workflows for everyone who needs to run E2E tests. From your project you can use 1 line of YML code to get the code, set up N testing containers, and run all the tests in parallel:
name: ci
on: [push]
jobs:
test:
# https://github.com/bahmutov/cypress-workflows
uses: bahmutov/cypress-workflows/.github/workflows/parallel.yml@v1
with:
n: 3
group: parallel tests
tag: parallel
secrets:
recordKey: ${{ secrets.CYPRESS_RECORD_KEY }}
Push the code and see the workflow in action (my example lives in the repo cypress-workflows-example)
You can pass Cypress action parameters to the workflow (just like I passed the group name and the tag string), and it passes them to the Cypress GH Action. Not interested in the parallel tests? Want to simply get the code, install, and run the tests? Use the “standard” reusable workflow:
name: ci
on: [push]
jobs:
test:
# https://github.com/bahmutov/cypress-workflows
uses: bahmutov/cypress-workflows/.github/workflows/standard.yml@v1
So simple!
For more details, read the blog post “The Simplest CI Setup For Running Cypress Tests” and check out my open-source workshop “Cypress on CI”