複数行を出力するにはヒアドキュメントを利用する
GitHub Actions で、$GITHUB_OUTPUT に値を出力して結果を別 step で使い回すことをしたい場合、複数行を値として渡そうとすると以下のエラーが出る。
Error: Unable to process file command 'output' successfully.
Error: Invalid format '...'
以下の対策方法が提供されている。
Workflow commands for GitHub Actions - Multiline strings
1つ。以下のように、echo している側を {} で囲って <<EOF
EOF
を利用し、まとめて $GITHUB_OUTPUT にリダイレクトする方法。
steps:
- name: Set the value in bash
id: step_one
run: |
{
echo 'JSON_RESPONSE<<EOF'
curl https://example.com
echo EOF
} >> "$GITHUB_OUTPUT"
2つ。以下のように <<EOF
EOF
を使うが、各行 $GITHUB_OUTPUT にリダイレクトする方法がある。
steps:
- name: Set the value in bash
id: step_one
run: |
echo 'JSON_RESPONSE<<EOF' >> $GITHUB_OUTPUT
echo "$(curl https://example.com)" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT