Deploying to GitHub Pages
This guide explains how to deploy your documentation to GitHub Pages using GitHub Actions.
Prerequisites
- A GitHub repository with your project
- The documentation in the
docs/folder (Starlight/Astro) - A GitHub account with permissions to create workflows
Method 1: GitHub Actions (Recommended)
Step 1: Create the Workflow File
Create a file at .github/workflows/deploy-docs.yml:
name: Deploy Docs to GitHub Pages
on: push: branches: [main] paths: - 'docs/**' workflow_dispatch:
permissions: contents: read pages: write id-token: write
concurrency: group: "pages" cancel-in-progress: false
jobs: build: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4
- name: Setup Node uses: actions/setup-node@v4 with: node-version: "20" cache: npm cache-dependency-path: docs/package-lock.json
- name: Setup Pages uses: actions/configure-pages@v4
- name: Install dependencies run: npm ci working-directory: docs
- name: Build with Astro run: npm run build working-directory: docs
- name: Upload artifact uses: actions/upload-pages-artifact@v3 with: path: docs/dist
deploy: environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest needs: build steps: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4Step 2: Configure Astro for GitHub Pages
Update docs/astro.config.mjs to set the correct base URL:
import { defineConfig } from 'astro/config';import starlight from '@astrojs/starlight';
export default defineConfig({ // Replace with your repository name site: 'https://YOUR_USERNAME.github.io', base: '/YOUR_REPO_NAME',
integrations: [ starlight({ title: 'Parkour Game Docs', // ... rest of your config }), ],});For example, if your GitHub username is johndoe and repo is parkour-game:
site: 'https://johndoe.github.io',base: '/parkour-game',Step 3: Enable GitHub Pages
- Go to your repository on GitHub
- Click Settings → Pages (in the sidebar)
- Under Build and deployment:
- Source: GitHub Actions
- Save the settings
Step 4: Push and Deploy
git add .git commit -m "Add GitHub Pages deployment"git push origin mainThe workflow will automatically run when you push changes to the docs/ folder.
Method 2: Manual Deployment
If you prefer manual deployments:
Build Locally
cd docsnpm installnpm run buildDeploy with gh-pages
Install the gh-pages package:
npm install --save-dev gh-pagesAdd a deploy script to docs/package.json:
{ "scripts": { "deploy": "astro build && gh-pages -d dist" }}Deploy:
npm run deployViewing Your Documentation
After deployment, your docs will be available at:
https://YOUR_USERNAME.github.io/YOUR_REPO_NAME/Troubleshooting
404 Errors
- Make sure the
basepath inastro.config.mjsmatches your repo name - Check that GitHub Pages is enabled in repository settings
- Wait a few minutes for the deployment to complete
Build Failures
Check the Actions tab in your repository for error logs:
- Go to your repository on GitHub
- Click Actions
- Click on the failed workflow run
- Expand the failed step to see the error
Assets Not Loading
Make sure all asset paths use the base URL prefix:
<!-- Use relative paths --><img src="./image.png" />
<!-- Or use Astro's built-in handling -->import { Image } from 'astro:assets';<Image src={import('./image.png')} alt="..." />Custom Domain (Optional)
To use a custom domain:
- Go to Settings → Pages
- Enter your custom domain
- Add a CNAME record in your DNS settings pointing to
YOUR_USERNAME.github.io - Update
siteinastro.config.mjs:
site: 'https://docs.yourdomain.com',base: '/', // Can be '/' with custom domainNext Steps
- Adding Content - Learn to add new documentation pages
- Starlight Docs - Full Starlight documentation