Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What is going on with this article?
@syui

Hugo+GitHub Pages+GitHub Actionsで自動デプロイする方法

More than 1 year has passed since last update.

branch:gh-pagesにdeployする場合

.github/workflows/gh-pages.yml
name: githubpages

on:
  push:
    branches:
    - master

jobs:
  build-deploy:
    runs-on: ubuntu-18.04
    # runs-on: macOS-10.14
    # runs-on: windows-2019
    steps:
    - uses: actions/checkout@master

    - name: Setup Hugo
      uses: peaceiris/actions-hugo@v2.2.0
      with:
        hugo-version: 'latest'

    - name: Build
      run: hugo --gc --minify --cleanDestinationDir

    - name: Deploy
      uses: peaceiris/actions-gh-pages@v2.3.1
      env:
        ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
        PUBLISH_BRANCH: gh-pages
        PUBLISH_DIR: ./public

branch:masterにdeployする場合

なぜかgithub-jekyll-build,deployがok表示されるのに、ページが表示されなかったので、github-pagesを.nojekyllで制御する。

.github/workflows/gh-pages.yml
name: github pages

on:
  push:
    branches:
    - src

jobs:
  build-deploy:
    runs-on: ubuntu-18.04
    steps:
    - uses: actions/checkout@master
      with:
        ref: src
        submodules: true

    - name: Setup Hugo
      uses: peaceiris/actions-hugo@v2.2.2
      with:
        hugo-version:
        # extended: true

    - name: Build
      run: |
           hugo --gc --minify --cleanDestinationDir
           touch ./public/.nojekyll
           cp ./CNAME ./public/

    - name: Deploy
      uses: peaceiris/actions-gh-pages@v2.5.0
      env:
        ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
        PUBLISH_BRANCH: master
        PUBLISH_DIR: ./public

概要

.github/workflows/gh-pages.ymlにファイルを置く

鍵を作る
$ ssh-keygen -t rsa -b 4096 -C "$(git config user.email)" -f gh-pages -N ""

gh-pagesが秘密鍵で、gh-pages.pubが公開鍵。公開鍵は見られても平気。

秘密鍵をgithub(リポジトリ設定)のsecretsに登録する。公開鍵をdeploy keysに登録する。名前は何でもいい。

# 秘密鍵
$ cat gh-pages|pbcopy
# 公開鍵
$ cat gh-pages.pub|pbcopy

一応、設定にてbranchをソースがあるブランチに変更しておく。あとは、pushすればgh-actions(ci)が動く。

1
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
syui

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
1
Help us understand the problem. What is going on with this article?