From ff42676b21bd0e84b54f93db128bc432e20b3124 Mon Sep 17 00:00:00 2001 From: Benjamin Lee <130000039+benlee0423@users.noreply.github.com> Date: Mon, 14 Aug 2023 08:37:24 -0700 Subject: [PATCH] Publish slack message to slack channel (#20) * add actions to publish slack messages --- .github/action_templates/slack/action.yaml | 29 +++++++++++++++++++ .github/workflows/docker_deps_image.yml | 2 +- .../workflows/docker_image_main_branch.yml | 16 ++++++++++ .github/workflows/docker_ngen_image.yml | 2 +- .github/workflows/docker_slack.yml | 25 ---------------- .github/workflows/docker_troute_image.yml | 2 +- 6 files changed, 48 insertions(+), 28 deletions(-) create mode 100644 .github/action_templates/slack/action.yaml delete mode 100644 .github/workflows/docker_slack.yml diff --git a/.github/action_templates/slack/action.yaml b/.github/action_templates/slack/action.yaml new file mode 100644 index 0000000..8d03856 --- /dev/null +++ b/.github/action_templates/slack/action.yaml @@ -0,0 +1,29 @@ +name: Send Slack Message +description: "Send slack message to a channel" + +inputs: + slack-webhook-url: + description: 'Slack webhook url' + required: true + job-status: + description: 'Job status' + required: true + pull_request_url: + description: 'Pull request url' + required: true + head_commit_url: + description: 'Head commit url' + required: true + +runs: + using: "composite" + steps: + - name: send slack message + uses: slackapi/slack-github-action@v1.24.0 + with: + payload: | + { + "text": "GitHub Action build result: ${{ inputs.job-status }}\n${{ inputs.pull_request_url || inputs.head_commit_url }}" + } + env: + SLACK_WEBHOOK_URL: ${{ inputs.slack-webhook-url}} \ No newline at end of file diff --git a/.github/workflows/docker_deps_image.yml b/.github/workflows/docker_deps_image.yml index 3f40f1c..a9f1985 100644 --- a/.github/workflows/docker_deps_image.yml +++ b/.github/workflows/docker_deps_image.yml @@ -25,4 +25,4 @@ jobs: docker-auth-token: ${{ secrets.DOCKER_AUTH_TOKEN }} github-sha: ${{ github.sha }} image-name: "ngen-deps" - dockerfile-name: "Dockerfile.ngen-deps" + dockerfile-name: "Dockerfile.ngen-deps" \ No newline at end of file diff --git a/.github/workflows/docker_image_main_branch.yml b/.github/workflows/docker_image_main_branch.yml index 49062b8..1f6d4c9 100644 --- a/.github/workflows/docker_image_main_branch.yml +++ b/.github/workflows/docker_image_main_branch.yml @@ -24,8 +24,24 @@ jobs: github-sha: ${{ github.sha }} image-name: "ciroh-ngen-image" dockerfile-name: "Dockerfile" + - name: Publish slack message + if: always() + uses: ./.github/action_templates/slack + with: + slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }} + job-status: ${{ job.status }} + pull_request_url: ${{ github.event.pull_request.html_url }} + head_commit_url: ${{ github.event.head_commit.url }} on-failure: runs-on: self-hosted if: ${{ github.event.workflow_run.conclusion == 'failure' }} steps: - run: echo 'The triggering workflow failed' + - name: Publish slack message + if: always() + uses: ./.github/action_templates/slack + with: + slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }} + job-status: ${{ job.status }} + pull_request_url: ${{ github.event.pull_request.html_url }} + head_commit_url: ${{ github.event.head_commit.url }} \ No newline at end of file diff --git a/.github/workflows/docker_ngen_image.yml b/.github/workflows/docker_ngen_image.yml index d429920..6aa6405 100644 --- a/.github/workflows/docker_ngen_image.yml +++ b/.github/workflows/docker_ngen_image.yml @@ -28,4 +28,4 @@ jobs: runs-on: self-hosted if: ${{ github.event.workflow_run.conclusion == 'failure' }} steps: - - run: echo 'The triggering workflow failed' + - run: echo 'The triggering workflow failed' \ No newline at end of file diff --git a/.github/workflows/docker_slack.yml b/.github/workflows/docker_slack.yml deleted file mode 100644 index b1040d6..0000000 --- a/.github/workflows/docker_slack.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Publish slack message -on: - push: - branches: [ main ] - paths: - - docker/** - workflow_run: - workflows: [Build and push final image] - types: - - completed - workflow_dispatch: - -jobs: - publish-slack: - runs-on: self-hosted - steps: - - run: echo 'The triggering workflow failed' - - name: Publish slack message - uses: ./.github/action_templates/slack - with: - slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }} - job-status: ${{ job.status }} - pull_request_url: ${{ github.event.pull_request.html_url }} - head_commit_url: ${{ github.event.head_commit.url }} - diff --git a/.github/workflows/docker_troute_image.yml b/.github/workflows/docker_troute_image.yml index f67d365..acc0f94 100644 --- a/.github/workflows/docker_troute_image.yml +++ b/.github/workflows/docker_troute_image.yml @@ -28,4 +28,4 @@ jobs: runs-on: self-hosted if: ${{ github.event.workflow_run.conclusion == 'failure' }} steps: - - run: echo 'The triggering workflow failed' + - run: echo 'The triggering workflow failed' \ No newline at end of file