Setting up
More Advanced
GitHub & GitHub Pages
the simple GitHub Pages setup works, but requires you to build and push a docs folder every time. Here we replace that with a GitHub Actions workflow that builds and deploys your site automatically on every push
Clean up, and update your build script to output to dist
- If you previously followed the simple GitHub Pages setup and committed a
docsfolder to your repository, delete it now. The new workflow builds the site itself and doesn’t need a checked-in output folder. - Open
package.jsonin your plain text editor and change thebuildscript so it outputs to../distinstead of../docs. The whole file should look like this:
{ "dependencies": { "@observablehq/notebook-kit": "latest" }, "scripts": { "preview": "notebooks preview --root nbks", "build": "notebooks build --root nbks --out ../dist -- *.html" } }
- Save the file.
Why
distand notdocs?distis a common convention for build output that gets generated, rather than hand-maintained and committed. Once GitHub Actions is building your site for you, there’s no need to commit the built files at all — you’ll adddist/to your.gitignore(it’s already there if you used the.gitignorefrom an earlier notebook).
Create the GitHub Actions workflow file
- Copy the YAML below into your plain text editor:
name: Deploy on: workflow_call: {} workflow_dispatch: {} push: branches: [main] jobs: deploy: runs-on: ubuntu-latest permissions: pages: write id-token: write environment: name: github-pages url: \${{ steps.deployment.outputs.page_url }} steps: - uses: actions/checkout@v6 - uses: actions/setup-node@v6 with: node-version: 24 cache: npm - run: npm ci - run: npm run build - uses: actions/configure-pages@v6 - uses: actions/upload-pages-artifact@v5 with: path: ./dist - name: Deploy id: deployment uses: actions/deploy-pages@v5
- Inside your project folder, create a folder called
.github, and inside that a folder calledworkflows(so the path is.github/workflows). Remember the top level folder here begins with a full-stop, so it will be invisible-by-default in your Finder or file system. - Save the file you copied as
deploy.ymlinside thatworkflowsfolder, giving the full path.github/workflows/deploy.yml.
What does this file do? It tells GitHub: “whenever someone pushes to the
mainbranch, install dependencies (npm ci), run the build (npm run build), and deploy whatever ends up in thedistfolder to GitHub Pages.”
Commit, push, and switch GitHub Pages over to GitHub Actions
- Back in the Terminal, inside your project folder,
add,commit, andpushyour changes:
git add . git commit -m "add deploy workflow" git push
- Go to GitHub and open your project’s repository. Click the Settings tab.
- Click the Pages item from the sidebar on the left.
- Under Build and deployment, change the Source to GitHub Actions (if it isn’t already set that way).
- Click the Actions tab. You should see a workflow run in progress (triggered automatically by your
push) — click it to watch its progress.
⚠️ First run may fail. If the very first run failed before you switched the Pages source to GitHub Actions, don’t worry — that’s expected. Click Deploy on the left of the Actions tab, then click the Run workflow button on the right to trigger it manually. This time it should build and deploy successfully.
- Once the workflow finishes with a green check mark, go back to your repo’s Settings → Pages. You’ll see the live URL for your site there, of the form:
https://<YourUserName>.github.io/<RepoName>
From now on, every time you push a change to main, GitHub Actions will automatically rebuild and redeploy your site — no manual npm run build required.