GitHub ActionsのAPIを利用してJobを再実行する方法を解説します。
手順としては
- アクセストークンを発行する
- cURLコマンドでURLへPOSTする
になります。
実際に動いているリポジトリはこちらです。
このエントリーの意図
GitHub Actions APIでWorkflow rerunが動かない人向けです。Workflow runs | GitHub Developer Guide
アクセストークンを発行する
「プロフィールアイコン」→「Settings」→「Developer settings」→「Personal access tokens」→「Generate new token」






GitHub Actionsを実行するファイル
「on」エレメントに「deployment」を指定します。push時にもWorkflowを実行したい場合は両方記述しておきます。
.github/workflows/test.yml
---
name: trailing whitespace
on: [deployment, push]
jobs:
trailing-whitespace:
name: Find Trailing Whitespace
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: harupy/find-trailing-whitespace@master
Workflowを再実行する
以下のコマンドで実行します。
curl -X POST \
-H "Authorization: token xxxxxxxxxxxxxxxx" \
-d '{"ref": "master", "environment": "periodic execution"}' \
https://api.github.com/repos/${username}/${reponame}/deployments
コマンドの詳しいオプションはDeployments | GitHub Developer Guideで確認する事ができます。