1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

GitHub Actionsで値をダンプする方法

Last updated at Posted at 2023-01-01

概要

github.*などのgithubコンテキストの値を単品でechoするのは簡単でしたが、オブジェクトのままダンプするのは意外と手こずってしまったのでメモ。

失敗例

echo '${{ github }}'だとObjectで表示されてしまいます。

.github/workflows/dump-value.yml
on:
  push:
  pull_request:

jobs:
  dump-value:
    name: dump-value
    runs-on: ubuntu-latest
    steps:
      - name: echo github
        run: echo '${{ github }}'

      - name: echo github.event_name
        run: echo '${{ github.event_name }}'

pushで起動した場合

image.png

pull_requestで起動した場合

image.png

対応

echo '${{ toJSON(github) }}'に置き換えるとJSON形式で出力されます。

.github/workflows/dump-value.yml
on:
  push:
  pull_request:

jobs:
  dump-value:
    name: dump-value
    runs-on: ubuntu-latest
    steps:
      - name: echo github
        run: echo '${{ toJSON(github) }}'

      - name: echo github.event_name
        run: echo '${{ github.event_name }}'

image.png

余談

値をダンプできるとpushpull_requestでgithubコンテキストの値が異なるのがよくわかりますね。

.github/workflows/dump-value.yml
on:
  push:
  pull_request:

jobs:
  dump-value:
    name: dump-value
    runs-on: ubuntu-latest
    steps:
      - name: echo github.event_name
        run: echo '${{ github.event_name }}'

      - name: Dump github.event.head_commit
        run: echo '${{ toJSON(github.event.head_commit) }}'

      - name: Dump github.event.pull_request
        run: echo '${{ toJSON(github.event.pull_request) }}'

pushで起動した場合

名称未設定.png

pull_requestで起動した場合

image.png

参考

GitHub Actions/Learn GitHub Actions/Contexts 例: ログへのコンテキスト情報の出力
https://docs.github.com/ja/actions/learn-github-actions/contexts#example-printing-context-information-to-the-log

GitHub Actions/Learn GitHub Actions/Expressions toJSON
https://docs.github.com/ja/actions/learn-github-actions/expressions#tojson

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?