Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 41 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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
Empty file added .nojekyll
Empty file.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,24 @@ python3 -m http.server 8099
```

Then open <http://127.0.0.1:8099/>. 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://<owner>.github.io/<repo>/`.

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

Expand Down
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
<meta name="description" content="MemeForge — a meme studio in your browser. Thousands of templates, every Google font, layers, filters, animated GIF export. No account, no watermark, works offline.">
<meta name="theme-color" content="#0E0F12">
<title>MemeForge — meme studio</title>
<meta property="og:type" content="website">
<meta property="og:title" content="MemeForge — meme studio">
<meta property="og:description" content="Templates, every Google font, layers, filters and animated GIF export. Runs entirely in your browser.">
<meta property="og:image" content="docs/screenshot.png">
<meta name="twitter:card" content="summary_large_image">
<link rel="manifest" href="app.webmanifest">
<link rel="icon" href="assets/icon.svg" type="image/svg+xml">
<link rel="stylesheet" href="css/app.css">
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
67 changes: 67 additions & 0 deletions tests/subpath.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// GitHub Pages serves a project site from /<repo>/, 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);
Loading