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
61 changes: 61 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Deploy demo site

# Publishes demo/ to GitHub Pages on every push to main that touches it.
#
# This replaces `npm run publish:demo` (the gh-pages package), which pushed
# the working directory to a gh-pages branch by hand. That made merging and
# deploying two separate events — a merged PR left the live site stale until
# someone remembered to run it — and published whatever happened to be on
# disk rather than a specific commit.
on:
push:
branches:
- main
paths:
- "demo/**"
- ".github/workflows/pages.yml"
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

# The site is only ever the newest commit, so a queued run can be dropped —
# but never one that is mid-deploy.
concurrency:
group: pages
cancel-in-progress: false

jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Stage the publishable demo files
run: |
mkdir -p _site
# index-local.html points at a local dist/ build and is a dev-only
# harness; the old publish script excluded it and so does this.
rsync -a --exclude 'index-local.html' demo/ _site/
# Without .nojekyll, Pages runs Jekyll and drops files starting "_".
touch _site/.nojekyll
echo "Publishing:"
ls -A _site

- name: Configure Pages
uses: actions/configure-pages@v5

- name: Upload site
uses: actions/upload-pages-artifact@v3
with:
path: _site

- name: Deploy
id: deployment
uses: actions/deploy-pages@v4
50 changes: 29 additions & 21 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,42 @@ visual-image-tool/

## Available scripts

| Script | Purpose |
| ---------------------- | ------------------------------------------------------------ |
| `npm run build` | Generate the distribution files in `dist/` |
| `npm run dev` | Run the build in watch mode |
| `npm test` | Run the unit tests once |
| `npm run test:watch` | Run the tests in watch mode |
| `npm run lint:check` | Check linting and formatting of JS/JSON with Biome |
| `npm run lint:fix` | Apply Biome fixes |
| `npm run format:check` | Check formatting of other file types with Prettier |
| `npm run format:fix` | Apply Prettier formatting |
| `npm run demo` | Serve `demo/` locally |
| `npm run publish:demo` | Publish `demo/` to GitHub Pages (all but `index-local.html`) |
| Script | Purpose |
| ---------------------- | -------------------------------------------------- |
| `npm run build` | Generate the distribution files in `dist/` |
| `npm run dev` | Run the build in watch mode |
| `npm test` | Run the unit tests once |
| `npm run test:watch` | Run the tests in watch mode |
| `npm run lint:check` | Check linting and formatting of JS/JSON with Biome |
| `npm run lint:fix` | Apply Biome fixes |
| `npm run format:check` | Check formatting of other file types with Prettier |
| `npm run format:fix` | Apply Prettier formatting |
| `npm run demo` | Serve `demo/` locally |

Linting and formatting are enforced in CI, so run `npm run lint:check` and `npm run format:check` before pushing.

### Publishing the demos

`npm run publish:demo` pushes `demo/` to the `gh-pages` branch, which is served
at <https://h4md1.fr/visual-image-tool/>.
There is nothing to run. `.github/workflows/pages.yml` deploys `demo/` to
<https://h4md1.fr/visual-image-tool/> on every push to `main` that touches it,
so merging a change to the demo publishes it.

The `--src "**/!(index-local).*"` pattern excludes `index-local.html`. That page
loads `../dist/visual-image-tool.umd.js`, which resolves above the site root
once published and 404s, so the page is only meaningful when served locally.
Everything else in `demo/` loads the published package from the CDN.
The workflow excludes `index-local.html`. That page loads
`../dist/visual-image-tool.umd.js`, which resolves above the site root once
published and 404s, so it is only meaningful when served locally with
`npm run demo`. Everything else in `demo/` loads the published package from
the CDN.

Note that `gh-pages` removes the branch's existing files before copying, but the
pattern it uses for that never matches dotfiles — anything like `.github/` that
lands on `gh-pages` stays there until it is removed by hand.
It also writes `.nojekyll`, without which Pages runs Jekyll and drops any file
whose name starts with an underscore.

To publish without a code change — or to re-deploy — run the workflow manually
from the Actions tab (`workflow_dispatch`).

This replaced `npm run publish:demo`, which pushed the working directory to a
`gh-pages` branch by hand. That made merging and deploying two separate events,
so a merged PR left the live site stale until someone remembered to run it, and
it published whatever was on disk rather than a specific commit.

## Build process

Expand Down
Loading