-
Notifications
You must be signed in to change notification settings - Fork 0
170 lines (169 loc) · 6.05 KB
/
notify_slack.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: notify_slack
on:
workflow_call:
inputs:
test_type:
type: string
required: true
test_subtype:
type: string
required: true
be_url:
type: string
required: true
fe_url:
type: string
required: false
default: ""
slack_channel:
type: string
required: false
default: "sdp-test-report"
workflow_name:
type: string
required: true
workflow_id:
type: string
required: true
default: ""
workflow_reusable_name:
type: string
required: true
default: ""
project:
description: Lagoon project name
type: string
required: true
default: ""
artifact_name:
description: Name of the report file
type: string
required: true
jobs:
slack_notify:
name: sdp-test-report
runs-on: ubuntu-latest
if: always()
steps:
- name: Wait 15s for previous jobs to conclude
run: sleep 15
- uses: dpc-sdp/workflow-conclusion-action@main
with:
JOB_ID: ${{ inputs.workflow_id }}
REUSABLE_WORKFLOW_NAME: ${{ inputs.workflow_reusable_name }}
- uses: actions/download-artifact@v4
with:
name: ${{ inputs.artifact_name }}
- name: prepare-report
run: |
if [[ -z $FE_BASE_URL ]]; then
echo TEST_ENVIRONMENTS="*BE URL:* $BE_BASE_URL" >> $GITHUB_ENV
else
echo TEST_ENVIRONMENTS="*BE URL:* $BE_BASE_URL \n *FE URL:* $FE_BASE_URL" >> $GITHUB_ENV
fi
env:
BE_BASE_URL: ${{ inputs.be_url }}
FE_BASE_URL: ${{ inputs.fe_url }}
- name: prepare-report-api
if: ${{ inputs.test_type == ':postman:' }}
run: |
echo "REPORT_TEXT=API test report is stored in the CI job summary artifacts" >> $GITHUB_ENV
- name: prepare-report-e2e
if: ${{ inputs.test_type != ':postman:' }}
run: |
if [ -f "report-url.txt" -a -s "report-url.txt" ]; then
echo "Workflow status is $WORKFLOW_CONCLUSION"
if [ "$WORKFLOW_CONCLUSION" = "success" ]; then
echo "REPORT_TEXT=:white_check_mark: *<$(cat report-url.txt)|Test Report>*" >> $GITHUB_ENV
else
echo "REPORT_TEXT=:bangbang: *<$(cat report-url.txt)|Test Report>*" >> $GITHUB_ENV
fi
else
echo "REPORT_TEXT=:crying_cat_face: No report found. Testing may have been skipped." >> $GITHUB_ENV
fi
- name: sdp-test-report-success
uses: slackapi/[email protected]
if: env.WORKFLOW_CONCLUSION == 'success'
env:
REPO_NAME: ${{ github.repository }}
REPO_URL: ${{ github.event.repository.html_url }}
JOB: ${{ github.workflow }}
LINK: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
BRANCH_LINK: ${{ github.event.pull_request && github.head_ref || github.ref_name }}
SLACK_BOT_TOKEN: ${{ secrets.TEST_SLACK_BOT_TOKEN }}
ARTIFACTS_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
with:
channel-id: ${{ inputs.slack_channel }}
payload: |
{
"attachments": [
{
"color": "#14b942",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${{ inputs.test_type }}${{ inputs.test_subtype }} *<${{ github.event.repository.html_url }}|${{ github.repository }}> - Test <${{ env.LINK }}|${{ inputs.workflow_name }}> on ${{ env.BRANCH_LINK }} has passed.*"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "${{ env.TEST_ENVIRONMENTS }}"
},
{
"type": "mrkdwn",
"text": "${{ env.REPORT_TEXT }}"
}
]
}
]
}
]
}
- name: sdp-test-report-fail
uses: slackapi/[email protected]
if: env.WORKFLOW_CONCLUSION != 'success'
with:
channel-id: ${{ inputs.slack_channel }}
payload: |
{
"attachments": [
{
"color": "#f44336",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${{ inputs.test_type }}${{ inputs.test_subtype }} *<${{ github.event.repository.html_url }}|${{ github.repository }}> - Test <${{ env.LINK }}|${{ inputs.workflow_name }}> on ${{ env.BRANCH_LINK }} has failed.*"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "${{ env.TEST_ENVIRONMENTS }}"
},
{
"type": "mrkdwn",
"text": "${{ env.REPORT_TEXT }}"
}
]
}
]
}
]
}
env:
REPO_NAME: ${{ github.repository }}
REPO_URL: ${{ github.event.repository.html_url }}
JOB: ${{ github.workflow }}
LINK: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
BRANCH_LINK: ${{ github.event.pull_request && github.head_ref || github.ref_name }}
SLACK_BOT_TOKEN: ${{ secrets.TEST_SLACK_BOT_TOKEN }}
ARTIFACTS_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"