-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
80 lines (76 loc) · 4.27 KB
/
action.yml
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: 'GitHub Actions Notify for Slack'
description: 'Send CI results to Slack'
inputs:
SLACK_WEBHOOK_URL: # cf. https://api.slack.com/messaging/webhooks
description: 'Slack Incoming WebHook URL'
required: true
default: ''
STATUS: # Status of previous job
description: 'Get previous job status'
required: false
default: ${{ job.status }}
#inputs:
# channel-id: # channel of input
# description: 'Slack Channel ID to post message'
# required: true
# default: ''
# SLACK_BOT_TOKEN: # channel of input
# description: 'Slack token to post message'
# required: true
# default: ''
runs:
using: "composite"
steps:
- name: 👤 Get commit info for notification
shell: bash
run: |
echo 'COMMIT_ACTOR=${{ github.actor }}' | awk -F '-preview' '{print $1}' >> $GITHUB_ENV
if [ "${{ inputs.STATUS }}" = "success" ]; then
echo "STATUS_LABEL=success" >> $GITHUB_ENV
echo "STATUS_TEXT=Success" >> $GITHUB_ENV
echo "STATUS_VERB=passed" >> $GITHUB_ENV
elif [ "${{ inputs.STATUS }}" = "skipped" ]; then
echo "STATUS_LABEL=default" >> $GITHUB_ENV
echo "STATUS_TEXT=Skip" >> $GITHUB_ENV
echo "STATUS_VERB=skipped" >> $GITHUB_ENV
else
echo "STATUS_LABEL=danger" >> $GITHUB_ENV
echo "STATUS_TEXT=Failure" >> $GITHUB_ENV
echo "STATUS_VERB=failed" >> $GITHUB_ENV
fi
if [ "${{ github.event_name }}" = "pull_request" ]; then
head_sha=$(echo "${{ github.event.pull_request.head.sha }}" | head -c8)
echo "COMMIT_SHA=$head_sha" >> $GITHUB_ENV
echo "COMMIT_MESSAGE<<EOF" >> $GITHUB_ENV
echo "${{ github.event.pull_request.title }}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "COMMIT_URL=${{ github.event.pull_request.html_url }}" >> $GITHUB_ENV
echo "COMMIT_LINK=${{github.repository}}#${{github.event.pull_request.number}}" >> $GITHUB_ENV
else
head_sha=$(echo "${{ github.sha }}" | head -c8)
echo "COMMIT_SHA=$head_sha" >> $GITHUB_ENV
echo "COMMIT_MESSAGE<<EOF" >> $GITHUB_ENV
echo "${{ github.event.head_commit.message }}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "COMMIT_URL=https://github.com/${{github.repository}}/commit/$head_sha" >> $GITHUB_ENV
echo "COMMIT_LINK=${{ github.repository }}#$head_sha" >> $GITHUB_ENV
fi
- name: 🔔 Slack CI Notify
uses: slackapi/[email protected]
# cf. https://github.com/slackapi/slack-github-action
id: slack
env:
SLACK_WEBHOOK_URL: ${{ inputs.SLACK_WEBHOOK_URL }}
with:
channel-id: ${{ inputs.channel-id }}
slack-message: |
Your tests ${{ env.STATUS_VERB }} on [${{ env.COMMIT_LINK }}](${{ env.COMMIT_URL }}) ([build](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})) : <span class='label label-${{ env.STATUS_LABEL }}'>${{ env.STATUS_TEXT }}</span><br><img src='https://github.com/${{ env.COMMIT_ACTOR }}.png' class='icon-rounded' width='16' height='16'> [${{ env.COMMIT_ACTOR }}](https://github.com/${{ env.COMMIT_ACTOR }}): ${{ env.COMMIT_MESSAGE }} ([${{ env.COMMIT_SHA }}](https://github.com/${{ github.repository }}/commit/${{ env.COMMIT_SHA }}))
# - name: 🔔 Notify results to Slack
# env:
# IDOBATA_SECRETS: ${{ inputs.slack_hook_url }}
# uses: mahaker/[email protected]
# with:
# hookUrl: ${{ env.IDOBATA_SECRETS }}
# format: 'markdown'
# message: |
# Your tests ${{ env.STATUS_VERB }} on [${{ env.COMMIT_LINK }}](${{ env.COMMIT_URL }}) ([build](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})) : <span class='label label-${{ env.STATUS_LABEL }}'>${{ env.STATUS_TEXT }}</span><br><img src='https://github.com/${{ env.COMMIT_ACTOR }}.png' class='icon-rounded' width='16' height='16'> [${{ env.COMMIT_ACTOR }}](https://github.com/${{ env.COMMIT_ACTOR }}): ${{ env.COMMIT_MESSAGE }} ([${{ env.COMMIT_SHA }}](https://github.com/${{ github.repository }}/commit/${{ env.COMMIT_SHA }}))