Skip to content

How to deploy to GitHub pages from a private repository.

Published: at 10:06 PM

Try using a GitHub action that looks something like this - don’t forget to set the deploy key:

name: Deploy Astro site to Pages

on:
  push:
    branches: [main]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
  group: "pages"
  cancel-in-progress: false

env:
  BUILD_PATH: "." # default value when not using subfolders
  # BUILD_PATH: subfolder

jobs:
  build:
    name: 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: ${{ env.BUILD_PATH }}/package-lock.json
      - name: Install dependencies
        run: npm install
        working-directory: ${{ env.BUILD_PATH }}
      - name: Build with Astro
        run: npx astro build
        working-directory: ${{ env.BUILD_PATH }}
      - name: Deploy to GitHub Pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
          publish_dir: ${{ env.BUILD_PATH }}/dist
          external_repository: YOUR_GITHUB_NAME/YOUR_GITHUB_REPO