2024-01-19 19:04:25 +05:30
# We use github cache to save snapshots between runs.
# For PRs and MergeQueues, the target commit is used, and for push events, github.event.previous is used.
# If a snapshot for a given Hash is not found, we checkout that commit, run the tests and cache the snapshots.
# These are then downloaded before running the E2E, providing the reference snapshots.
# If there are any errors, the diff image is uploaded to artifacts, and the user is notified.
2021-01-28 22:39:17 +01:00
name : E2E
2021-01-28 22:36:18 +01:00
2023-07-02 10:03:31 +05:30
on :
push :
2024-01-19 19:45:55 +05:30
branches-ignore :
- 'gh-readonly-queue/**'
2023-07-02 10:03:31 +05:30
pull_request :
merge_group :
2021-01-28 22:36:18 +01:00
2022-04-25 23:38:27 +00:00
permissions :
contents : read
2024-01-24 21:02:12 +05:30
pull-requests : write
2022-04-25 23:38:27 +00:00
2024-01-19 15:50:40 +05:30
env :
2024-01-19 19:04:25 +05:30
# For PRs and MergeQueues, the target commit is used, and for push events, github.event.previous is used.
2024-01-23 23:49:52 +05:30
targetHash : ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha || (github.event.before == '0000000000000000000000000000000000000000' && 'develop' || github.event.before) }}
2024-01-19 15:50:40 +05:30
2021-01-28 22:36:18 +01:00
jobs :
2024-01-19 12:06:53 +05:30
cache :
runs-on : ubuntu-latest
2024-01-31 11:32:55 +05:30
container :
image : cypress/browsers:node-20.11.0-chrome-121.0.6167.85-1-ff-120.0-edge-121.0.2277.83-1
options : --user 1001
2024-01-19 12:06:53 +05:30
steps :
- uses : actions/checkout@v4
- uses : pnpm/action-setup@v2
- name : Setup Node.js
uses : actions/setup-node@v4
with :
2024-01-30 20:44:39 +05:30
node-version-file : '.node-version'
2024-01-19 12:06:53 +05:30
- name : Cache snapshots
id : cache-snapshot
uses : actions/cache@v4
with :
save-always : true
path : ./cypress/snapshots
2024-01-19 15:50:40 +05:30
key : ${{ runner.os }}-snapshots-${{ env.targetHash }}
2024-01-19 12:06:53 +05:30
2024-01-19 19:04:25 +05:30
# If a snapshot for a given Hash is not found, we checkout that commit, run the tests and cache the snapshots.
2024-01-19 12:06:53 +05:30
- name : Switch to base branch
if : ${{ steps.cache-snapshot.outputs.cache-hit != 'true' }}
uses : actions/checkout@v4
with :
2024-01-19 15:50:40 +05:30
ref : ${{ env.targetHash }}
2024-01-19 12:17:20 +05:30
2024-01-24 21:02:12 +05:30
- name : Install dependencies
if : ${{ steps.cache-snapshot.outputs.cache-hit != 'true' }}
uses : cypress-io/github-action@v6
with :
# just perform install
runTests : false
- name : Build
if : ${{ steps.cache-snapshot.outputs.cache-hit != 'true' && github.event_name == 'pull_request' }}
run : |
pnpm run build:viz
mkdir -p cypress/snapshots/stats/base
mv stats cypress/snapshots/stats/base
2024-01-19 12:06:53 +05:30
- name : Cypress run
2024-01-24 21:02:12 +05:30
uses : cypress-io/github-action@v6
2024-01-19 12:06:53 +05:30
id : cypress-snapshot-gen
2024-01-24 22:17:10 +05:30
if : ${{ steps.cache-snapshot.outputs.cache-hit != 'true' }}
2024-01-19 12:06:53 +05:30
with :
2024-01-24 21:02:12 +05:30
install : false
2024-01-19 12:06:53 +05:30
start : pnpm run dev
wait-on : 'http://localhost:9000'
browser : chrome
2024-01-19 12:17:20 +05:30
2023-07-02 10:14:35 +05:30
e2e :
2021-01-28 22:36:18 +01:00
runs-on : ubuntu-latest
2024-01-31 11:35:07 +05:30
container :
image : cypress/browsers:node-20.11.0-chrome-121.0.6167.85-1-ff-120.0-edge-121.0.2277.83-1
options : --user 1001
2024-01-19 12:06:53 +05:30
needs : cache
2021-01-28 22:36:18 +01:00
strategy :
2022-09-21 10:36:38 +05:30
fail-fast : false
2021-01-28 22:36:18 +01:00
matrix :
2022-09-21 10:42:27 +05:30
containers : [ 1 , 2 , 3 , 4 ]
2021-01-28 22:36:18 +01:00
steps :
2023-11-09 12:56:57 +01:00
- uses : actions/checkout@v4
2021-01-28 22:36:18 +01:00
2022-09-25 19:38:47 +01:00
- uses : pnpm/action-setup@v2
# uses version from "packageManager" field in package.json
2022-09-21 10:36:38 +05:30
2024-01-30 20:44:39 +05:30
- name : Setup Node.js
2023-11-09 12:56:57 +01:00
uses : actions/setup-node@v4
2022-09-14 04:12:45 +01:00
with :
2024-01-30 20:44:39 +05:30
node-version-file : '.node-version'
2021-01-28 22:36:18 +01:00
2024-01-19 19:04:25 +05:30
# These cached snapshots are downloaded, providing the reference snapshots.
2024-01-19 12:06:53 +05:30
- name : Cache snapshots
id : cache-snapshot
uses : actions/cache/restore@v3
with :
path : ./cypress/snapshots
2024-01-19 15:50:40 +05:30
key : ${{ runner.os }}-snapshots-${{ env.targetHash }}
2024-01-19 12:06:53 +05:30
2024-01-24 21:02:12 +05:30
- name : Install dependencies
uses : cypress-io/github-action@v6
with :
runTests : false
- name : Build
2024-01-24 21:12:16 +05:30
id : size
if : ${{ github.event_name == 'pull_request' && matrix.containers == 1 }}
2024-01-24 21:02:12 +05:30
run : |
pnpm run build:viz
mv stats cypress/snapshots/stats/head
2024-01-24 21:51:15 +05:30
{
echo 'size_diff<<EOF'
npx tsx scripts/size.ts
echo EOF
} >> "$GITHUB_OUTPUT"
2024-01-24 21:12:16 +05:30
# Size diff only needs to be posted from one job, on PRs.
- name : Comment PR size difference
if : ${{ github.event_name == 'pull_request' && matrix.containers == 1 }}
uses : thollander/actions-comment-pull-request@v2
with :
message : |
${{ steps.size.outputs.size_diff }}
comment_tag : size-diff
2024-01-24 21:02:12 +05:30
2022-09-21 10:36:38 +05:30
# Install NPM dependencies, cache them correctly
# and run all Cypress tests
- name : Cypress run
2024-01-24 21:02:12 +05:30
uses : cypress-io/github-action@v6
2023-01-16 01:23:42 +05:30
id : cypress
2022-09-25 19:56:15 +01:00
# If CYPRESS_RECORD_KEY is set, run in parallel on all containers
# Otherwise (e.g. if running from fork), we run on a single container only
2024-01-24 22:17:10 +05:30
if : ${{ ( env.CYPRESS_RECORD_KEY != '' ) || ( matrix.containers == 1 ) }}
2022-09-21 10:36:38 +05:30
with :
2024-01-24 21:02:12 +05:30
install : false
2023-06-17 17:54:13 +05:30
start : pnpm run dev:coverage
2022-09-21 10:36:38 +05:30
wait-on : 'http://localhost:9000'
2024-01-19 12:06:53 +05:30
browser : chrome
2022-09-25 19:56:15 +01:00
# Disable recording if we don't have an API key
# e.g. if this action was run from a fork
record : ${{ secrets.CYPRESS_RECORD_KEY != '' }}
parallel : ${{ secrets.CYPRESS_RECORD_KEY != '' }}
2022-09-14 04:12:45 +01:00
env :
2022-09-21 10:36:38 +05:30
CYPRESS_RECORD_KEY : ${{ secrets.CYPRESS_RECORD_KEY }}
2023-06-17 17:54:13 +05:30
VITEST_COVERAGE : true
2023-07-07 15:56:30 +05:30
CYPRESS_COMMIT : ${{ github.sha }}
2024-01-19 12:06:53 +05:30
2023-06-17 17:54:13 +05:30
- name : Upload Coverage to Codecov
uses : codecov/codecov-action@v3
2023-07-06 11:32:37 +05:30
# Run step only pushes to develop and pull_requests
if : ${{ steps.cypress.conclusion == 'success' && (github.event_name == 'pull_request' || github.ref == 'refs/heads/develop')}}
2023-06-17 17:34:19 +05:30
with :
2023-06-17 17:44:27 +05:30
files : coverage/cypress/lcov.info
2023-06-17 17:34:19 +05:30
flags : e2e
name : mermaid-codecov
2023-07-02 13:22:00 +05:30
fail_ci_if_error : false
2023-06-17 17:34:19 +05:30
verbose : true
2023-07-03 21:01:04 +05:30
token : 6845cc80-77ee-4e17-85a1-026cd95e0766
2024-01-19 12:06:53 +05:30
2024-01-19 19:04:25 +05:30
# We upload the artifacts into numbered archives to prevent overwriting
2023-01-16 01:23:42 +05:30
- name : Upload Artifacts
2024-01-19 14:42:51 +05:30
uses : actions/upload-artifact@v4
2024-01-19 19:04:25 +05:30
if : ${{ always() }}
2023-01-16 01:23:42 +05:30
with :
2024-01-19 16:18:07 +05:30
name : snapshots-${{ matrix.containers }}
2024-01-19 14:42:51 +05:30
retention-days : 1
2024-01-19 15:50:40 +05:30
path : ./cypress/snapshots
2024-01-19 14:42:51 +05:30
combineArtifacts :
needs : e2e
runs-on : ubuntu-latest
2024-01-19 16:24:42 +05:30
if : ${{ always() }}
2024-01-19 14:42:51 +05:30
steps :
2024-01-19 19:04:25 +05:30
# Download all snapshot artifacts and merge them into a single folder
2024-01-19 14:46:21 +05:30
- name : Download All Artifacts
uses : actions/download-artifact@v4
with :
path : snapshots
2024-01-19 16:18:07 +05:30
pattern : snapshots-*
2024-01-19 14:46:21 +05:30
merge-multiple : true
2024-01-19 19:04:25 +05:30
# For successful push events, we save the snapshots cache
2024-01-19 16:18:07 +05:30
- name : Save snapshots cache
id : cache-upload
2024-01-19 19:04:25 +05:30
if : ${{ github.event_name == 'push' && needs.e2e.result != 'failure' }}
2024-01-19 16:18:07 +05:30
uses : actions/cache/save@v3
with :
2024-01-19 19:04:25 +05:30
path : ./snapshots
2024-01-19 16:18:07 +05:30
key : ${{ runner.os }}-snapshots-${{ github.event.after }}
2024-01-19 19:04:25 +05:30
- name : Flatten images to a folder
if : ${{ needs.e2e.result == 'failure' }}
2024-01-19 16:18:07 +05:30
run : |
2024-01-19 14:46:21 +05:30
mkdir errors
cd snapshots
2024-01-19 16:18:07 +05:30
find . -mindepth 2 -type d -name "*__diff_output__*" -exec sh -c 'mv "$0"/*.png ../errors/' {} \;
2024-01-19 19:04:25 +05:30
2024-01-19 16:18:07 +05:30
- name : Upload Error snapshots
2024-01-19 19:04:25 +05:30
if : ${{ needs.e2e.result == 'failure' }}
2024-01-19 14:46:21 +05:30
uses : actions/upload-artifact@v4
2024-01-19 15:30:18 +05:30
id : upload-artifacts
2024-01-19 14:46:21 +05:30
with :
name : error-snapshots
retention-days : 10
path : errors/
2024-01-19 19:04:25 +05:30
2024-01-19 15:30:18 +05:30
- name : Notify Users
2024-01-19 19:04:25 +05:30
if : ${{ needs.e2e.result == 'failure' }}
2024-01-19 15:30:18 +05:30
run : |
2024-01-19 16:23:26 +05:30
echo "::error title=Visual tests failed::You can view images that failed by downloading the error-snapshots artifact: ${{ steps.upload-artifacts.outputs.artifact-url }}"