Example GitHub Action running changed Cypress specs against master first, then all the tests
Inspired by Jest and the --changedSince
flag in GitHub Actions CI
Example pull request #2 with just changed file spec-b.js
. The GitHub workflow .github/workflows/ci.yml determines that this file has changed against the master
branch and first runs just this spec. If that passes, then it runs ALL specs.
We determine the changed Cypress specs using the following git
command (after checking out both head and base branches)
git diff --name-only \
origin/${{ github.base_ref }} origin/${{ github.head_ref }} -- cypress/integration
Then if this returns something we can use cypress run --spec ...
to run the changed specs first.
CHANGED_SPECS=$(git diff --name-only origin/${{ github.base_ref }} origin/${{ github.head_ref }} -- cypress/integration)
if [ -n "$CHANGED_SPECS" ]; then
echo "Running the following changed specs"
echo $CHANGED_SPECS
npx cypress run --spec $CHANGED_SPECS
fi
And after that we can run all specs using Cypress GitHub Action
The combination of fail fast on the changed specs + run all specs afterwards feels good.