(1) Add ssh deploy key
Generate your deploy key with the following command.
ssh-keygen -t rsa -b 4096 -C "$(git config user.email)" -f gh-pages -N ""
# You will get 2 files:
# gh-pages.pub (public key)
# gh-pages (private key)
Next, Go to Repository Settings
- Go to Deploy Keys and add your public key with the Allow write access
- Go to Secrets and add your private key as
ACTIONS_DEPLOY_KEY
(2) Create your workflow
Repository type - Project
An example YAML file (.github/workflows/gh-pages.yml
) with Hugo action.
name: github pages
on:
push:
branches:
- master
jobs:
build-deploy:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@master
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2.2.0
with:
hugo-version: '0.58.3'
- name: Build
run: hugo --gc --minify --cleanDestinationDir
- name: Deploy
uses: peaceiris/actions-gh-pages@v2.4.0
env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: ./public
The above example is for Project Pages sites. (<username>/<project_name>
repository)
Repository type - User and Organization
For User and Organization Pages sites (<username>/<username>.github.io
repository),
we have to set master
branch to PUBLISH_BRANCH
.
on:
push:
branches:
- source # default branch
PUBLISH_BRANCH: master # deploying branch
For more details, go to repositories.