Publish to GitHub Pages¶
Publish a Guidedog site to GitHub Pages in one of two ways. GitHub Actions can build
and deploy it on each push, with released Guidedog and GitHub’s official Pages
actions, and no personal token. Or guidedog-pages can publish it from your own
machine, whenever you ask or whenever the sources change. Neither needs Python or an
Odin compiler.
Build and deploy with GitHub Actions¶
Prepare the project¶
Create a project if you do not have one:
guidedog quickstart docs -q -p 'Project manual' -a 'Project contributors'
guidedog build -b html docs build/site -W
guidedog serve docs
Commit the sources, configuration, templates, and static files. Keep generated
output out of Git. In the repository’s Settings -> Pages, choose GitHub Actions
as the publishing source. Restrict the github-pages environment to main;
add approval rules if your team needs them. GitHub plan and organization policies
may limit Pages availability.
Add the workflow¶
Save this as .github/workflows/docs-pages.yml. It assumes a project in docs
and a source branch named main. Change those two names for your project.
The build runs for pull requests too; only main can deploy.
name: Documentation
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: docs-pages-${{ github.ref }}
cancel-in-progress: false
defaults:
run:
shell: bash
jobs:
build:
runs-on: ubuntu-22.04
timeout-minutes: 15
permissions:
contents: read
pages: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Install Guidedog
env:
GUIDEDOG_VERSION: 0.6.3
GUIDEDOG_SHA256: 35eca388ac7a4061076bfa688102127acdb2f1db30e183c8a5b8002362e359d0
run: |
set -euo pipefail
archive="$RUNNER_TEMP/guidedog-linux-amd64.tar.gz"
url="https://github.com/insanai/guidedog/releases/download/v${GUIDEDOG_VERSION}/guidedog-linux-amd64.tar.gz"
curl --proto '=https' --tlsv1.2 --fail --show-error --silent --location "$url" -o "$archive"
printf '%s %s\n' "$GUIDEDOG_SHA256" "$archive" | sha256sum --check --strict
mkdir -p "$RUNNER_TEMP/guidedog"
tar -xzf "$archive" -C "$RUNNER_TEMP/guidedog" --strip-components=1
echo "$RUNNER_TEMP/guidedog" >> "$GITHUB_PATH"
- name: Configure Pages
id: pages
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
- name: Build the site
env:
PAGES_BASE_URL: ${{ steps.pages.outputs.base_url }}
run: |
set -euo pipefail
guidedog --version
guidedog build -b html docs build/site -W -D "html_baseurl=$PAGES_BASE_URL"
test -s build/site/index.html
touch build/site/.nojekyll
- name: Upload Pages artifact
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
with:
path: build/site
deploy:
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
needs: build
runs-on: ubuntu-22.04
timeout-minutes: 10
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy
id: deployment
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1
The action commits are pinned. configure-pages uses the latest release checked
for this guide, v6.0.0. When upgrading Guidedog, update both the version and the
Linux amd64 archive’s verified SHA-256. Review action updates separately.
If the project selects build plugins, install and register their trusted executables
in the build job before running guidedog build. Registrations on your computer
are not copied to an Actions runner. Supply each plugin’s project and configuration
when registering it; qualification runs there too. Packaged plugins need no Odin
compiler. See Write a native plugin for the complete example. The deploy job uses
GitHub’s Pages action; it does not invoke a publishing plugin.
The build job can read sources. Only the deploy job receives Pages and OIDC
permissions. GitHub supplies its short-lived credentials; do not add a personal
token. A failed build prevents deployment. Pull-request content never enters the
deploy job. Keep this workflow on pull_request, not pull_request_target.
Check the published site¶
Open the deployment URL shown by the completed workflow. For a project repository,
it normally includes /REPOSITORY/. Check navigation, search, images, language
links, and fonts at that address. html_baseurl sets canonical metadata; it does
not rewrite root-relative URLs in custom templates. Prefer relative asset links.
For PDF downloads, build the book first and copy the PDF into build/site before
the upload step. Assemble all language editions there too. Upload only the finished
publication, never the repository root or a build cache. See Build and publish documentation for
output paths and Internationalization for translation catalogs.
If deployment is refused, check the Pages source, the environment’s allowed branches and approvals, and the deploy job’s permissions. A successful upload is not a successful deployment. The official action reports the deployment result.
Publish from this machine¶
guidedog-pages publishes from your own computer instead: it builds the project
with the installed guidedog, and pushes the whole site to a branch of its own in
one Git commit. GitHub Pages then deploys that branch. It comes with Guidedog in the
release archives and the Homebrew formula, and needs no Git, Python, or Odin.
Use one route per site. A repository has one Pages source: GitHub Actions or a
branch. guidedog-pages refuses to publish while Pages deploys from Actions or
from another branch, and switching is a deliberate setup step.
Set it up once¶
Write pages.toml beside your project. It names the repository, the branch, and
the credential profile; it holds no secret, so you can commit it:
guidedog-pages init --repository=octo/manual --project=docs
Store a token for the profile. Make a fine-grained personal access token for the
repository with Contents: read and write, and Pages: read so that
publication can confirm the deployment (Pages: write and Administration:
write too if you want setup to configure Pages). Paste it when asked; it is
not shown, and it goes to the macOS Keychain, the Windows Credential Manager, or
the Secret Service of a Linux desktop, never to a file:
guidedog-pages auth import --profile=default
guidedog-pages auth status
auth login signs in with a code instead (GitHub’s device flow), for a GitHub
App or OAuth App you registered with the device flow enabled:
guidedog-pages auth login --client-id=YOUR_APP_ID. Guidedog ships without
an app of its own.
Authorize the target on this machine, and check that everything is ready:
guidedog-pages bind
guidedog-pages doctor
bind shows the account, the repository with its GitHub ID, the branch, and the
Pages settings, and asks before it records them. Publication goes only to a bound
target: a pages.toml that names another repository, a repository that was
renamed, transferred, or made again, or another account’s token is refused until
you bind again. bind refuses a branch that holds work Guidedog did not publish;
--adopt lets the next publication replace it, after you have checked. The
branch must not be the repository’s default branch. doctor checks everything and
changes nothing.
Publish¶
guidedog-pages publish --dry-run
guidedog-pages publish
publish builds the project with warnings as errors (strict = true), and
sets html_baseurl to site_url. It reads the branch, lists what will be
added, changed, and removed, and sends one push that holds only the files the
branch lacks. GitHub moves the branch only if it still has the commit that was
read, so a publication never overwrites a newer one; if another publication got
there first, run the command again. A .nojekyll file is added, so folders such
as _static are served. Then it waits, up to wait_seconds, for GitHub Pages
to deploy that commit.
The first publication makes the branch. GitHub usually starts deploying a new
gh-pages branch by itself; otherwise publish ends with pages.no-site. Then
run guidedog-pages setup, which asks before it points GitHub Pages at the branch,
or choose Deploy from a branch, your branch, / (root) in Settings -> Pages.
The exit status says what happened: 0 when the site is live or was already
published, 1 when nothing was published, 6 when GitHub accepted the publication
but has not confirmed the deployment yet, and 7 when it is not known whether the
branch moved. Check later with guidedog-pages status. If a publication lost its
answer from GitHub, guidedog-pages recover reads the branch and settles it; it
never moves the branch back.
To publish a site you build yourself, such as a site with several languages and
PDF books assembled by a script, write site = "build/site" instead of
project; the folder is copied and checked before it is published.
Publish on every change¶
guidedog-pages watch publishes once, then again whenever the sources change
and have been quiet for debounce_ms (at most max_wait_ms after the first
change). A failed build or publication is reported, and the published site stays
as it was. Ctrl+C stops it. It watches files on this machine; to publish after a
push to GitHub, use the Actions route above.
A scheduler can keep it running. On macOS, a launch agent in
~/Library/LaunchAgents/org.example.docs.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key><string>org.example.docs</string>
<key>ProgramArguments</key>
<array>
<string>/opt/homebrew/bin/guidedog-pages</string>
<string>watch</string>
</array>
<key>WorkingDirectory</key><string>/Users/me/src/manual</string>
<key>RunAtLoad</key><true/>
<key>KeepAlive</key><true/>
</dict>
</plist>
On Linux, a systemd user service, ~/.config/systemd/user/docs-pages.service,
started with systemctl --user enable --now docs-pages. A user service reaches
the desktop’s Secret Service; on a server without one, give the token with
--credential=env and an Environment=GUIDEDOG_PAGES_TOKEN=... drop-in readable
only by you:
[Unit]
Description=Publish the manual to GitHub Pages
[Service]
WorkingDirectory=%h/src/manual
ExecStart=/usr/local/bin/guidedog-pages watch
Restart=on-failure
[Install]
WantedBy=default.target
On Windows, a scheduled task at logon, so that the Credential Manager is available:
$action = New-ScheduledTaskAction -Execute "guidedog-pages.exe" -Argument "watch" `
-WorkingDirectory "C:\src\manual"
Register-ScheduledTask -TaskName "Publish manual" -Action $action `
-Trigger (New-ScheduledTaskTrigger -AtLogOn)
Tokens and automation¶
--credential=env takes the token from GUIDEDOG_PAGES_TOKEN for one command,
and never stores it; GUIDEDOG_PAGES_CREDENTIAL=env chooses the same for runs
that cannot take the option, such as guidedog publish. Without either, the
variable is ignored. A missing or locked credential store is reported; the token is
never written to a plain file instead. auth logout deletes the stored token;
revoke it at GitHub too, under Settings -> Developer settings.
Through guidedog publish¶
guidedog-pages is also a publisher for guidedog publish, which builds the
project with Guidedog’s own engine and hands the frozen site to it:
guidedog plugin register pages "$(command -v guidedog-pages)"
guidedog publish --publisher=pages --config=pages.toml
Sign in, bind, and set up with guidedog-pages itself, or through
guidedog plugin run pages -- auth import. See Write a native plugin.
Troubleshooting¶
Every problem names its code and what to do. The common ones:
| Code | What to do |
|---|---|
pages.unbound |
Run guidedog-pages bind: this machine has not been allowed to publish there. |
pages.no-token, pages.credential |
Store a token with auth import or auth login; GitHub refused or expired it. |
pages.permission |
Give the token Contents: read and write for the repository, or approve it for the organization’s single sign-on. |
pages.source, pages.no-site |
Run guidedog-pages setup, or change the Pages source in the settings. |
pages.conflict |
Another publication moved the branch first; run the command again. |
pages.ruleset |
A ruleset or branch protection refused the push; allow the account to push. |
pages.unsettled |
Run guidedog-pages recover. |
pages.deployment |
The branch holds the site, but the Pages build failed; see the repository’s Actions tab. |