Shipping these docs with GitHub Actions
The documentation you are reading is Markdown. A push to the source repository turns it into static HTML and publishes that HTML to a second repository, which GitHub Pages serves. This post is the setup, written down so the next person does not have to rediscover it.
Two repositories, one job
The site uses a split that is common for organization Pages sites:
| Repository | Contains | Role |
|---|---|---|
nirantarasi/nirantarasi | Markdown, VitePress config, tests | Source of truth |
nirantarasi/nirantarasi.github.io | Only generated HTML, CSS, and JS | What Pages serves |
A repository named <organization>.github.io owns the organization's root URL, so https://nirantarasi.github.io/ can only come from the second repository. Everything else is ordinary: the build runs in the first repository and the result has to land in the second one.
That cross-repository write is the only genuinely awkward part. Building the site is not.
Let Pages serve a finished artifact
GitHub Pages can build a site with Jekyll, but Jekyll is a second build system running after the first one has already finished. It re-processes Markdown, treats {{ ... }} as Liquid, and can choke on code samples that show template syntax. There is nothing to gain: VitePress already produced the final files.
Set Settings → Pages → Source to GitHub Actions in the publishing repository. The legacy "pages build and deployment" workflow then stops running and only your own workflow deploys.
This matters when a deploy starts failing for reasons that have nothing to do with your content. A Jekyll error in a repository that contains no Jekyll is a strong hint that the Pages source is still set to a branch.
The workflow
One workflow file in the source repository does everything:
name: Build and publish documentation
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run build
- run: npm run check:links
- run: npm test
- uses: actions/checkout@v4
with:
repository: nirantarasi/nirantarasi.github.io
token: ${{ secrets.PAGES_TOKEN }}
path: pages
- name: Publish
run: |
rsync -a --delete --exclude='.git/' --exclude='.github/' \
.vitepress/dist/ pages/
cd pages
git add -A
if git diff --cached --quiet; then
echo "No changes to publish."
exit 0
fi
git -c user.name="nirantarasi-docs-bot" \
-c user.email="docs@nirantarasi.dev" \
commit -m "Deploy docs"
git pushA few details are load-bearing.
Checkout the publish repository with path. The second actions/checkout puts the publish repository in pages/ without disturbing the source checkout at the workspace root. It also configures the remote with the token, so the plain git push at the end works without any URL rewriting.
Use rsync --delete. A build only writes the files it knows about. Without --delete, a page you removed stays published forever. --delete makes the published tree mirror the build exactly.
Exclude .git and .github. The first is the publish repository's own history; the second contains its Pages workflow. Deleting either turns a content update into a broken repository.
Exit early when nothing changed. git diff --cached --quiet keeps the publish repository free of empty commits on metadata-only changes.
Fail loudly when the token is missing. A short check before the second checkout prints a readable error instead of a confusing authentication failure:
- name: Verify publish token
env:
PAGES_TOKEN: ${{ secrets.PAGES_TOKEN }}
run: |
if [ -z "$PAGES_TOKEN" ]; then
echo "::error::The PAGES_TOKEN secret is not set."
exit 1
fiAuthenticating the cross-repository write
The source repository has to authenticate as something that may write to the publish repository. Three options exist, and the choice depends on what your organization allows.
Deploy key (if enabled)
An SSH deploy key scoped to one repository, with write access, added as PAGES_DEPLOY_KEY. This is the smallest possible credential. Some organizations disable deploy keys for security reasons, in which case the setting page reports that deploy keys are disabled and this route is closed.
Fine-grained personal access token (the one used here)
A fine-grained token, scoped to the organization, limited to the single publish repository, with Contents: read and write and a fixed expiry. Store it as a repository secret named PAGES_TOKEN.
Two things are easy to get wrong:
- The resource owner must be the organization, not your personal account. A personal-scoped token cannot be granted access to an organization's private repositories.
- If the organization reviews tokens, the token stays pending until an owner approves it under Organization settings → Personal access tokens.
GitHub App (when tokens are restricted)
Create a GitHub App with Contents: read and write, install it on the publish repository only, and store its APP_ID and APP_PRIVATE_KEY as secrets. Then mint a short-lived installation token at the start of the job:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}Pass the result as the token: input of the second actions/checkout, and use ${{ steps.app-token.outputs.token }} in place of secrets.PAGES_TOKEN. The token expires in about an hour and nothing long-lived sits in the secret store.
What to check when a deploy fails
| Symptom | Likely cause |
|---|---|
The PAGES_TOKEN secret is not set | Secret missing, or the name differs by a character |
Permission denied / 403 | Token lacks Contents write, or targets the wrong repository |
| A Jekyll error appears in the log | Pages source is still set to a branch |
| Deleted pages remain live | rsync is missing --delete |
| The publish repository's workflow vanishes | .github/ was not excluded from rsync |
Keep the manual path
CI is convenient, but a small script that does the same three steps — build, rsync into the publish repository, commit and push — is worth keeping for the day Actions is unavailable or a secret has expired. It uses your own credentials, so it is not blocked by anything the organization restricts for workflows.
That is the whole setup. The site now rebuilds on every push, publishes only when the output actually changed, and the only credential involved is one that can write to one repository.