背景
-
study
: 本SSGの記事repo -
study_gatsby
: 本SSGのビルド環境repo
study_gatsby
からsubmoduleでstudy
を参照している。
before
study
リポジトリにデプロイアクションを記述していたのだが、gatsbyビルド環境はstudy_gatsby
リポジトリにあり、分かれていて辛い状態だった。
after
デプロイアクションをstudy_gatsby
リポジトリに移し、study
リポジトリpush時にstudy_gatsby
リポジトリのデプロイアクションをディスパッチするように変更した。
これによりgatsbyビルド環境とデプロイアクションが一箇所にまとまり管理しやすくなった。
詳細
study_gatsby
のワークフローyaml
on:
push:
branches:
- master
+ repository_dispatch:
+ types:
+ - "study blog contents updated"
repository_dispatch
で"study blog contents updated"
イベントをサブスクライブする。
study
のワークフローyaml
name: "dispatch study_gatsby repo's Actions"
on:
push:
branches:
- master
jobs:
publish:
runs-on: ubuntu-16.04
steps:
- name: Create GitHub dispatch event
run: |
curl --request POST 'https://api.github.com/repos/wand2016/study_gatsby/dispatches' \
--header 'Authorization: Bearer ${{secrets.ACCESS_TOKEN_FOR_DISPATCH}}' \
--header 'Content-Type: application/json' \
--data-raw '{
"event_type": "study blog contents updated"
}'
GitHubアカウントの設定からrepo権限でPersonal Access Tokenを発行して
study
リポジトリのsecretsに登録しておく。
--header 'Authorization: Bearer ${{secrets.ACCESS_TOKEN_FOR_DISPATCH}}' \
event_type
にはstudy_gatsby
でサブスクライブしたイベントと同名のものを指定する。
--data-raw '{
"event_type": "study blog contents updated"
}'