TIL

Deploying to GitHub Pages via GitHub Actions

You don't need to push to gh-pages anymore. Instead you can deploy directly from GitHub Actions. You can use the actions/upload-pages-artifact and actions/deploy-pages actions.

Here is an example will deploy on any pushes to the main branch:

# ...
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      # add step(s) to build the site here
      - name: Upload artifact
        if: github.ref == 'refs/heads/main'
        uses: actions/upload-pages-artifact@v1
        with:
          path: dist  # name of directory that contains the static site
  deploy:
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/main'
    permissions:
      pages: write
      id-token: write
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    needs: build
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v1

Note: You could do this all in a single job, but I am splitting them into two to limit the operations that are performed with elevated permissions. This provides a little extra security to the process.

See the workflow for this site for real-world usage.