Skip to content

Revise API links and update section headers #407

Revise API links and update section headers

Revise API links and update section headers #407

Workflow file for this run

name: "Tests: E2E"
on:
pull_request:
workflow_dispatch:
inputs:
pr:
description: "PR number or PR URL to deploy/test (supports fork PRs). Example: 1234"
required: false
type: string
test_scope:
description: 'Test scope to run'
required: true
default: 'smoke'
type: choice
options:
- smoke
- all
test_config_url:
description: 'Google Sheet CSV URL for test configuration (leave empty for defaults)'
required: false
type: string
test_scenario:
description: 'Scenario name from the CSV to use for tests'
required: false
default: 'carlos_case'
type: string
base_url:
description: 'Base URL to run tests against (defaults to Netlify branch preview)'
required: false
type: string
jobs:
get_branch_name:
name: Extract branch name
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.extract_branch.outputs.branch }}
deploy_alias: ${{ steps.extract_branch.outputs.deploy_alias }}
head_sha: ${{ steps.extract_branch.outputs.head_sha }}
steps:
- name: Resolve branch / PR head (workflow_dispatch supports fork PRs)
id: extract_branch
shell: bash
env:
GH_TOKEN: ${{ github.token }}
EVENT_NAME: ${{ github.event_name }}
PR_INPUT: ${{ github.event.inputs.pr }}
REPOSITORY: ${{ github.repository }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
DEFAULT_SHA: ${{ github.sha }}
run: |
set -euo pipefail
if [[ "$EVENT_NAME" == "workflow_dispatch" && -n "${PR_INPUT:-}" ]]; then
# Accept "123" or a full PR URL ending in /pull/123
if [[ "$PR_INPUT" =~ ^[0-9]+$ ]]; then
PR_NUMBER="$PR_INPUT"
elif [[ "$PR_INPUT" =~ /pull/([0-9]+)$ ]]; then
PR_NUMBER="${BASH_REMATCH[1]}"
else
echo "Invalid pr input: '$PR_INPUT' (expected a PR number like 123 or a URL ending in /pull/123)" >&2
exit 1
fi
echo "Resolving PR: $PR_NUMBER"
PR_JSON="$(gh pr view "$PR_NUMBER" --repo "$REPOSITORY" --json headRefOid,headRefName)"
HEAD_SHA="$(echo "$PR_JSON" | jq -r .headRefOid)"
BRANCH_NAME="$(echo "$PR_JSON" | jq -r .headRefName)"
elif [[ "$EVENT_NAME" == "pull_request" ]]; then
# Use PR head directly — github.sha is the merge commit, not the PR head
HEAD_SHA="$PR_HEAD_SHA"
BRANCH_NAME="$PR_HEAD_REF"
else
BRANCH_NAME="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
HEAD_SHA="$DEFAULT_SHA"
fi
echo "branch=${BRANCH_NAME}" >> "$GITHUB_OUTPUT"
echo "head_sha=${HEAD_SHA}" >> "$GITHUB_OUTPUT"
# Sanitize branch name into a valid deploy alias
if [[ "$BRANCH_NAME" == "main" || "$BRANCH_NAME" == "master" ]]; then
DEPLOY_ALIAS="e2e-main-preview"
else
DEPLOY_ALIAS="$(echo "$BRANCH_NAME" \
| tr '[:upper:]' '[:lower:]' \
| sed 's/[^a-z0-9-]/-/g; s/^-\+//; s/-\+$//' \
| cut -c1-37)"
fi
echo "deploy_alias=${DEPLOY_ALIAS}" >> "$GITHUB_OUTPUT"
tests_e2e_netlify_prepare:
needs: [get_branch_name]
name: Deploy preview for E2E tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
# Fix: use resolved head_sha so fork PRs check out the right commit
ref: ${{ needs.get_branch_name.outputs.head_sha || github.ref }}
- uses: actions/setup-node@v3
with:
node-version: '20'
- name: Enable Corepack
run: corepack enable
- name: Get yarn cache directory
id: yarn-cache-dir
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Cache yarn dependencies
uses: actions/cache@v4
with:
path: |
${{ steps.yarn-cache-dir.outputs.dir }}
**/node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Cache npm global packages (Netlify CLI)
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-netlify-cli-v1
restore-keys: |
${{ runner.os }}-npm-
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Install Netlify CLI
run: npm install -g netlify-cli
- name: Deploy to Netlify (E2E Preview)
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ vars.NETLIFY_SITE_ID }}
DEPLOY_ALIAS: ${{ needs.get_branch_name.outputs.deploy_alias }}
run: |
echo "Deploying with alias: $DEPLOY_ALIAS"
yarn build:platform && netlify deploy \
--dir=${{ github.workspace }}/apps/platform/bundle-platform/ \
--alias="$DEPLOY_ALIAS" \
--filter platform \
--site ${{ vars.NETLIFY_SITE_ID }}
tests_e2e_netlify:
needs: [tests_e2e_netlify_prepare, get_branch_name]
name: Run end-to-end tests on Netlify PR preview
runs-on: ubuntu-latest
timeout-minutes: 50
steps:
- uses: actions/checkout@v3
with:
# Fix: use resolved head_sha so fork PRs check out the right commit
ref: ${{ needs.get_branch_name.outputs.head_sha || github.ref }}
- uses: actions/setup-node@v3
with:
node-version: '20'
- name: Enable Corepack
run: corepack enable
- name: Get yarn cache directory
id: yarn-cache-dir
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Cache yarn dependencies
uses: actions/cache@v4
with:
path: |
${{ steps.yarn-cache-dir.outputs.dir }}
**/node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Cache Playwright browsers
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-playwright-
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Install Playwright browsers
run: |
cd packages/platform-test
yarn playwright install --with-deps chromium webkit
- name: Run E2E tests
# Fix: move expressions into env vars to avoid script injection
env:
CI: true
EVENT_NAME: ${{ github.event_name }}
TEST_SCOPE: ${{ github.event.inputs.test_scope }}
PLAYWRIGHT_TEST_BASE_URL: ${{ github.event.inputs.base_url || format('https://{0}--ot-platform.netlify.app', needs.get_branch_name.outputs.deploy_alias) }}
DEBUG: pw:api
TEST_CONFIG_URL: ${{ github.event.inputs.test_config_url }}
TEST_SCENARIO: ${{ github.event.inputs.test_scenario }}
run: |
if [[ "$EVENT_NAME" == "workflow_dispatch" && "$TEST_SCOPE" == "all" ]]; then
yarn dev:test:platform:e2e
else
yarn dev:test:platform:e2e:smoke
fi
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: ${{ github.workspace }}/packages/platform-test/playwright-report
retention-days: 7