-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6a7123
commit 40b20a9
Showing
7 changed files
with
2,809 additions
and
1,565 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: Argos CI Screenshots | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
take-screenshots: | ||
if: ${{ github.ref_name == 'main' || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'Argos')) }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Prepare Yarn | ||
uses: ./.github/actions/prepare/ | ||
- name: Prepare build | ||
run: yarn prepare | ||
shell: bash | ||
- name: Checkout remote | ||
run: yarn checkout:remote | ||
- name: Generate API | ||
run: yarn generate:api | ||
shell: bash | ||
|
||
- name: Install Playwright browsers | ||
run: yarn playwright install --with-deps chromium | ||
|
||
- name: Build the website | ||
run: yarn build | ||
|
||
- name: Take screenshots with Playwright | ||
run: yarn playwright test | ||
|
||
- name: Upload screenshots to Argos | ||
run: yarn argos upload ./screenshots |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { devices } from '@playwright/test'; | ||
import type { PlaywrightTestConfig } from '@playwright/test'; | ||
|
||
const config: PlaywrightTestConfig = { | ||
webServer: { | ||
port: 3000, | ||
command: 'yarn docusaurus serve', | ||
}, | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { | ||
...devices['Desktop Chrome'], | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
export default config; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* Iframes can load lazily */ | ||
iframe, | ||
/* Avatars can be flaky due to using external sources: GitHub/Unavatar */ | ||
.avatar__photo, | ||
/* Gifs load lazily and are animated */ | ||
img[src$='.gif'], | ||
/* Algolia keyboard shortcuts appear with a little delay */ | ||
.DocSearch-Button-Keys > kbd, | ||
/* The live playground preview can often display dates/counters */ | ||
[class*='playgroundPreview'] { | ||
visibility: hidden; | ||
} | ||
|
||
/* Different docs last-update dates can alter layout */ | ||
.theme-last-updated, | ||
/* Mermaid diagrams are rendered client-side and produce layout shifts */ | ||
.docusaurus-mermaid-container { | ||
display: none; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as fs from 'fs'; | ||
import { test } from '@playwright/test'; | ||
import { argosScreenshot } from '@argos-ci/playwright'; | ||
import { extractSitemapPathnames, pathnameToArgosName } from './utils'; | ||
|
||
// Constants | ||
const siteUrl = 'http://localhost:3000'; | ||
const sitemapPath = './build/sitemap.xml'; | ||
const stylesheetPath = './screenshot.css'; | ||
const stylesheet = fs.readFileSync(stylesheetPath).toString(); | ||
|
||
// Wait for hydration, requires Docusaurus v2.4.3+ | ||
// Docusaurus adds a <html data-has-hydrated="true"> once hydrated | ||
// See https://github.com/facebook/docusaurus/pull/9256 | ||
function waitForDocusaurusHydration() { | ||
return document.documentElement.dataset.hasHydrated === 'true'; | ||
} | ||
|
||
function screenshotPathname(pathname: string) { | ||
test(`pathname ${pathname}`, async ({ page }) => { | ||
const url = siteUrl + pathname; | ||
await page.goto(url); | ||
await page.waitForFunction(waitForDocusaurusHydration); | ||
await page.addStyleTag({ content: stylesheet }); | ||
await argosScreenshot(page, pathnameToArgosName(pathname)); | ||
}); | ||
} | ||
|
||
test.describe('Docusaurus site screenshots', () => { | ||
const pathnames = extractSitemapPathnames(sitemapPath).filter((pathname) => | ||
pathname.match( | ||
' ^/$|' + | ||
'mana-calculator|' + | ||
'learn/glossary|' + | ||
'build/networks-endpoints|' + | ||
'create-mnemonic|' + | ||
'(api|apis)/core', | ||
), | ||
); | ||
console.log('Pathnames to screenshot:', pathnames); | ||
pathnames.forEach(screenshotPathname); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as cheerio from 'cheerio'; | ||
import * as fs from 'fs'; | ||
|
||
// Extract a list of pathnames, given a fs path to a sitemap.xml file | ||
// Docusaurus generates a build/sitemap.xml file for you! | ||
export function extractSitemapPathnames(sitemapPath: string): string[] { | ||
const sitemap = fs.readFileSync(sitemapPath).toString(); | ||
const $ = cheerio.load(sitemap, { xmlMode: true }); | ||
const urls: string[] = []; | ||
$('loc').each(function handleLoc() { | ||
urls.push($(this).text()); | ||
}); | ||
return urls.map((url) => new URL(url).pathname); | ||
} | ||
|
||
// Converts a pathname to a decent screenshot name | ||
export function pathnameToArgosName(pathname: string): string { | ||
return pathname.replace(/^\/|\/$/g, '') || 'index'; | ||
} |
Oops, something went wrong.