Skip to content

Commit 28f0efc

Browse files
committed
additional fixes to make playwrite work
1 parent 69d5706 commit 28f0efc

File tree

3 files changed

+83
-37
lines changed

3 files changed

+83
-37
lines changed

.github/workflows/build-preview.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ jobs:
9898
9999
let filesList = '';
100100
if (templateFiles.length > 0) {
101-
filesList = templateFiles.map(file => `- \`${file.filename}\``).join('\\n ');
101+
filesList = templateFiles.map(file => `- \`${file.filename}\``).join('\n ');
102102
} else {
103103
filesList = '- No template/static files changed';
104104
}
105105
106-
const fullComment = comment + '\\n ' + filesList + `
106+
const fullComment = comment + '\n ' + filesList + `
107107
108108
---
109109
<sub>Build completed by GitHub Actions</sub>`;

.github/workflows/pr-preview.yml

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,20 @@ jobs:
108108
IMAGE_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n1)
109109
echo "Using image tag: $IMAGE_TAG"
110110
111-
# Pull the image locally if it's not available
112-
echo "Pulling image to ensure it's available locally..."
113-
docker pull "$IMAGE_TAG"
111+
# Check if image is available locally first
112+
if docker images --format "table {{.Repository}}:{{.Tag}}" | grep -q "$IMAGE_TAG"; then
113+
echo "Image found locally, using local image"
114+
else
115+
echo "Image not found locally, attempting to pull..."
116+
if docker pull "$IMAGE_TAG"; then
117+
echo "Successfully pulled image"
118+
else
119+
echo "Failed to pull image, but this might be expected immediately after push"
120+
echo "Waiting 10 seconds and trying again..."
121+
sleep 10
122+
docker pull "$IMAGE_TAG" || echo "Still failed to pull, continuing with local build"
123+
fi
124+
fi
114125
115126
# Save the image as tar
116127
docker save "$IMAGE_TAG" -o wrongsecrets-preview.tar
@@ -195,15 +206,15 @@ jobs:
195206
196207
let filesList = '';
197208
if (relevantFiles.length > 0) {
198-
filesList = relevantFiles.slice(0, 10).map(file => `- \`${file.filename}\``).join('\\n ');
209+
filesList = relevantFiles.slice(0, 10).map(file => `- \`${file.filename}\``).join('\n ');
199210
if (relevantFiles.length > 10) {
200-
filesList += `\\n - ... and ${relevantFiles.length - 10} more files`;
211+
filesList += `\n - ... and ${relevantFiles.length - 10} more files`;
201212
}
202213
} else {
203214
filesList = '- No relevant files changed';
204215
}
205216
206-
const finalComment = comment + '\\n ' + filesList + `
217+
const finalComment = comment + '\n ' + filesList + `
207218
208219
Visual diff screenshots will be available shortly...
209220
@@ -320,48 +331,64 @@ jobs:
320331
sleep 2
321332
done
322333
334+
- name: Setup Node.js
335+
uses: actions/setup-node@v4
336+
with:
337+
node-version: '18'
338+
323339
- name: Install Playwright
324340
run: |
325-
npm install -g playwright@latest
326-
playwright install chromium
341+
npm install playwright@latest
342+
npx playwright install --with-deps chromium
327343
328344
- name: Take screenshots
329345
run: |
330346
mkdir -p screenshots
331347
348+
# Verify services are still running
349+
echo "Verifying services are still running..."
350+
docker ps --filter "name=pr-version" --format "table {{.Names}}\t{{.Status}}"
351+
docker ps --filter "name=main-version" --format "table {{.Names}}\t{{.Status}}"
352+
353+
# Test connectivity one more time
354+
echo "Testing connectivity..."
355+
curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 || echo "PR version not responding"
356+
curl -s -o /dev/null -w "%{http_code}" http://localhost:8081 || echo "Main version not responding"
357+
332358
node -e "
333359
const { chromium } = require('playwright');
334360
(async () => {
335-
const browser = await chromium.launch();
361+
const browser = await chromium.launch({ headless: true });
336362
const page = await browser.newPage();
337363
await page.setViewportSize({ width: 1280, height: 1024 });
338364
339365
try {
340366
// PR version screenshots
341367
console.log('Taking PR screenshots...');
342-
await page.goto('http://localhost:8080', { waitUntil: 'networkidle' });
368+
await page.goto('http://localhost:8080', { waitUntil: 'networkidle', timeout: 30000 });
343369
await page.screenshot({ path: 'screenshots/pr-home.png', fullPage: true });
344370
345-
await page.goto('http://localhost:8080/about', { waitUntil: 'networkidle' });
371+
await page.goto('http://localhost:8080/about', { waitUntil: 'networkidle', timeout: 30000 });
346372
await page.screenshot({ path: 'screenshots/pr-about.png', fullPage: true });
347373
348374
// Try to get a challenge page
349-
await page.goto('http://localhost:8080/challenge/1', { waitUntil: 'networkidle' });
375+
await page.goto('http://localhost:8080/challenge/1', { waitUntil: 'networkidle', timeout: 30000 });
350376
await page.screenshot({ path: 'screenshots/pr-challenge.png', fullPage: true });
351377
352378
// Main version screenshots
353379
console.log('Taking main branch screenshots...');
354-
await page.goto('http://localhost:8081', { waitUntil: 'networkidle' });
380+
await page.goto('http://localhost:8081', { waitUntil: 'networkidle', timeout: 30000 });
355381
await page.screenshot({ path: 'screenshots/main-home.png', fullPage: true });
356382
357-
await page.goto('http://localhost:8081/about', { waitUntil: 'networkidle' });
383+
await page.goto('http://localhost:8081/about', { waitUntil: 'networkidle', timeout: 30000 });
358384
await page.screenshot({ path: 'screenshots/main-about.png', fullPage: true });
359385
360-
await page.goto('http://localhost:8081/challenge/1', { waitUntil: 'networkidle' });
386+
await page.goto('http://localhost:8081/challenge/1', { waitUntil: 'networkidle', timeout: 30000 });
361387
await page.screenshot({ path: 'screenshots/main-challenge.png', fullPage: true });
362388
363389
} catch (error) {
364390
console.error('Screenshot error:', error);
391+
process.exit(1);
365392
} finally {
366393
await browser.close();
367394
}

.github/workflows/visual-diff.yml

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,37 +84,56 @@ jobs:
8484
docker run -d -p 8081:8080 --name main-version wrongsecrets-main
8585
sleep 30
8686
87+
- name: Setup Node.js
88+
uses: actions/setup-node@v4
89+
with:
90+
node-version: '18'
91+
8792
- name: Install Playwright
8893
run: |
89-
npm install -g playwright
90-
playwright install chromium
94+
npm install playwright@latest
95+
npx playwright install --with-deps chromium
9196
9297
- name: Take screenshots
9398
run: |
9499
mkdir -p screenshots
95100
96-
# Screenshot main pages
101+
# Verify services are running
102+
echo "Verifying services are running..."
103+
docker ps --filter "name=pr-version" --format "table {{.Names}}\t{{.Status}}"
104+
docker ps --filter "name=main-version" --format "table {{.Names}}\t{{.Status}}"
105+
106+
# Screenshot main pages with error handling
97107
node -e "
98108
const { chromium } = require('playwright');
99109
(async () => {
100-
const browser = await chromium.launch();
110+
const browser = await chromium.launch({ headless: true });
101111
const page = await browser.newPage();
102-
103-
// PR version screenshots
104-
await page.goto('http://localhost:8080');
105-
await page.screenshot({ path: 'screenshots/pr-home.png', fullPage: true });
106-
107-
await page.goto('http://localhost:8080/about');
108-
await page.screenshot({ path: 'screenshots/pr-about.png', fullPage: true });
109-
110-
// Main version screenshots
111-
await page.goto('http://localhost:8081');
112-
await page.screenshot({ path: 'screenshots/main-home.png', fullPage: true });
113-
114-
await page.goto('http://localhost:8081/about');
115-
await page.screenshot({ path: 'screenshots/main-about.png', fullPage: true });
116-
117-
await browser.close();
112+
await page.setViewportSize({ width: 1280, height: 1024 });
113+
114+
try {
115+
// PR version screenshots
116+
console.log('Taking PR screenshots...');
117+
await page.goto('http://localhost:8080', { waitUntil: 'networkidle', timeout: 30000 });
118+
await page.screenshot({ path: 'screenshots/pr-home.png', fullPage: true });
119+
120+
await page.goto('http://localhost:8080/about', { waitUntil: 'networkidle', timeout: 30000 });
121+
await page.screenshot({ path: 'screenshots/pr-about.png', fullPage: true });
122+
123+
// Main version screenshots
124+
console.log('Taking main branch screenshots...');
125+
await page.goto('http://localhost:8081', { waitUntil: 'networkidle', timeout: 30000 });
126+
await page.screenshot({ path: 'screenshots/main-home.png', fullPage: true });
127+
128+
await page.goto('http://localhost:8081/about', { waitUntil: 'networkidle', timeout: 30000 });
129+
await page.screenshot({ path: 'screenshots/main-about.png', fullPage: true });
130+
131+
} catch (error) {
132+
console.error('Screenshot error:', error);
133+
process.exit(1);
134+
} finally {
135+
await browser.close();
136+
}
118137
})();
119138
"
120139

0 commit comments

Comments
 (0)