LoginSignup
16
9

More than 3 years have passed since last update.

GitHubActionsのrepository_dispatchを試す

Last updated at Posted at 2019-10-11

概要

GitHubActionsではGitHub上のいろんなイベントをフックしてActionを実行できますが、外部からAPIリクエストによってもActionを起動することができます。それがrepository_dispatchです。

GitHubActionsのイベントフックにrepository_dispatchを設定する

workflow.yaml
name: Sample

on: repository_dispatch

・・・以下省略・・・

GitHubのAPIを叩く

curl -X POST -H "Authorization: token トークン" -H "Accept: application/vnd.github.everest-preview+json" -d '{"event_type": "イベントタイプ(自分で決める)"}' -i  https://api.github.com/repos/オーガナイゼーション名/リポジトリ名/dispatches

詳しくはこちら: https://developer.github.com/v3/repos/#create-a-repository-dispatch-event

トークンはGitHubでSettings > Developer settings > Personal access tokensで作成できます。作成するときにはrepoスコープについての権限を付与することを忘れないでください。

repository_dispatch経由で実行されるActionのブランチはどうやって指定するの?

残念ながらできないようです。https://help.github.com/en/articles/events-that-trigger-workflows#external-events-repository_dispatch に書いてあるとおり、Commit that changes statusなので、一番最新で変更があったブランチの最新のCommitで自動的にActionが走ると思われます。これだと使えない…。repository_dispatchはまだお試しくらいの機能なようです。

16
9
1

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
16
9