feat: run snippets from files #64
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: Playwright | |
on: | |
pull_request: | |
types: [labeled, synchronize, opened, reopened] | |
push: | |
branches: | |
- 'core' | |
paths-ignore: | |
- '**.md' | |
- '**.txt' | |
- '.gitignore' | |
- 'docs/**' | |
workflow_dispatch: | |
permissions: | |
contents: write | |
pull-requests: write | |
actions: read | |
concurrency: | |
group: playwright-${{ github.event_name }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.ref }} | |
cancel-in-progress: ${{ github.event_name == 'pull_request' }} | |
jobs: | |
playwright-default: | |
name: Playwright tests (Default Mode) | |
runs-on: ubuntu-22.04 | |
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v4 | |
- name: Set up PHP | |
uses: codesnippetspro/setup-php@v2 | |
with: | |
php-version: "8.1" | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: .node-version | |
cache: 'npm' | |
- name: Compute dependency hash | |
id: deps-hash | |
run: | | |
set -euo pipefail | |
tmpfile=$(mktemp) | |
for f in src/composer.lock package-lock.json; do | |
if [ -f "$f" ]; then | |
cat "$f" >> "$tmpfile" | |
fi | |
done | |
if [ -s "$tmpfile" ]; then | |
deps_hash=$(shasum -a 1 "$tmpfile" | awk '{print $1}' | cut -c1-8) | |
else | |
deps_hash=$(echo "${GITHUB_SHA:-unknown}" | cut -c1-8) | |
fi | |
echo "deps_hash=$deps_hash" >> "$GITHUB_OUTPUT" | |
- name: Get build cache | |
id: deps-cache | |
uses: actions/cache/restore@v4 | |
with: | |
path: | | |
node_modules | |
src/vendor | |
key: ${{ runner.os }}-deps-${{ steps.deps-hash.outputs.deps_hash }} | |
restore-keys: | | |
${{ runner.os }}-deps- | |
- name: Install workflow dependencies (wp-env, playwright) | |
if: steps.deps-cache.outputs.cache-hit != 'true' | |
run: npm run prepare-environment:ci && npm run bundle | |
- name: Save vendor and node_modules cache | |
if: steps.deps-cache.outputs.cache-hit != 'true' | |
uses: actions/cache/save@v4 | |
with: | |
path: | | |
src/vendor | |
node_modules | |
key: ${{ runner.os }}-deps-${{ steps.deps-hash.outputs.deps_hash }} | |
- name: Start WordPress environment | |
run: | | |
npx wp-env start | |
- name: Activate code-snippets plugin | |
run: npx wp-env run cli wp plugin activate code-snippets | |
- name: WordPress debug information | |
run: | | |
npx wp-env run cli wp core version | |
npx wp-env run cli wp --info | |
- name: Install playwright/test | |
run: | | |
npx playwright install chromium | |
- name: Run Playwright tests (Default Mode) | |
run: npm run test:playwright -- --project=chromium-db-snippets | |
- name: Stop WordPress environment | |
if: always() | |
run: npx wp-env stop | |
- uses: actions/upload-artifact@v4 | |
if: always() | |
with: | |
name: playwright-test-results-default-mode | |
path: test-results/ | |
if-no-files-found: ignore | |
retention-days: 2 | |
playwright-file-based-execution: | |
name: Playwright tests (File-based Execution) | |
runs-on: ubuntu-22.04 | |
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v4 | |
- name: Set up PHP | |
uses: codesnippetspro/setup-php@v2 | |
with: | |
php-version: "8.1" | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: .node-version | |
cache: 'npm' | |
- name: Compute dependency hash | |
id: deps-hash | |
run: | | |
set -euo pipefail | |
tmpfile=$(mktemp) | |
for f in src/composer.lock package-lock.json; do | |
if [ -f "$f" ]; then | |
cat "$f" >> "$tmpfile" | |
fi | |
done | |
if [ -s "$tmpfile" ]; then | |
deps_hash=$(shasum -a 1 "$tmpfile" | awk '{print $1}' | cut -c1-8) | |
else | |
deps_hash=$(echo "${GITHUB_SHA:-unknown}" | cut -c1-8) | |
fi | |
echo "deps_hash=$deps_hash" >> "$GITHUB_OUTPUT" | |
- name: Get build cache | |
id: deps-cache | |
uses: actions/cache/restore@v4 | |
with: | |
path: | | |
node_modules | |
src/vendor | |
key: ${{ runner.os }}-deps-${{ steps.deps-hash.outputs.deps_hash }} | |
restore-keys: | | |
${{ runner.os }}-deps- | |
- name: Install workflow dependencies (wp-env, playwright) | |
if: steps.deps-cache.outputs.cache-hit != 'true' | |
run: npm run prepare-environment:ci && npm run bundle | |
- name: Save vendor and node_modules cache | |
if: steps.deps-cache.outputs.cache-hit != 'true' | |
uses: actions/cache/save@v4 | |
with: | |
path: | | |
src/vendor | |
node_modules | |
key: ${{ runner.os }}-deps-${{ steps.deps-hash.outputs.deps_hash }} | |
- name: Start WordPress environment | |
run: | | |
npx wp-env start | |
- name: Activate code-snippets plugin | |
run: npx wp-env run cli wp plugin activate code-snippets | |
- name: WordPress debug information | |
run: | | |
npx wp-env run cli wp core version | |
npx wp-env run cli wp --info | |
- name: Install playwright/test | |
run: | | |
npx playwright install chromium | |
- name: Run Playwright tests (File-based Execution) | |
run: npm run test:playwright -- --project=chromium-file-based-snippets | |
- name: Verify file-based execution enabled | |
if: always() | |
run: | | |
npx wp-env run cli wp eval 'echo file_exists(WP_CONTENT_DIR . "/code-snippets/flat-files-enabled.flag") ? "ENABLED" : "DISABLED";' | |
- name: Stop WordPress environment | |
if: always() | |
run: npx wp-env stop | |
- uses: actions/upload-artifact@v4 | |
if: always() | |
with: | |
name: playwright-test-results-file-based-execution | |
path: test-results/ | |
if-no-files-found: ignore | |
retention-days: 2 | |
test-result: | |
needs: [playwright-default, playwright-file-based-execution] | |
if: always() && (needs.playwright-default.result != 'skipped' || needs.playwright-file-based-execution.result != 'skipped') | |
runs-on: ubuntu-22.04 | |
name: Playwright - Test Results Summary | |
steps: | |
- name: Test status summary | |
run: | | |
echo "Default Mode: ${{ needs.playwright-default.result }}" | |
echo "File-based Execution: ${{ needs.playwright-file-based-execution.result }}" | |
- name: Check overall status | |
if: ${{ (needs.playwright-default.result != 'success' && needs.playwright-default.result != 'skipped') || (needs.playwright-file-based-execution.result != 'success' && needs.playwright-file-based-execution.result != 'skipped') }} | |
run: exit 1 |