🍣
GitHub Actionsのactionのoutputsを呼び出し元で使う方法
背景
GitHub Actionsを使用していると共通化のため「action.yml」を作成することが多い。
このaction.ymlで呼び出し元にoutputを渡す方法について思いの他手間取ったので記録する。
結論
そこまで大した内容では無いため、要所だけ抜粋する。
action.yml
name: "My Action"
outputs:
myOutput:
description: "This is my output"
value: ${{ steps.step_id.outputs.some_output }}
main.yml
jobs:
example-job:
runs-on: ubuntu-latest
steps:
- name: Run My Action
id: my_action
uses: ./path/to/your/action
- name: Use Action Output
run: echo "The output is ${{ steps.my_action.outputs.myOutput }}"
要点
action.yml
でもoutputsを用意して値を入れる。この際の形式に注意が必要だった。
action.yml向けにoutputsの記述ルールが違う
後は、action実行時にidを使用して従来通り<steps.{id},outputs.{name}>の様に使用できる。
いつも使用しているパターン
main.yml
outputs:
myOutput: some_output
actionsでの書き方
action.yml
name: "My Action"
outputs:
myOutput:
description: "This is my output"
value: ${{ steps.step_id.outputs.some_output }}
Discussion