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-02-18

はじめに

僕は今まで「GitHub Actionsのログ出力が見づらい問題」に悩まされていました。
唐突ですが、以下のworkflowを実行してみましょう。

main.yml
name: main
on:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: '3.x'
          architecture: 'x64'
      - name: Run Python
        run: |
          python -m pip install --upgrade pip
          pip install opencv-python
          pip install Pillow
          pip install python-dotenv
          pip install selenium
          python main.py

パッケージはログ出力の見づらさが伝われば良いので、テキトーに選びました。
main.pyは以下のようになっています。

main.py
print('Hello World')

実行すると以下のようになりました。

グループ化無

...見づらいです。ぱっと見「Hello World」がどこにあるのか分かりません。
どうにかしてログ出力を見やすくする方法はないかと調べていたところ、公式のドキュメントで以下のようなものを見つけました。

groupを使えばログ出力をグループ化することができるようです。

何故かこれに関する記事がQiitaで1つも見つからなかったので、備忘録として残しておきます。

1.ymlファイルの修正

main.ymlを以下のように修正します。(2行加えるだけですが...)

main.yml
      # 省略
      - name: Run Python
        run: |
          echo "::group::pip install --upgrade pip"
          python -m pip install --upgrade pip
          pip install opencv-python
          pip install Pillow
          pip install python-dotenv
          pip install selenium
          echo "::endgroup::"
          python main.py

echo "::group::<グループ名>"でログ出力をグループ化できます。(グループ名は任意)
echo "::endgroup::"でグループ化を終了します。

2.実行

実行すると以下のようになりました。

グループ化有

すごくスッキリしました。
グループ名の部分を押すと展開できます。

グループ化有

以下のリポジトリに今回のコードが置いてあります。

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?