コンテンツにスキップ

Repository dispatch event

Repository Dispatch · Actions · GitHub Marketplace · GitHubを使うことで、他のリポジトリへRepository dispatchイベントを送ることができる。対象リポジトリではworkflowのトリガとしてrepository_dispatchで実行できる。

イベント生成側

パーソナルアクセストークン - GitHub Docsを使ってPushトリガーなどで指定リポジトリへrepository-dispatchイベントを送信できます。

- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.PAT }}
repository: username/my-repo
event-type: my-event

イベント受信側

指定イベント(my-event)でworkflowを起動する

name: Repository Dispatch
on:
repository_dispatch:
types: [my-event]
jobs:
myEvent:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.client_payload.ref }}
- run: echo ${{ github.event.client_payload.sha }}

応用

上記を組み合わせることで、ドキュメントのリポジトリへpushで別リポジトリのworkflowでdeployができるようになる。