Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI workflow that runs only changed E2E tests, and succeeds when no tests have changed #10233

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/actions/e2e-pw/run-changed-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: 'Run Changed Tests'
description: 'Runs Playwright E2E Only Changed Tests'

runs:
using: 'composite'
steps:
- name: First Run Playwright E2E Tests (Only Changed)
id: first_run_e2e_pw_tests_only_changed
# Use +e to trap errors when running E2E tests.
shell: /bin/bash +e {0}
run: npm run test:e2e-pw-ci-only-changed
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 7
75 changes: 75 additions & 0 deletions .github/workflows/e2e-pw-pull-request-only-changed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: E2E Playwright Tests - Pull Request - Only Changed

on:
pull_request:
branches:
- develop
- trunk
workflow_dispatch:
workflow_call:
inputs:
wcpay-use-build-artifact:
type: boolean
required: false
default: false
repo-branch:
type: string
required: false
description: 'Branch to be used for running tests'

env:
E2E_GH_TOKEN: ${{ secrets.E2E_GH_TOKEN }}
WCP_DEV_TOOLS_REPO: ${{ secrets.WCP_DEV_TOOLS_REPO }}
WCP_DEV_TOOLS_BRANCH: 'trunk'
TRANSACT_PLATFORM_SERVER_REPO: ${{ secrets.TRANSACT_PLATFORM_SERVER_REPO }}
WC_SUBSCRIPTIONS_REPO: ${{ secrets.WC_SUBSCRIPTIONS_REPO }}
E2E_BLOG_ID: ${{ secrets.E2E_BLOG_ID }}
E2E_BLOG_TOKEN: ${{ secrets.E2E_BLOG_TOKEN }}
E2E_USER_TOKEN: ${{ secrets.E2E_USER_TOKEN }}
WC_E2E_SCREENSHOTS: 1
E2E_SLACK_CHANNEL: ${{ secrets.E2E_SLACK_CHANNEL }}
E2E_SLACK_TOKEN: ${{ secrets.E2E_SLACK_TOKEN }}
E2E_USE_LOCAL_SERVER: false
E2E_RESULT_FILEPATH: 'tests/e2e/results.json'
WCPAY_USE_BUILD_ARTIFACT: ${{ inputs.wcpay-use-build-artifact }}
WCPAY_ARTIFACT_DIRECTORY: 'zipfile'
NODE_ENV: 'test'
FORCE_E2E_DEPS_SETUP: true

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
wcpay-e2e-tests-only-changed:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == true
name: WC - latest

env:
E2E_WP_VERSION: 'latest'
E2E_WC_VERSION: 'latest'
Comment on lines +50 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The E2E tests - All workflow runs tests against different versions of WP and WC (7.7.0, latest and beta, for example). Would we want to consider this in this workflow? There will be times when tests will pass against latest but fail against beta, like with the Coming Soon mode introduced in the latest WC release.


steps:
- name: Checkout WCPay repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.repo-branch || github.ref }}
fetch-depth: 0

- name: 'Download WooCommerce Payments build file'
if: ${{ inputs.wcpay-use-build-artifact }}
uses: actions/download-artifact@v4
with:
name: woocommerce-payments
path: ${{ env.WCPAY_ARTIFACT_DIRECTORY }}

- name: Setup E2E environment
uses: ./.github/actions/e2e/env-setup

- name: Install Playwright
shell: bash
run: npx playwright install chromium

- name: Run tests, upload screenshots & logs
uses: ./.github/actions/e2e-pw/run-changed-tests
5 changes: 4 additions & 1 deletion .github/workflows/e2e-pw-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- develop
- trunk
workflow_dispatch:
pull_request_review:
types:
- submitted
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if E2E tests are run as usual and then someone adds a new review? Would the tests trigger again?

Copy link
Contributor Author

@tpaksu tpaksu Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right, pull_request.ready_for_review action seems like the correct event that should trigger this.

Edit: It ran again when I added an answer on the main thread :D Confirmed this.

workflow_call:
inputs:
wcpay-use-build-artifact:
Expand Down Expand Up @@ -43,7 +46,7 @@ concurrency:
jobs:
wcpay-e2e-tests:
runs-on: ubuntu-latest

if: github.event.pull_request.draft == false
name: WC - latest

env:
Expand Down
4 changes: 4 additions & 0 deletions changelog/dev-add-workflow-to-run-only-changed-e2e-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Add workflow that only runs changed E2E tests, and succeeds if nothing changed
95 changes: 80 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"test:e2e-pw-update-snapshots": "npm run test:e2e-pw -- --update-snapshots",
"test:e2e-pw-ui": "./tests/e2e-pw/test-e2e-pw-ui.sh",
"test:e2e-pw-ci": "npx playwright test --config=tests/e2e-pw/playwright.config.ts --grep-invert @todo",
"test:e2e-pw-ci-only-changed": "npx playwright test --only-changed=origin/develop --pass-with-no-tests --config=tests/e2e-pw/playwright.config.ts --grep-invert @todo",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only-changed flag points to origin/develop, but the workflow will run when the PR targets develop or trunk. Should we keep 2 test:e2e-pw-ci-only-changed npm scripts, one for trunk and the other one for develop so that we could choose one or another depending on the branch targeted by the PR?

"test:update-snapshots": "npm run test:js -- --updateSnapshot",
"test:php": "./bin/run-tests.sh",
"test:php-coverage": "./bin/check-test-coverage.sh",
Expand Down Expand Up @@ -96,7 +97,7 @@
"devDependencies": {
"@automattic/color-studio": "2.3.1",
"@jest/test-sequencer": "29.5.0",
"@playwright/test": "1.43.1",
"@playwright/test": "1.50.0",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.7",
"@testing-library/jest-dom": "5.14.1",
"@testing-library/react": "11.2.5",
Expand Down
Loading