GitHub Actions Tips
ブランチ名の取得方法
ソースブランチの取得 (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
BooleanタイプのInputsの検証結果
GitHub Actionがpush
でトリガーされたのかpull_request
でトリガーされたのかの判定
${{ github.event == 'pull_request' }}
concurrency option
同時実行制御に利用
GHE 関連情報
GHE のキャッシュストレージ 10GB/repo
GHEのArtifactの保持期間 default: 90days max: 400days
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]' |
envの優先度整理
検証中
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へ渡し変える必要があるみたい
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は呼び出し先のワークフローへ伝搬されないのか。。。
Special thanks to https://twitter.com/snow_cait san
デバッグログの有効化
下記をsecretsに設定
- ACTIONS_RUNNER_DEBUG: true
- ACTIONS_STEP_DEBUG: true
Matrixで複数のキーバリューペアを使いたい場合
matrix:
key-1:
- val-1: "something-1"
val-2: "something-2"
Action Runner Controller