メモ: GitHub Actionsでpkgdownサイトをビルドする
これを使いたい。
GitHub版のusethisパッケージをインストール
devtools::install_github("r-lib/usethis")
GitHub Actionsの設定ファイルをレポジトリに追加
usethis::use_github_action()
を使うと、 https://github.com/r-lib/actions/tree/master/examples にあるYAMLファイルを持ってこれる。
usethis::use_github_action("pkgdown.yaml")
.Rbuildignore
に.github
を追加
usethis::use_github_action()
は個別のファイルを.Rbuildignore
に入れてくれるけど、.github
全体をignoreしないと以下のエラーが出る。
─ checking for empty or unneeded directories Removed empty directory ‘xxx/.github/workflows’ Removed empty directory ‘xxx/.github’
usethisにもissueは登録されているけどまだやってくれないっぽいので.Rbuildignore
に以下を自分で追加する。
^\.github$
これで準備は完了だが、まだgit pushしてはいけない。GitHub Pagesの設定をgh-pages
ブランチにしておく必要がある。
Personal Access Tokenを取得
これで動くかと思いきや、gh-pages
ブランチの前にもう一つやることがあった。
id:u_riboに教えてもらって気付いたけど、GitHub Actionsでデフォルトで使われているGITHUB_TOKEN
だと、pushはできるけどGitHub Pagesのビルドがトリガーされないというバグ?があるらしい。
ので、自分でPersonal Access Tokenを設定する。https://github.com/settings/tokens/newからrepo
にチェックを入れて発行。
これを、レポジトリのSettings Secretsから適当な名前で登録(GITHUB_PAT
とか)し、
.github/workflows/pkgdown.yml
の最後の行のトークンをGITHUB_TOKEN
からその名前に書き換える。
- Rscript -e "pkgdown:::deploy_local(new_process = FALSE, remote_url = 'https://x-access-token:${{secrets.GITHUB_TOKEN}}@github.com/${{github.repository}}.git')" + Rscript -e "pkgdown:::deploy_local(new_process = FALSE, remote_url = 'https://x-access-token:${{secrets.GITHUB_PAT}}@github.com/${{github.repository}}.git')"
そのうちGitHub側で直るような気もするけど、とりあえず今はこういう対処が必要みたいです。
gh-pages
(もうすでにgh-pages
ブランチを使っていれば無視してOK)
まずは空のブランチをつくってpush
git checkout --orphan gh-pages git rm --cached -r . git commit --allow-empty -m "initial commit" git push origin -u gh-pages
そしてGitHub Pagesの設定を変える。
git push
これでpushすれば動くはず。