SQUARE-201: Prevent fatal error on incompatible environments. #1007
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Run E2E tests | |
| on: | |
| push: | |
| branches: | |
| - smoke-testing | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| e2e: | |
| if: "${{ ( github.event_name == 'pull_request' ) || github.event_name == 'push' }}" | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| type: [ '@general', '@cashapp', '@sync', '@giftcard' ] | |
| env: | |
| WP_ADMIN_USERNAME: ${{ secrets.WP_ADMIN_USERNAME }} | |
| WP_ADMIN_PASSWORD: ${{ secrets.WP_ADMIN_PASSWORD }} | |
| SQUARE_APPLICATION_ID: ${{ secrets.SQUARE_APPLICATION_ID }} | |
| SQUARE_ACCESS_TOKEN: ${{ secrets.SQUARE_ACCESS_TOKEN }} | |
| SQUARE_LOCATION_ID: ${{ secrets.SQUARE_LOCATION_ID }} | |
| GH_TOKEN: ${{ secrets.ORG_DOWNLOADS }} | |
| permissions: | |
| pull-requests: write | |
| name: E2E tests (${{ matrix.type }}) | |
| steps: | |
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| - uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0 | |
| with: | |
| php-version: '7.4' | |
| tools: composer:v2 | |
| - uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 | |
| with: | |
| node-version-file: '.nvmrc' | |
| - name: Install Node dependencies | |
| run: npm ci && npm run build | |
| - name: Install playwright | |
| run: npx playwright install --with-deps chromium | |
| # Use compiled versions to avoid need for npm and composer installation and build step. | |
| - name: Install required WP plugins | |
| run: | | |
| gh release download --repo woocommerce/woocommerce-pre-orders --pattern woocommerce-pre-orders.zip --dir ./test-plugins | |
| gh release download --repo woocommerce/woocommerce-subscriptions --pattern woocommerce-subscriptions.zip --dir ./test-plugins | |
| cd ./test-plugins | |
| unzip -o woocommerce-pre-orders.zip | |
| unzip -o woocommerce-subscriptions.zip | |
| cd .. | |
| - name: Set the core version | |
| if: "${{ contains(github.event.pull_request.labels.*.name, 'needs: WP RC test') }}" | |
| id: run-rc-test | |
| run: ./tests/bin/set-core-version.js WordPress/WordPress#master | |
| - name: Setup E2E environment | |
| run: npm run env:start | |
| - name: Run E2E tests | |
| id: square_e2e_tests | |
| if: ${{ github.event_name == 'pull_request' && matrix.type != '@general' }} | |
| run: npm run test:e2e -- --grep ${{ matrix.type }} | |
| - name: Run E2E tests (General) | |
| id: square_e2e_tests_general | |
| if: ${{ github.event_name == 'pull_request' && matrix.type == '@general' }} | |
| run: npm run test:e2e -- --grep-invert "@cashapp|@sync|@giftcard" | |
| - name: Remove existing labels | |
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
| continue-on-error: true | |
| with: | |
| script: | | |
| const labelsToRemove = ['status: e2e tests passing', 'status: e2e tests failing']; | |
| const { data } = await github.rest.issues.listLabelsOnIssue({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| }) | |
| // Return early if there are no labels. | |
| if ( data.length == 0 ) { | |
| console.log ( 'Issue has no labels; not attempting to remove any labels' ); | |
| return; | |
| } | |
| // Remove each label if it exists. | |
| for ( const labelName of labelsToRemove ) { | |
| const labelExists = data.filter( label => label.name === labelName ); | |
| if ( labelExists.length > 0 ) { | |
| console.log( `Removing label "${labelName}"...` ); | |
| await github.rest.issues.removeLabel({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| name: labelName | |
| }) | |
| } else { | |
| console.log( `Label "${labelName}" not found on issue; skipping removal` ); | |
| } | |
| } | |
| - name: Update Success Label | |
| if: | | |
| always() && | |
| ( steps.square_e2e_tests.conclusion == 'success' || steps.square_e2e_tests_general.conclusion == 'success' ) | |
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
| continue-on-error: true | |
| with: | |
| script: | | |
| github.rest.issues.addLabels({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| labels: ['status: e2e tests passing'] | |
| }) | |
| - name: Update Failure Label | |
| if: | | |
| always() && | |
| ( steps.square_e2e_tests.conclusion == 'failure' || steps.square_e2e_tests_general.conclusion == 'failure' ) | |
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
| continue-on-error: true | |
| with: | |
| script: | | |
| github.rest.issues.addLabels({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| labels: ['status: e2e tests failing'] | |
| }) | |
| - name: Run E2E Smoke Test | |
| if: ${{ github.event_name == 'push' && matrix.type != '@general' }} | |
| run: npm run test:e2e -- --grep ${{ matrix.type }} | |
| - name: Run E2E Smoke Test (General) | |
| if: ${{ github.event_name == 'push' && matrix.type == '@general' }} | |
| run: npm run test:e2e -- --grep-invert "@cashapp|@sync|@giftcard" | |
| - uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1 | |
| if: always() | |
| with: | |
| name: playwright-report-${{ matrix.type }} | |
| path: tests/e2e/test-results/report | |
| retention-days: 2 | |
| if-no-files-found: ignore |