2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Githubのマニュアルトリガーworkflow_dispatchをdefault以外のブランチから試す方法

Posted at

概要

github actionsのworkflow_dispatchをPR内で試してみたい、そんなあなたへ贈るtips
(2021/05/18現在、default branchからでしかGithub GUIのアクションからworkflow_dispatchを実行することはできません)

結論

gh コマンドを使い、以下のようにブランチ名を指定して実行する。
gh workflow run --ref branch_name

そうすると実行可能なworkflow一覧が出てくるので選択し、実行する。

workflow_dispatchとは

Github actionsをmanualで実行し、inputで以下のように値を渡せる便利機能です!

on: 
  workflow_dispatch:
    inputs:
      logLevel:
        description: 'Log level'     
        required: true
        default: 'warning'
      tags:
        description: 'Test scenario tags'  
jobs:
  printInputs:
    runs-on: ubuntu-latest
    steps:
    - run: |
        echo "Log level: ${{ github.event.inputs.logLevel }}"
        echo "Tags: ${{ github.event.inputs.tags }}" 

Screenshot 2021-05-18 at 16.54.50.png

ref: https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/

しかし、現在だとdefaultに設定したブランチに存在しない限りworkflow_dispatchをgithub GUI上で試すことはできません。
そこでgithub 公式のcliツールである ghを使います。

gh (GitHub CLI)

macだったら簡単にbrew install ghでインストールできます。

インストール完了したらgh workflow run --ref branch_nameとコマンドラインから実行してみてください、ここのbranch_nameは検証したいworkflowが存在するブランチ名を指定します。

そうすると実行可能なworkflow一覧が見れるかと思います、なので対象のworkflowを選択しenterを押すと実行できます。

ちなみに gh run view <run-id> で実行中のworkflowのログを見ることができます。

2
1
0

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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?