2
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.

SlackにGithub Actionsのステータスを通知する 通知内容をちょっとだけ変更

Last updated at Posted at 2023-07-05

概要

  • 下記の記事でActionsの結果をSlackに通知する機能を作ったが、若干結果がわかりにくい、成功したらチェックマーク、成功以外の時は赤いバツ印を表示したい

方法

  • ワークフローファイルを下記のように変更する。(これは三項演算子を用いた記載方法)

    name: 'do PHP-CS-Fixer'
    
    on:
      pull_request:
        types: [opened, reopened, synchronize]
      
    jobs:
      do_php-cs-fixer:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v3
          - name: init
            run: make use_actions_init
          - name: lint-check
            run: make use_actions_lint_all_fix_plan
          - name: Notify Slack
            if: always()
            uses: rtCamp/action-slack-notify@v2
            env:
              SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
              SLACK_COLOR: ${{ job.status }}
              SLACK_MESSAGE: "do PHP-CS-Fixer ${{ (job.status == 'success') && ':white_check_mark:' || ':x:' }}"
              SLACK_USERNAME: Github Actions
              SLACK_ICON_EMOJI: ':eyes:'
    

Cursor_と_式_-_GitHub_Docs.png

  • actionsのyamlの三項演算子は下記のようなルールらしい。

    ${{ (式 true or false) && trueの場合の処理 || falseの場合の処理 }}
    
  • ちなみにPHPの三項演算子はこんな感じ。

    ( true or false) ? trueの場合の処理 : falseの場合の処理;
    
    
  • 下記のように通知される。

    Cursor_と_02_notice_git_hub_actions_-DokuPro-1_個の新しいアイテム-_Slack.png

参考文献

2
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
2
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?