From 141da55d9363d8c66f88db726d5d9c7318e00fa1 Mon Sep 17 00:00:00 2001 From: Kaleo Date: Thu, 23 Feb 2023 15:52:04 +0800 Subject: [PATCH] Add new workflow to post status msg to slack --- .github/workflows/slack_status_notify.yml | 147 ++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 .github/workflows/slack_status_notify.yml diff --git a/.github/workflows/slack_status_notify.yml b/.github/workflows/slack_status_notify.yml new file mode 100644 index 0000000..24a77ff --- /dev/null +++ b/.github/workflows/slack_status_notify.yml @@ -0,0 +1,147 @@ +name: Workflow to post status msg in Slack channel +on: + workflow_call: + inputs: + status: + #['success', 'failure', 'cancelled', 'skipped'] + type: string + required: false + slack_channel_id: + type: string + required: true + msg: + type: string + required: true + secrets: + SLACK_BOT_TOKEN: + required: true + + + +jobs: + post-slack-msg: + name: Post msg to Slack + runs-on: ubuntu-latest + timeout-minutes: 10 + env: + RUN_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + + steps: + - name: Post in progress msg on Slack + if: inputs.status == '' + uses: slackapi/slack-github-action@v1.23.0 + with: + # Slack channel id, channel name, or user id to post message. + # See also: https://api.slack.com/methods/chat.postMessage#channels + # You can pass in multiple channels to post to by providing a comma-delimited list of channel IDs. + channel-id: ${{ inputs.slack_channel_id }} + payload: | + { + "text": "${{ inputs.msg }}", + "attachments": [ + { + "color": "dbab09", + "fields": [ + { + "title": "Status", + "short": true, + "value": "In Progress" + }, + { + "title": "Run", + "short": true, + "value": "${{ env.RUN_URL }}" + } + ] + } + ] + } + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + + - name: Post success msg to Slack + if: inputs.status == 'success' + uses: slackapi/slack-github-action@v1.23.0 + with: + channel-id: ${{ inputs.slack_channel_id }} + payload: | + { + "text": "${{ inputs.msg }}", + "attachments": [ + { + "color": "28a745", + "fields": [ + { + "title": "Status", + "short": true, + "value": "Success" + }, + { + "title": "Run", + "short": true, + "value": "${{ env.RUN_URL }}" + } + ] + } + ] + } + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + + - name: Post failure msg to Slack + if: inputs.status == 'failure' + uses: slackapi/slack-github-action@v1.23.0 + with: + channel-id: ${{ inputs.slack_channel_id }} + payload: | + { + "text": "${{ inputs.msg }}", + "attachments": [ + { + "color": "bc0d24", + "fields": [ + { + "title": "Status", + "short": true, + "value": "Failure" + }, + { + "title": "Run", + "short": true, + "value": "${{ env.RUN_URL }}" + } + ] + } + ] + } + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + + - name: Post cancelled msg to Slack + if: inputs.status == 'cancelled' + uses: slackapi/slack-github-action@v1.23.0 + with: + channel-id: ${{ inputs.slack_channel_id }} + payload: | + { + "text": "${{ inputs.msg }}", + "attachments": [ + { + "color": "808080", + "fields": [ + { + "title": "Status", + "short": true, + "value": "Cancelled" + }, + { + "title": "Run", + "short": true, + "value": "${{ env.RUN_URL }}" + } + ] + } + ] + } + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}