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

Get subdomain multisite tests working properly #148

Merged
merged 22 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ff53ea9
add copying the changes in the PR to the subdomain tests
jazzsequence Jul 31, 2024
75e933f
switch to git mode before we try pushing things
jazzsequence Jul 31, 2024
20daa86
remove color tags
jazzsequence Jul 31, 2024
b425a1d
exclude node_modules from rsync
jazzsequence Jul 31, 2024
3f0e604
add multisite config to the fixture site
jazzsequence Jul 31, 2024
7405de3
fix quoting
jazzsequence Jul 31, 2024
90296bb
remove lingering ${type} vars and stray quote
jazzsequence Jul 31, 2024
1619e06
don't run playwright tests if files we don't care about were affected
jazzsequence Jul 31, 2024
3312f0d
remove color tags
jazzsequence Jul 31, 2024
fe79af5
don't save in a variable
jazzsequence Jul 31, 2024
f8ae367
exclude node_modules from rsync
jazzsequence Jul 31, 2024
47e8d92
fix quoting
jazzsequence Jul 31, 2024
3f4d299
remove lingering ${type} vars and stray quote
jazzsequence Jul 31, 2024
dffdcfb
don't run playwright tests if files we don't care about were affected
jazzsequence Jul 31, 2024
2899f36
move the wait to earlier
jazzsequence Jul 31, 2024
60c3da8
give up on the multisite checking
jazzsequence Jul 31, 2024
fc08498
install graphql as part of the workflow
jazzsequence Jul 31, 2024
38c9386
clear ache after installing graphql
jazzsequence Jul 31, 2024
17d4860
break the subdomain sites up
jazzsequence Jul 31, 2024
46aaa50
allow the graphql endpoint to be passed
jazzsequence Jul 31, 2024
22c3022
copy the application.php for subdom
jazzsequence Jul 31, 2024
4e9d827
add more debugging info to failure output
jazzsequence Aug 1, 2024
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
4 changes: 2 additions & 2 deletions .github/tests/wpcm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { test, expect } from "@playwright/test";
const exampleArticle = "Hello world!";
const siteTitle = process.env.SITE_NAME || "WPCM Playwright Tests";
const siteUrl = process.env.SITE_URL || "https://dev-wpcm-playwright-tests.pantheonsite.io";
let graphqlEndpoint = process.env.GRAPHQL_ENDPOINT || `${siteUrl}/wp/graphql`;

test("homepage loads and contains example content", async ({ page }) => {
await page.goto(siteUrl);
Expand Down Expand Up @@ -41,8 +42,7 @@ test("validate core resource URLs", async ({ request }) => {
});

test("graphql is able to access hello world post", async ({ request }) => {
let graphqlEndpoint = `${siteUrl}/wp/graphql`;
let apiRoot = await request.get(`${siteUrl}/wp/graphql`);
let apiRoot = await request.get(graphqlEndpoint);
// If the above request doesn't resolve, it's because we're on a subsite where the path is ${siteUrl}/graphql -- similar to the rest api.
if (!apiRoot.ok()) {
graphqlEndpoint = `${siteUrl}/graphql`;
Expand Down
82 changes: 75 additions & 7 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
name: WordPress Composer Playwright Tests
on:
pull_request:
paths-ignore:
- '.github/workflows/ci.yml'
- '.github/workflows/composer-diff.yml'
- '.github/workflows/phpcbf.yml'
- '.github/workflows/sage-test.yml'
- '.github/workflows/sync-default.yml'
- '.github/tests/*.bats'
- 'private/scripts/**'
- 'docs/**'
- '*.md'
- 'phpcs.yml'
- 'wp-cli.yml'
- '.lando.upstream.yml'
- 'CODEOWNERS'
- '.editorconfig'
types:
- opened
- reopened
Expand Down Expand Up @@ -358,6 +373,7 @@ jobs:
echo "SITE_NAME=$SITE_NAME" >> $GITHUB_ENV
echo "SITE_URL=$SITE_URL" >> $GITHUB_ENV
echo "SUBDOMAIN_URL=$SUBDOMAIN_URL" >> $GITHUB_ENV
echo "SITE_ID=wpcm-subdom-playwright-tests" >> $GITHUB_ENV

- name: Install SSH keys
uses: webfactory/[email protected]
Expand Down Expand Up @@ -385,13 +401,65 @@ jobs:
echo "Install Playwright Browsers"
npx playwright install --with-deps

- name: Run Playwright tests
- name: Copy changes from PR
run: |
echo "Commit Message: ${{ env.COMMIT_MSG }}"
echo "Setting up some git config..."
git config --global user.email "[email protected]"
git config --global user.name "Pantheon WPCM Bot"

echo "Switching to git mode..."
terminus connection:set "${{ env.SITE_ID }}".dev git

echo "Clone the site locally and copy PR updates"
terminus local:clone ${{ env.SITE_ID }}
cd ~/pantheon-local-copies/"${{ env.SITE_ID }}"

echo "Copying latest changes and committing to the site."
rsync -a --exclude='.git' --exclude='status-*.txt' --exclude="node_modules" "${{ github.workspace }}/" .
git add -A
git commit -m "Update to latest commit: ${{ env.COMMIT_MSG }}" || true

echo "Installing wp-graphql..."
composer require wp-graphql/wp-graphql
git add composer.json composer.lock
git commit -m "Add WP-GraphQL plugin" || true

echo "Copying the subdomain multisite config/application.php file..."
cp -f "${{ github.workspace }}/.github/fixtures/config/application.subdom.php" config/application.php
git add config/application.php
git commit -m "Add subdomain multisite config" || true

# Push and wait for the git push to finish.
git push origin master || true
terminus workflow:wait "${{ env.SITE_ID }}".dev

echo "Checking WordPress install status"
terminus wp "${{ env.SITE_ID }}".dev -- cli info

# Activte WP-GraphQL plugin
terminus wp "${{ env.SITE_ID }}".dev -- plugin activate wp-graphql
terminus env:clear-cache "${{ env.SITE_ID }}".dev

# Run curl checks against the site URLs to ensure the main site and the subdomain site exist.
echo "Checking site URLs"
SITE_URL_TEST=$(curl -s -o /dev/null -w "%{http_code}" ${{ env.SITE_URL }})
SUBDOMAIN_URL_TEST=$(curl -s -o /dev/null -w "%{http_code}" ${{ env.SUBDOMAIN_URL }})
if [ $SITE_URL_TEST -ne 200 ] || [ $SUBDOMAIN_URL_TEST -ne 200 ]; then
echo "One or more site URLs are not returning a 200 status code. Exiting."
echo "${{ env.SITE_URL }} - ${SITE_URL_TEST}"
echo "${{ env.SUBDOMAIN_URL }} - ${SUBDOMAIN_URL_TEST}"
exit 1
fi
- name: Run Playwright tests on main site
env:
SITE_NAME: ${{ env.SITE_NAME }}
SITE_URL: ${{ env.SITE_URL }}
run: |
npm run test .github/tests/wpcm.spec.ts
SITE_NAME=Foo
SITE_URL=${{ env.SUBDOMAIN_URL }}
echo "Running Playwright tests on WordPress Subdomain subsite"
npm run test .github/tests/wpcm.spec.ts
GRAPHQL_ENDPOINT: ${{ env.SITE_URL }}/wp/graphql
run: npm run test .github/tests/wpcm.spec.ts
- name: Run Playwright tests on subdomain site
env:
SITE_NAME: Foo
SITE_URL: ${{ env.SUBDOMAIN_URL }}
GRAPHQL_ENDPOINT: ${{ env.SUBDOMAIN_URL }}/wp/graphql
run: npm run test .github/tests/wpcm.spec.ts
2 changes: 1 addition & 1 deletion devops/scripts/setup-playwright-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ copy_pr_updates() {
echo "Commit Message: ${commit_msg}"
cd ~/pantheon-local-copies/"${site_id}"
echo -e "${YELLOW}Copying latest changes and committing to the site.${RESET}"
rsync -a --exclude='.git' --exclude='status-*.txt' "${workspace}/" .
rsync -a --exclude='.git' --exclude='status-*.txt' --exclude="node_modules" "${workspace}/" .
git add -A
git commit -m "Update to latest commit: ${commit_msg}" || true
git push origin master || true
Expand Down
Loading