| 1 | name: E2E |
| 2 | |
| 3 | on: |
| 4 | push: |
| 5 | branches: |
| 6 | - develop |
| 7 | - master |
| 8 | - release/** |
| 9 | pull_request: |
| 10 | merge_group: |
| 11 | |
| 12 | concurrency: ${{ github.workflow }}-${{ github.ref }} |
| 13 | |
| 14 | permissions: |
| 15 | contents: read |
| 16 | |
| 17 | env: |
| 18 | # For PRs and MergeQueues, the target commit is used, and for push events to non-develop branches, github.event.previous is used if available. Otherwise, 'develop' is used. |
| 19 | targetHash: >- |
| 20 | ${{ |
| 21 | github.event.pull_request.base.sha || |
| 22 | github.event.merge_group.base_sha || |
| 23 | ( |
| 24 | ( |
| 25 | (github.event_name == 'push' && github.ref == 'refs/heads/develop') || |
| 26 | github.event.before == '0000000000000000000000000000000000000000' |
| 27 | ) && 'develop' |
| 28 | ) || |
| 29 | github.event.before |
| 30 | }} |
| 31 | RUN_VISUAL_TEST: >- |
| 32 | ${{ github.repository == 'mermaid-js/mermaid' && (github.event_name != 'pull_request' || !startsWith(github.head_ref, 'renovate/')) }} |
| 33 | jobs: |
| 34 | cache: |
| 35 | runs-on: ubuntu-latest |
| 36 | container: |
| 37 | image: cypress/browsers:node-20.16.0-chrome-127.0.6533.88-1-ff-128.0.3-edge-127.0.2651.74-1 |
| 38 | options: --user 1001 |
| 39 | steps: |
| 40 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 41 | - uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0 |
| 42 | - name: Setup Node.js |
| 43 | uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 |
| 44 | with: |
| 45 | node-version-file: '.node-version' |
| 46 | - name: Cache snapshots |
| 47 | id: cache-snapshot |
| 48 | uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 |
| 49 | with: |
| 50 | path: ./cypress/snapshots |
| 51 | key: ${{ runner.os }}-snapshots-${{ env.targetHash }} |
| 52 | |
| 53 | # If a snapshot for a given Hash is not found, we checkout that commit, run the tests and cache the snapshots. |
| 54 | - name: Switch to base branch |
| 55 | if: ${{ steps.cache-snapshot.outputs.cache-hit != 'true' }} |
| 56 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 57 | with: |
| 58 | ref: ${{ env.targetHash }} |
| 59 | |
| 60 | - name: Install dependencies |
| 61 | if: ${{ steps.cache-snapshot.outputs.cache-hit != 'true' }} |
| 62 | uses: cypress-io/github-action@108b8684ae52e735ff7891524cbffbcd4be5b19f # v6.7.16 |
| 63 | with: |
| 64 | # just perform install |
| 65 | runTests: false |
| 66 | |
| 67 | - name: Calculate bundle size |
| 68 | if: ${{ steps.cache-snapshot.outputs.cache-hit != 'true'}} |
| 69 | run: | |
| 70 | pnpm run build:viz |
| 71 | mkdir -p cypress/snapshots/stats/base |
| 72 | mv stats cypress/snapshots/stats/base |
| 73 | |
| 74 | e2e: |
| 75 | runs-on: ubuntu-latest |
| 76 | container: |
| 77 | image: cypress/browsers:node-20.16.0-chrome-127.0.6533.88-1-ff-128.0.3-edge-127.0.2651.74-1 |
| 78 | options: --user 1001 |
| 79 | needs: cache |
| 80 | strategy: |
| 81 | fail-fast: false |
| 82 | matrix: |
| 83 | containers: [1, 2, 3, 4, 5] |
| 84 | steps: |
| 85 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 86 | |
| 87 | - uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0 |
| 88 | # uses version from "packageManager" field in package.json |
| 89 | |
| 90 | - name: Setup Node.js |
| 91 | uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 |
| 92 | with: |
| 93 | node-version-file: '.node-version' |
| 94 | |
| 95 | # These cached snapshots are downloaded, providing the reference snapshots. |
| 96 | - name: Cache snapshots |
| 97 | id: cache-snapshot |
| 98 | uses: actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 |
| 99 | with: |
| 100 | path: ./cypress/snapshots |
| 101 | key: ${{ runner.os }}-snapshots-${{ env.targetHash }} |
| 102 | |
| 103 | - name: Install dependencies |
| 104 | uses: cypress-io/github-action@108b8684ae52e735ff7891524cbffbcd4be5b19f # v6.7.16 |
| 105 | with: |
| 106 | runTests: false |
| 107 | |
| 108 | - name: Output size diff |
| 109 | if: ${{ matrix.containers == 1 }} |
| 110 | run: | |
| 111 | pnpm run build:viz |
| 112 | mv stats cypress/snapshots/stats/head |
| 113 | echo '## Bundle size difference' >> "$GITHUB_STEP_SUMMARY" |
| 114 | echo '' >> "$GITHUB_STEP_SUMMARY" |
| 115 | npx tsx scripts/size.ts >> "$GITHUB_STEP_SUMMARY" |
| 116 | |
| 117 | # Install NPM dependencies, cache them correctly |
| 118 | # and run all Cypress tests |
| 119 | - name: Cypress run |
| 120 | uses: cypress-io/github-action@108b8684ae52e735ff7891524cbffbcd4be5b19f # v6.7.16 |
| 121 | id: cypress |
| 122 | with: |
| 123 | install: false |
| 124 | start: pnpm run dev:coverage |
| 125 | wait-on: 'http://localhost:9000' |
| 126 | browser: chrome |
| 127 | # Disable recording if we don't have an API key |
| 128 | # e.g. if this action was run from a fork |
| 129 | record: ${{ env.RUN_VISUAL_TEST == 'true' && secrets.CYPRESS_RECORD_KEY != '' }} |
| 130 | env: |
| 131 | ARGOS_PARALLEL: ${{ env.RUN_VISUAL_TEST == 'true' }} |
| 132 | ARGOS_PARALLEL_TOTAL: ${{ env.RUN_VISUAL_TEST == 'true' && strategy.job-total || 1 }} |
| 133 | ARGOS_PARALLEL_INDEX: ${{ env.RUN_VISUAL_TEST == 'true' && matrix.containers || 1 }} |
| 134 | CYPRESS_COMMIT: ${{ github.sha }} |
| 135 | CYPRESS_RECORD_KEY: ${{ env.RUN_VISUAL_TEST == 'true' && secrets.CYPRESS_RECORD_KEY || ''}} |
| 136 | SPLIT: ${{ strategy.job-total }} |
| 137 | SPLIT_INDEX: ${{ strategy.job-index }} |
| 138 | SPLIT_FILE: 'cypress/timings.json' |
| 139 | VITEST_COVERAGE: true |
| 140 | |
| 141 | - name: Upload Coverage to Codecov |
| 142 | uses: codecov/codecov-action@13ce06bfc6bbe3ecf90edbbf1bc32fe5978ca1d3 # v5.3.1 |
| 143 | # Run step only pushes to develop and pull_requests |
| 144 | if: ${{ steps.cypress.conclusion == 'success' && (github.event_name == 'pull_request' || github.ref == 'refs/heads/develop')}} |
| 145 | with: |
| 146 | files: coverage/cypress/lcov.info |
| 147 | flags: e2e |
| 148 | name: mermaid-codecov |
| 149 | fail_ci_if_error: false |
| 150 | verbose: true |
| 151 | token: 6845cc80-77ee-4e17-85a1-026cd95e0766 |
| 152 | |