Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
139 changes: 139 additions & 0 deletions .github/workflows/_internal-e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: E2E Test

on:
workflow_dispatch: {}
push:
branches:
- main
paths:
- "_test/demo-package/Test/e2e/**"
- "warden/**"
- "setup-magento/**"
- ".github/workflows/_internal-e2e.yaml"
- "!(**/*.md)"
pull_request:
branches:
- main
paths:
- "_test/demo-package/Test/e2e/**"
- "warden/**"
- "setup-magento/**"
- ".github/workflows/_internal-e2e.yaml"
- "!(**/*.md)"

# Standing up the whole stack costs a runner for a while; there is no reason to
# keep paying for a run whose commit has already been superseded.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
storefront-smoke-test:
name: "storefront tests"
if: "!startsWith(github.head_ref, 'release-please')"
runs-on: ubuntu-latest
timeout-minutes: 60
env:
# setup:install, the hostname the runner resolves and the URL the browser
# opens all have to agree, so they are derived from one place.
TRAEFIK_DOMAIN: mageos.test
TRAEFIK_SUBDOMAIN: app
E2E_DIRECTORY: actions/_test/demo-package/Test/e2e
# Pinned rather than taken from supported-version: this workflow is here
# to tell us whether the action still serves a store, so a service bump
# elsewhere should not change what it reports. The release pipeline picks
# its own versions.
PHP_VERSION: "8.4"
COMPOSER_VERSION: "2.10.2"
steps:
# Not at the workspace root: warden/setup-environment checks the Warden
# CLI out into warden/ there, which is where this repository keeps that
# action, and the checkout would land on top of it.
- uses: actions/checkout@v6
with:
path: actions

# mode: extension is how the other internal workflows get a project onto
# disk -- composer create-project --no-install, into ./_ghamagento. The
# dependencies are then installed inside the container, by the PHP version
# that will serve them.
- name: Create the Mage-OS project
uses: ./actions/setup-magento
with:
php-version: ${{ env.PHP_VERSION }}
tools: "composer:v2"
mode: extension
magento_repository: "https://repo.mage-os.org/"
magento_version: "mage-os/project-community-edition:4.0.0"

- name: Serve the store in Warden
id: warden
uses: ./actions/warden/setup-environment
with:
base_directory: "./_ghamagento"
php_version: ${{ env.PHP_VERSION }}
composer_version: ${{ env.COMPOSER_VERSION }}
database: "mariadb:11.8"
search: "opensearch:3.4"
rabbitmq: "rabbitmq:4.2"
redis: "redis:7.4"
varnish: "varnish:8.0"
run_composer_install: 1
run_setup_install: 1
run_admin_user_creation: 1
run_magento_config_preset: 1
run_reindex: 1
traefik_domain: ${{ env.TRAEFIK_DOMAIN }}
traefik_subdomain: ${{ env.TRAEFIK_SUBDOMAIN }}
# The three inputs a browser needs, and nothing a PHPUnit suite pays for.
base_url: "https://${{ env.TRAEFIK_SUBDOMAIN }}.${{ env.TRAEFIK_DOMAIN }}/"
configure_host_resolution: 1
run_static_content_deploy: 1
static_content_themes: "Magento/luma"

# Separate from the test run so that "the store was never reachable" and
# "the store rendered the wrong thing" are different red steps.
- name: Confirm the store answers on the resolved hostname
run: curl --silent --show-error --fail --insecure --head "${{ steps.warden.outputs.base_url }}" | head -1

# A bare setup:install has nothing to buy. The command reindexes itself.
# Streamed in rather than copied: the project directories are owned by the
# container's user.
- name: Seed the catalog
working-directory: ./_ghamagento
shell: bash
env:
PROFILE: ${{ github.workspace }}/${{ env.E2E_DIRECTORY }}/fixtures/mageos-e2e.xml
run: |
export WARDEN="$(dirname $(pwd))/warden/bin/warden"
${WARDEN} env exec -T php-fpm bash -c 'cat > /tmp/mageos-e2e.xml' < "${PROFILE}"
${WARDEN} env exec -T php-fpm bin/magento setup:performance:generate-fixtures /tmp/mageos-e2e.xml

- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: ${{ env.E2E_DIRECTORY }}/package-lock.json

- name: Install Playwright
working-directory: ${{ env.E2E_DIRECTORY }}
run: |
npm ci
npx playwright install --with-deps chromium

- name: Run the storefront tests
working-directory: ${{ env.E2E_DIRECTORY }}
env:
PLAYWRIGHT_BASE_URL: ${{ steps.warden.outputs.base_url }}
run: npx playwright test

- name: Upload the Playwright report
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: |
${{ env.E2E_DIRECTORY }}/playwright-report
${{ env.E2E_DIRECTORY }}/test-results
retention-days: 30
if-no-files-found: ignore
156 changes: 156 additions & 0 deletions .github/workflows/e2e-README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# Browser-based E2E Tests for Mage-OS

A Github Workflow that stands a Mage-OS store up, **serves it**, and points a
browser-based test runner at it.

This is not the PHPUnit-based suite that upstream calls "functional tests". It
installs a store, serves it through Traefik and Varnish on a resolvable
hostname, optionally seeds a catalog, and runs a browser against the result.

## Inputs

See the [e2e.yaml](./e2e.yaml)

### What to install

| Input | Description | Required | Default |
| -------------------- | --------------------------------------------------------------------------- | -------- | ----------------------------- |
| magento_version | The package to install, e.g. `mage-os/project-community-edition:4.0.0` | true | NULL |
| magento_repository | The composer repository to install it from | false | https://repo.mage-os.org/ |
| php_version | The PHP version that installs and serves the store | false | 8.4 |
| composer_version | The Composer version used inside the container | false | 2.10.2 |

A release gate points `magento_repository` at the preview repository and
`magento_version` at the release being built, which is how it tests the
artifact about to be tagged rather than whatever is already published.

### What to serve it with

| Input | Description | Required | Default |
| ---------------------- | ------------------------------------------------------------------------- | -------- | --------------- |
| database | Database service and version | false | mariadb:11.8 |
| search | Search service and version | false | opensearch:3.4 |
| rabbitmq | Message queue service and version | false | rabbitmq:4.2 |
| redis | Cache service and version | false | redis:7.4 |
| varnish | HTTP cache service and version | false | varnish:8.0 |
| static_content_themes | Space separated themes to deploy static content for. Empty deploys every theme, which is considerably slower. | false | Magento/luma |

### Where the suite comes from

| Input | Description | Required | Default |
| ----------------- | ---------------------------------------------------------------- | -------- | --------------------------------- |
| suite_repository | The repository holding the test suite | false | mage-os/github-actions |
| suite_ref | The ref to check it out at | false | main |
| test_directory | The suite's directory, relative to the root of `suite_repository` | false | _test/demo-package/Test/e2e |

The defaults point at the suite this repository carries for its own canary. A
caller with a suite of its own overrides all three.

### How to run it

| Input | Description | Required | Default |
| ------------------------ | ------------------------------------------------------------------ | -------- | -------------------- |
| test_command | The command to run, from `test_directory` | false | `npx playwright test` |
| node_version | Node version for the runner | false | 22 |
| fixture_profile | A performance-toolkit profile to seed, relative to the suite root. Empty skips seeding. | false | _test/demo-package/Test/e2e/fixtures/mageos-e2e.xml |
| timeout_minutes | Job timeout | false | 60 |
| artifact_name | Name of the uploaded report artifact | false | playwright-report |
| artifact_retention_days | How long the report is kept | false | 30 |

## Secrets

| Input | Description | Required | Default |
| ------------- | --------------------------------------------------------------------------- | -------- | ------- |
| composer_auth | JSON string of composer credentials | false | NULL |

## Outputs

| Output | Description |
| -------- | ------------------------------------- |
| base_url | The URL the store was served on |

## `test_command`

The workflow does not know what test runner you use. `test_command` is run from
`test_directory` with `PLAYWRIGHT_BASE_URL` already set to the served store, so
a caller can pass grep filters, shards, a different reporter, or something that
is not Playwright at all, without this workflow growing an input per flag.

The command arrives through the environment rather than interpolated into the
script, so its quoting is bash's problem and not the expression engine's.

**Keep evidence policy out of it.** `trace`, `video` and `screenshot` belong in
the suite's own config, where they are reviewable. A CLI flag overrides the
config, and `--trace on` records a trace for every passing test, which uploads
a large artifact for no benefit. The default command carries no flags for that
reason.

### A setup phase

Playwright's project `dependencies` are the mechanism for shared state that is
expensive to build -- an authenticated admin or customer session saved as
`storageState` and reused by every spec that needs it. Express that in the
suite's config rather than as two `--grep` / `--grep-invert` invocations in
`test_command`: two invocations write to the same report directory, so the
second overwrites the first and a failing setup phase loses its own evidence.
One command, one report, one exit code.

Data is a different matter. Catalog and configuration are seeded through
`fixture_profile` by the CLI in seconds; doing the same work through a browser
would be slower and flakier for no gain.

## Fixtures

`fixture_profile` is a [performance
toolkit](https://developer.adobe.com/commerce/php/development/tools/performance-toolkit/)
profile, applied with `setup:performance:generate-fixtures`. The command
reindexes as part of its own run, so no `indexer:reindex` follows it.

A bare `setup:install` has no salable product, so any suite that reaches a
product page or a checkout needs this. Leave it empty for a suite that asserts
only on what a bare install provides.

## Usage

```yaml
jobs:
e2e:
uses: mage-os/github-actions/.github/workflows/e2e.yaml@main
with:
magento_version: "mage-os/project-community-edition:4.0.0"
```

Gating a release on the artifact that is about to be tagged:

```yaml
jobs:
storefront-check:
needs: [ deploy ]
uses: mage-os/github-actions/.github/workflows/e2e.yaml@main
with:
magento_repository: ${{ inputs.repo }}
magento_version: "mage-os/project-community-edition:${{ inputs.mageos_release }}"
artifact_name: "storefront-check-${{ inputs.mageos_release }}"
```

Running a suite of your own:

```yaml
jobs:
e2e:
uses: mage-os/github-actions/.github/workflows/e2e.yaml@main
with:
magento_version: "mage-os/project-community-edition:4.0.0"
suite_repository: my-org/my-e2e-tests
suite_ref: v1.2.0
test_directory: "."
test_command: "npx playwright test --grep @smoke"
fixture_profile: "fixtures/minimal.xml"
```

## Where things end up on the runner

`warden/setup-environment` checks the Warden CLI out into `warden/` at the
workspace root, and `base_directory` has to sit exactly one level below it.
That is why the suite is checked out into `suite/` and the store into
`_ghamagento/`, and why neither is at the workspace root.
Loading
Loading