1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2019-10-21

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
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?