[前][次][番号順一覧][スレッド一覧]

ruby-changes:57157

From: Takashi <ko1@a...>
Date: Mon, 19 Aug 2019 01:50:19 +0900 (JST)
Subject: [ruby-changes:57157] Takashi Kokubun: 2f6c8ed26e (master): Implement Slack notification for Actions

https://git.ruby-lang.org/ruby.git/commit/?id=2f6c8ed26e

From 2f6c8ed26eec4ad2d2fdaa0823cc63ba32f4c7a2 Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Mon, 19 Aug 2019 01:49:51 +0900
Subject: Implement Slack notification for Actions


diff --git a/.github/actions/notify-slack/action.yml b/.github/actions/notify-slack/action.yml
new file mode 100644
index 0000000..1a51a25
--- /dev/null
+++ b/.github/actions/notify-slack/action.yml
@@ -0,0 +1,53 @@ https://github.com/ruby/ruby/blob/trunk/.github/actions/notify-slack/action.yml#L1
+name: notify-slack
+description: You can notify slack of GitHub Actions.
+author: k0kubun
+inputs:
+  status:
+    description: Success or Failure
+  matrix_name:
+    description: Matrix task name
+  committer_name:
+    description: Git committer name
+  commit_message:
+    description: Git commit message
+  commit_timestamp:
+    description: Git commit timestamp
+runs:
+  using: docker
+  image: 'docker://ruby:2.6-slim'
+  args:
+    - /usr/local/bin/ruby
+    - -e
+    - |-
+      require 'json'
+      require 'net/http'
+      require 'uri'
+
+      github_repo = ENV.fetch('GITHUB_REPOSITORY')
+      github_sha  = ENV.fetch('GITHUB_SHA')
+      github_ref  = ENV.fetch('GITHUB_REF')
+
+      workflow = ENV.fetch('GITHUB_WORKFLOW')
+      matrix   = ENV.fetch('INPUT_MATRIX_NAME')
+      status   = ENV.fetch('INPUT_STATUS')
+
+      message   = ENV.fetch('INPUT_COMMIT_MESSAGE')
+      timestamp = ENV.fetch('INPUT_COMMIT_TIMESTAMP')
+      committer = ENV.fetch('INPUT_COMMITTER_NAME')
+
+      commit_url = "https://github.com/#{github_repo}/commit/#{github_sha}"
+      attachment = {
+        title: "#{status}: #{workflow} / #{matrix}",
+        title_link: "#{commit_url}/checks",
+        text: "<#{commit_url}|#{github_sha[0...10]}> of #{github_repo}@#{File.basename(github_ref)} "\
+              "by #{committer} on #{timestamp}: #{message}",
+        color: status == 'Success' ? 'good' : 'danger',
+      }
+
+      resp = Net::HTTP.post(
+        URI(ENV.fetch('SLACK_WEBHOOK_URL')),
+        { attachments: [attachment] }.to_json,
+        { 'Content-Type' => 'application/json' },
+      )
+      puts "#{resp.code} (#{resp.body}) -- #{payload.to_json}"
+      resp.value
diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml
index e357e3a..d974a9f 100644
--- a/.github/workflows/macos.yml
+++ b/.github/workflows/macos.yml
@@ -42,19 +42,20 @@ jobs: https://github.com/ruby/ruby/blob/trunk/.github/workflows/macos.yml#L42
       - name: configure
         run: ./configure -C --disable-install-doc --with-openssl-dir=$(brew --prefix openssl@1...) --with-readline-dir=$(brew --prefix readline)
       - run: make $JOBS
-      - name: make check
+      - name: Tests
         run: make -s ${{ matrix.test_task }}
         env:
           TESTOPTS: "$JOBS -q --tty=no"
           MSPECOPT: "-ff" # not using `-j` because sometimes `mspec -j` silently dies
-        if: matrix.test_task == 'check'
-      # test-bundler/test-bundled-gems are separated because it randomly fails and ends up cancelling `make check`.
-      # TODO: Remove `continue-on-error` once they become stable and also we have a notification for their failure.
-      - name: make test-bundler/test-bundled-gems
-        run: make -s ${{ matrix.test_task }}
-        env:
-          TESTOPTS: "$JOBS -q --tty=no"
-        continue-on-error: true
-        if: matrix.test_task != 'check'
       - name: Leaked Globals
         run: make -s leaked-globals
+      - uses: ./.github/actions/notify-slack
+        with:
+          status: ${{ job.status }}
+          matrix_name: ${{ matrix.test_task }}
+          committer_name: ${{ github.event.head_commit.committer.name }}
+          commit_message: ${{ github.event.head_commit.message }}
+          commit_timestamp: ${{ github.event.head_commit.timestamp }}
+        env:
+          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
+        if: failure() && github.event_name == 'push'
diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml
index 8c2d3a2..31fba17 100644
--- a/.github/workflows/ubuntu.yml
+++ b/.github/workflows/ubuntu.yml
@@ -45,16 +45,20 @@ jobs: https://github.com/ruby/ruby/blob/trunk/.github/workflows/ubuntu.yml#L45
       - name: configure
         run: ./configure -C --disable-install-doc
       - run: make $JOBS
-      - name: make check
+      - name: Tests
         run: make -s ${{ matrix.test_task }}
         env:
           TESTOPTS: "$JOBS -q --tty=no"
           MSPECOPT: "-ff" # not using `-j` because sometimes `mspec -j` silently dies
-        if: matrix.test_task == 'check'
-      # TODO: Remove `continue-on-error` once they become stable and also we have a notification for their failure.
-      - name: make test-bundler/test-bundled-gems
-        run: make -s ${{ matrix.test_task }}
-        if: matrix.test_task != 'check'
-        continue-on-error: true
       - name: Leaked Globals
         run: make -s leaked-globals
+      - uses: ./.github/actions/notify-slack
+        with:
+          status: ${{ job.status }}
+          matrix_name: ${{ matrix.test_task }}
+          committer_name: ${{ github.event.head_commit.committer.name }}
+          commit_message: ${{ github.event.head_commit.message }}
+          commit_timestamp: ${{ github.event.head_commit.timestamp }}
+        env:
+          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
+        if: failure() && github.event_name == 'push'
diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml
index 984ac70..ae5d2e5 100644
--- a/.github/workflows/windows.yml
+++ b/.github/workflows/windows.yml
@@ -53,3 +53,13 @@ jobs: https://github.com/ruby/ruby/blob/trunk/.github/workflows/windows.yml#L53
         run: |
           call "C:\Program Files (x86)\Microsoft Visual Studio\${{ matrix.vs }}\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
           nmake ${{ matrix.test_task }}
+      - uses: ./.github/actions/notify-slack
+        with:
+          status: ${{ job.status }}
+          matrix_name: ${{ matrix.test_task }}
+          committer_name: ${{ github.event.head_commit.committer.name }}
+          commit_message: ${{ github.event.head_commit.message }}
+          commit_timestamp: ${{ github.event.head_commit.timestamp }}
+        env:
+          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
+        if: failure() && github.event_name == 'push'
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]