Skip to content

Add slack notification to Snapshot-CI #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Dec 19, 2024
86 changes: 86 additions & 0 deletions .github/workflows/snapshot-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,89 @@ jobs:
path: |
powsybl-metrix/metrix-simulator/build/install/bin
powsybl-metrix/metrix-simulator/build/install/etc

- name: Store job result
if: always()
run: |
echo "${{ matrix.os }}=${{ job.status }}" >> job_result_${{ matrix.os }}.txt

- name: Upload job result
if: always()
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # 4.3.3
with:
name: job-results_${{ matrix.os }}
path: job_result_${{ matrix.os }}.txt

outputs:
core-version: ${{ env.CORE_VERSION }}
metrix-branch: ${{ env.INTEGRATION_BRANCH }}

# Slack notification on failure
notify_slack:
needs: build_powsybl_metrix
runs-on: ubuntu-latest
if: always()
steps:
- name: Determine workflow status
id: workflow_status
run: |
if [ "${{ job.status }}" == "success" ]; then
echo "icon=✅" >> $GITHUB_OUTPUT
echo "status=Successful" >> $GITHUB_OUTPUT
else
echo "icon=❌" >> $GITHUB_OUTPUT
echo "status=Failed" >> $GITHUB_OUTPUT
fi

- name: Download job results
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8

- name: Combine job results
run: |
for dir in job-results_*; do
cat "$dir"/* >> combined_job_results.txt
done

- name: Format job results
id: format_results
run: |
formatted=""
while IFS='=' read -r os status; do
icon=$([ "$status" == "success" ] && echo ":white_check_mark:" || echo ":x:")
formatted+="${icon} Build powsybl-metrix on *${os}*\\n"
done < combined_job_results.txt
formatted="${formatted%\\n}" # Remove the last newline
echo "formatted_results=${formatted}" >> $GITHUB_OUTPUT

- name: Send Slack Notification
uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2
with:
author_name: 'powsybl-metrix on GitHub'
status: custom
custom_payload: |
{
attachments: [{
color: '${{ job.status }}' === 'success' ? "#319f4b" : '${{ job.status }}' === 'failure' ? "#f64538" : "#ffc965",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"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 }}"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"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>"
}
}
]
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_METRIX }}
Loading