Skip to content

Commit 7e904f9

Browse files
authored
Add slack notification to Snapshot-CI (#193)
* test with slack notification Signed-off-by: Nicolas Rol <[email protected]> * test slack notification Signed-off-by: Nicolas Rol <[email protected]> * fix status Signed-off-by: Nicolas Rol <[email protected]> * fix status Signed-off-by: Nicolas Rol <[email protected]> * use upload/download-artifacts to transfert status Signed-off-by: Nicolas Rol <[email protected]> * fix artifacts names Signed-off-by: Nicolas Rol <[email protected]> * fix artifacts names Signed-off-by: Nicolas Rol <[email protected]> * fix artifacts names Signed-off-by: Nicolas Rol <[email protected]> * test with notification Signed-off-by: Nicolas Rol <[email protected]> * fix variable Signed-off-by: Nicolas Rol <[email protected]> * delete JOB_RESULT variable + change token Signed-off-by: Nicolas Rol <[email protected]> * test one line - no notification Signed-off-by: Nicolas Rol <[email protected]> * add notification and metrix branch used Signed-off-by: Nicolas Rol <[email protected]> * fix text Signed-off-by: Nicolas Rol <[email protected]> * fix line Signed-off-by: Nicolas Rol <[email protected]> * delete unused file Signed-off-by: Nicolas Rol <[email protected]> --------- Signed-off-by: Nicolas Rol <[email protected]>
1 parent 977754d commit 7e904f9

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

Diff for: .github/workflows/snapshot-ci.yml

+86
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,89 @@ jobs:
149149
path: |
150150
powsybl-metrix/metrix-simulator/build/install/bin
151151
powsybl-metrix/metrix-simulator/build/install/etc
152+
153+
- name: Store job result
154+
if: always()
155+
run: |
156+
echo "${{ matrix.os }}=${{ job.status }}" >> job_result_${{ matrix.os }}.txt
157+
158+
- name: Upload job result
159+
if: always()
160+
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # 4.3.3
161+
with:
162+
name: job-results_${{ matrix.os }}
163+
path: job_result_${{ matrix.os }}.txt
164+
165+
outputs:
166+
core-version: ${{ env.CORE_VERSION }}
167+
metrix-branch: ${{ env.INTEGRATION_BRANCH }}
168+
169+
# Slack notification on failure
170+
notify_slack:
171+
needs: build_powsybl_metrix
172+
runs-on: ubuntu-latest
173+
if: always()
174+
steps:
175+
- name: Determine workflow status
176+
id: workflow_status
177+
run: |
178+
if [ "${{ job.status }}" == "success" ]; then
179+
echo "icon=✅" >> $GITHUB_OUTPUT
180+
echo "status=Successful" >> $GITHUB_OUTPUT
181+
else
182+
echo "icon=❌" >> $GITHUB_OUTPUT
183+
echo "status=Failed" >> $GITHUB_OUTPUT
184+
fi
185+
186+
- name: Download job results
187+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
188+
189+
- name: Combine job results
190+
run: |
191+
for dir in job-results_*; do
192+
cat "$dir"/* >> combined_job_results.txt
193+
done
194+
195+
- name: Format job results
196+
id: format_results
197+
run: |
198+
formatted=""
199+
while IFS='=' read -r os status; do
200+
icon=$([ "$status" == "success" ] && echo ":white_check_mark:" || echo ":x:")
201+
formatted+="${icon} Build powsybl-metrix on *${os}*\\n"
202+
done < combined_job_results.txt
203+
formatted="${formatted%\\n}" # Remove the last newline
204+
echo "formatted_results=${formatted}" >> $GITHUB_OUTPUT
205+
206+
- name: Send Slack Notification
207+
uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2
208+
with:
209+
author_name: 'powsybl-metrix on GitHub'
210+
status: custom
211+
custom_payload: |
212+
{
213+
attachments: [{
214+
color: '${{ job.status }}' === 'success' ? "#319f4b" : '${{ job.status }}' === 'failure' ? "#f64538" : "#ffc965",
215+
"blocks": [
216+
{
217+
"type": "section",
218+
"text": {
219+
"type": "mrkdwn",
220+
"text": "${{ steps.workflow_status.outputs.icon }} *${{ steps.workflow_status.outputs.status }} workflow: Snapshot-CI on <https://github.com/powsybl/powsybl-metrix|powsybl-metrix>*\n\nBranch built: ${{ needs.build_powsybl_metrix.outputs.metrix-branch }}\nPowSyBl-Core version used: ${{ needs.build_powsybl_metrix.outputs.core-version }}"
221+
}
222+
},
223+
{
224+
"type": "divider"
225+
},
226+
{
227+
"type": "section",
228+
"text": {
229+
"type": "mrkdwn",
230+
"text": "*Workflow details:*\n\n${{ steps.format_results.outputs.formatted_results }}\n\nSee logs on <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|GitHub>"
231+
}
232+
}
233+
]
234+
}]
235+
}
236+
env:
237+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_METRIX }}

0 commit comments

Comments
 (0)