AI Hints
CI/CD with GitHub Actions · Lesson 92 of 138

GitHub Pages

Free static hosting.

⏱ 2 min read▶ Video at 1:46:09🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

GitHub Pages hosts static websites, for free, straight from a repository. It's perfect for docs, project pages, and blogs. And a workflow can build and publish the site on every push.

GitHub Pages
From the video: GitHub Pages
  • Static sites, free
  • Docs and project pages
  • Published by a workflow

pages.yml

The workflow needs pages write, and ID token write, to publish. The build step makes the site folder. Here it's a single page, but usually it's a site generator. Upload pages artifact packs the folder, and deploy pages publishes it.

.github/workflows/pages.ymlyaml
name: Pages
on:
  push:
    branches: [main]
permissions:
  pages: write
  id-token: write
jobs:
  site:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Build the site
        run: mkdir -p site && echo "<h1>Shop docs</h1>" > site/index.html
      - uses: actions/upload-pages-artifact@v3
        with: { path: site }
      - uses: actions/deploy-pages@v4

Building locally

Our helper runs the build step, and skips the two GitHub only actions. Cat shows the page that would be published. On GitHub, the site appears at the owner's name, dot github dot IO, slash the repository name.

Terminal
run-steps .github/workflows/pages.yml | grep -E "✓|↷"
  ↷ uses actions/checkout@v4  (GitHub only)
  ✓ Build the site
  ↷ uses actions/upload-pages-artifact@v3  (GitHub only)
  ↷ uses actions/deploy-pages@v4  (GitHub only)
cat site/index.html
<h1>Shop docs</h1>

Summary

GitHub Pages hosts static sites, and two actions upload and deploy them. Turn Pages on in the settings, with GitHub Actions as the source. Next, logging in to a cloud without long lived keys.

Key takeaways
  • pages: write
  • upload-pages-artifact
  • deploy-pages
Next up: Cloud Login with OIDC — no stored keys