Open19

GitHub Actions Tips

gizumongizumon

ブランチ名の取得方法
github-image

ソースブランチの取得 (push / pull_request)

if ${{ github.event_name == 'pull_request' }}; then
  echo "push to ${{ github.head_ref }} ... (event:pull_request)"
  git push origin main ${{ github.head_ref }}
else
  echo "push to ${{ github.ref_name }} ... (event:push)"
  git push origin ${{ github.ref_name }}
fi

参考: https://dev.classmethod.jp/articles/how-to-get-a-ref-branch-within-a-workflow-execution-in-github-actions/ 🙇‍♂️

gizumongizumon

fromJsonの挙動整理

検証中

# Case Example Result
1 String fromJSON("text") Throw Error 😅
2 Number fromJSON("1") 1
3 Boolean fromJSON("true") true
4 Array fromJSON('["a", "b", "c"]') ["a", "b", "c"]
5 Object fromJSON('{"a": 1, "b":2, "c": 3}') {"a": 1, "b": 2, "c": 3}
6 Broken array fromJSON('[a, b, c]') '[a, b, c]'
gizumongizumon

Unrecognized named-value: 'secrets'. Located at position 1 within expression

As-Is

    secrets:
      SOMETHING:
...
  if: {{ secrets.SOMETHING != '' }}

To-Be

    secrets:
      SOMETHING:
...
env:
  SOMETHING: ${{ secrets.SOMETHING }}
...
  if: {{ env.SOMETHING != '' }}

=> secretsにはアクセス不可のため、envへ渡し変える必要があるみたい

gizumongizumon

Any environment variables set in an env context defined at the workflow level in the caller workflow are not propagated to the called workflow. For more information about the env context, see "Context and expression syntax for GitHub Actions."

おおお、reusable workflowの場合、
呼び出し元で定義したenvは呼び出し先のワークフローへ伝搬されないのか。。。

gizumongizumon

デバッグログの有効化

下記をsecretsに設定

  • ACTIONS_RUNNER_DEBUG: true
  • ACTIONS_STEP_DEBUG: true
gizumongizumon

Matrixで複数のキーバリューペアを使いたい場合

      matrix:
        key-1:
          - val-1: "something-1"
            val-2: "something-2"