Tl;Dr
shell
キーワードにてbash -xe {0}
と指定できる。
jobs:
build:
...
steps:
- name: Hello
shell: bash -xe {0} # custom shell
run: |
echo "Hello!"
なぜ利用したい?
GitHub Actionsでシェルを実行する時、デフォルトでは-x
オプションが指定されていないため、エラーが発生したときにどこで失敗したのか分かりづらいことがある。
以下では2行目でechoo "Bad"
とタイポしているが、それが原因で失敗していることが分かりづらい。
shell
キーワードでbash -xe {0}
を指定しておけば、以下のように失敗した箇所が分かりやすい。
また、デフォルトでは-e
オプションが指定されているため、いずれかのコマンドが失敗したタイミングで終了扱いになるが、その挙動が好ましくない場合bash -x {0}
と指定することで回避できる。
Custom shell
公式ドキュメントに記載がある。
You can set the shell value to a template string using command […options] {0} [..more_options]. GitHub interprets the first whitespace-delimited word of the string as the command, and inserts the file name for the temporary script at {0}.
command […options] {0} [..more_options]
という書式で指定すればよいと書かれており、今回はbash -xe {0}
と指定した(more_options
は指定していない)が、他にも任意のコマンドを指定することができる。
終わりに
ググってすぐに見つからなかったので、比較的ググラビリティの高そうなタイトルで簡単に書いてみた。