概要
Github Actions で実行したステップの出力結果を後続に連携したい場合、決められた様式で出力することで対応できます。
例
- name: Set color
id: random-color-generator
run: echo "SELECTED_COLOR=green" >> $GITHUB_OUTPUT
- name: Get color
run: echo "The selected color is ${{ steps.random-color-generator.outputs.SELECTED_COLOR }}"
Actions から実行する JavaScript 内で、出力結果をセットする手順をメモに残す。
手順
- @actions/core パッケージをインストール
npm install @actions/core
- JavaScript 内で
core.setOutput
を実行するconst core = require('@actions/core'); core.setOutput('outputKey', 'outputVal');
- 後続のワークフローで参照する
- name: echo run: | echo ${{steps.step_id.outputs.outputKey}} - name: if test if: steps.step_id.outputs.outputKey != 'SAMPLE_VALUE' run: | echo "trueの処理"
参考情報
https://github.com/actions/toolkit#packages
https://github.com/actions/toolkit/tree/main/packages/core