diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 0000000..ff8615e --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,41 @@ +name: Deploy to GitHub Pages + +# MemeForge is a static site, so the whole repository is the artifact. +# Runs on every push to main, or on demand from any branch. +on: + push: + branches: [main] + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +# Let a running deploy finish rather than cancelling it mid-publish. +concurrency: + group: pages + cancel-in-progress: false + +jobs: + deploy: + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - uses: actions/checkout@v4 + + - name: Keep Jekyll out of it + # Without this, Jekyll's default excludes would drop vendor/ and the + # app would load with no libraries at all. + run: touch .nojekyll + + - uses: actions/configure-pages@v5 + + - uses: actions/upload-pages-artifact@v3 + with: + path: '.' + + - id: deployment + uses: actions/deploy-pages@v4 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..aa61346 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,41 @@ +name: Tests + +# Kept separate from the Pages workflow on purpose: a flaky test run should +# never be the reason the site stops publishing. +on: + push: + branches: ['**'] + pull_request: + workflow_dispatch: + +jobs: + playwright: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 20 + + - run: npm install --no-audit --no-fund + + - run: npx playwright install --with-deps chromium + + - name: Serve the site + run: | + python3 -m http.server 8099 >/tmp/http.log 2>&1 & + for i in $(seq 1 30); do + curl -sf http://127.0.0.1:8099/index.html >/dev/null && exit 0 + sleep 1 + done + echo "server never came up" && cat /tmp/http.log && exit 1 + + - run: npm test + + - if: always() + uses: actions/upload-artifact@v4 + with: + name: screenshots + path: tests/shots/ + if-no-files-found: ignore diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index 4ff8ca8..82de5b4 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,24 @@ python3 -m http.server 8099 ``` Then open . Deploying means copying the folder to any -static host (GitHub Pages, Netlify, an S3 bucket). +static host. + +## Publishing to GitHub Pages + +`.github/workflows/pages.yml` publishes the repository as-is. Two things to do +once: + +1. **Settings → Pages → Build and deployment → Source: GitHub Actions.** +2. Merge to `main`. Every push to `main` then republishes; you can also run the + workflow by hand from the Actions tab once it is on the default branch. + +The site lands at `https://.github.io//`. + +Notes if you fork or rename things: `.nojekyll` is required, because Jekyll's +default excludes would drop `vendor/` and the app would load with no libraries +at all. Every path in the app is relative, so a project site served from a +subdirectory works without configuration — `npm run test:subpath` is there to +prove it (serve the parent directory on port 8100 first). ## Tests diff --git a/index.html b/index.html index 22a05c3..c783707 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,11 @@ MemeForge — meme studio + + + + + diff --git a/package.json b/package.json index d1cb4a5..560383e 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "dev": "npx --yes http-server -p 8099 -c-1 .", "fixtures": "node tests/make-fixtures.mjs", "test": "node tests/make-fixtures.mjs && node tests/smoke.mjs && node tests/offline.mjs", - "test:offline": "node tests/offline.mjs" + "test:offline": "node tests/offline.mjs", + "test:subpath": "node tests/subpath.mjs" }, "devDependencies": { "playwright": "^1.56.1" diff --git a/tests/subpath.mjs b/tests/subpath.mjs new file mode 100644 index 0000000..84bc8d0 --- /dev/null +++ b/tests/subpath.mjs @@ -0,0 +1,67 @@ +// GitHub Pages serves a project site from //, not from the domain root. +// This checks that every path in the app — modules, fonts, the service worker, +// the GIF encoder's worker script — still resolves one directory down. +// +// (cd .. && python3 -m http.server 8100 &) +// node tests/subpath.mjs + +import { chromium } from 'playwright'; +import { basename, resolve } from 'node:path'; + +const repo = basename(resolve('.')); +const BASE = process.env.SUBPATH_URL || `http://127.0.0.1:8100/${repo}`; + +const results = []; +const check = (name, ok, detail = '') => { + results.push(ok); + console.log(`${ok ? 'PASS' : 'FAIL'} ${name}${detail ? ` — ${detail}` : ''}`); +}; + +const browser = await chromium.launch(); +const page = await browser.newPage({ viewport: { width: 1280, height: 820 } }); + +const problems = []; +page.on('pageerror', (err) => problems.push(`pageerror: ${err.message}`)); +page.on('response', (res) => { + if (res.status() >= 400 && res.url().startsWith(new URL(BASE).origin)) { + problems.push(`${res.status()} ${res.url()}`); + } +}); + +const host = new URL(BASE).hostname; +await page.route('**/*', (route) => ( + new URL(route.request().url()).hostname === host ? route.continue() : route.abort() +)); + +await page.goto(`${BASE}/index.html`); +await page.waitForTimeout(4000); + +await page.setInputFiles('#file-input', 'tests/fixtures/sample.png'); +await page.waitForFunction(() => window.studio?.hasMedia, null, { timeout: 15000 }); +await page.locator('.rail-btn[data-panel="text"]').click(); +await page.locator('#add-classic').click(); +await page.waitForTimeout(500); + +check('canvas takes the picture', await page.evaluate(() => window.studio.canvas.width === 640)); +check('bundled interface fonts load', await page.evaluate( + () => document.fonts.check('400 20px Archivo') && document.fonts.check('400 20px Anton'), +)); + +const scopes = await page.evaluate( + () => navigator.serviceWorker.getRegistrations().then((regs) => regs.map((r) => r.scope)), +); +check('service worker scoped to the subpath', scopes.some((s) => s.endsWith(`/${repo}/`)), scopes.join(',')); + +await page.setInputFiles('#file-input', 'tests/fixtures/sample.gif'); +await page.waitForFunction(() => window.studio?.isAnimated, null, { timeout: 20000 }); +const size = await page.evaluate(async () => (await window.studio.toGifBlob({ scale: 1 })).size); +check('GIF worker script resolves', size > 2000, `${size} bytes`); + +check('no 404s and no exceptions', problems.length === 0, problems.slice(0, 3).join(' | ')); + +await page.screenshot({ path: 'tests/shots/07-subpath.png' }); +await browser.close(); + +const failed = results.filter((ok) => !ok).length; +console.log(`\n${results.length - failed}/${results.length} checks passed`); +process.exit(failed ? 1 : 0);