JavaScriptを有効にしてください

【Github】Github Actions Slack に通知してみる

 ·  ☕ 1 分で読めます

Github Actions Slackに通知してみる

push された通知など Slack に通知してみます。

Slack の用意

以下の Slack アプリの Incoming Webhook を利用します。

Webhook URL を取得します。

Github の用意

  1. 導入したい RepositorySettingsを選択。
  2. 左のメニューの Secrets を指定
  3. 右上の New repository secret を選択。
  4. NameSLACK_WEBHOOK_URL を設定。
  5. Value に取得した Webhook URL を設定。

Github Actionsの設定

Github Actions を作成します。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
name: Slack

on: push

jobs:
  slack:
    # Ubuntu
    runs-on: ubuntu-latest
    steps:
      # Slack
      - name: Slack Notification
        uses: tokorom/action-slack-incoming-webhook@main
        env:
          INCOMING_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
        with:
          text: Github Actions Slack Notification

これを push すると以下のように Slack に通知が行きます。
slack-notification.png

通知のカスタマイズ

通知をカスタマイズすることが出来ます。
attachments を追加することによって通知をカスタマイズ出来ます。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
name: Slack

on: push

jobs:
  slack:
    # Ubuntu
    runs-on: ubuntu-latest
    steps:
      # Slack
      - name: Slack Notification
        uses: tokorom/action-slack-incoming-webhook@main
        env:
          INCOMING_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
        with:
          text: Start Github Actions
          attachments: |
            [
              {
                "color": "good",
                "author_name": "${{ github.actor }}",
                "author_icon": "${{ github.event.sender.avatar_url }}",
                "fields": [
                  {
                    "title": "Push Repository",
                    "value": "${{ github.event.repository.url }}"
                  }
                ]
              }
            ]            

以下のようにプッシュした人の名前とアバター画像、Repository の URL が通知されます。
slack-notification-customize.png

参考

共有

こぴぺたん
著者
こぴぺたん
Copy & Paste Engineer