Skip to content

Commit

Permalink
Update slack notification
Browse files Browse the repository at this point in the history
  • Loading branch information
CountNick committed Jun 19, 2024
1 parent 55931b7 commit 34785e1
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,30 @@ jobs:

notification:
name: Slack notification
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
if: always()
needs: [ci]

env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

steps:
- name: Send notification
uses: edge/simple-slack-notify@master
with:
channel: "#ci"
username: CI
status: ${{ (contains(needs.*.result, 'cancelled') && 'cancelled') || (contains(needs.*.result, 'failure') && 'failure') || 'success' }}
success_text: ":octocat: <${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}|Build #${env.GITHUB_RUN_NUMBER}> of *${env.GITHUB_REPOSITORY}@${{ github.ref_name }}* by *${env.GITHUB_ACTOR}* completed successfully."
failure_text: ":octocat: <${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}|Build #${env.GITHUB_RUN_NUMBER}> of *${env.GITHUB_REPOSITORY}@${{ github.ref_name }}* by *${env.GITHUB_ACTOR}* failed."
cancelled_text: ":octocat: <${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}|Build #${env.GITHUB_RUN_NUMBER}> of *${env.GITHUB_REPOSITORY}@${{ github.ref_name }}* by *${env.GITHUB_ACTOR}* was cancelled."
- run: |
successText=":octocat: <${{ env.GITHUB_SERVER_URL }}/${{ env.GITHUB_REPOSITORY }}/actions/runs/${{ env.GITHUB_RUN_ID }}|Versie ${{ inputs.version }}> uitgerold naar *${{ inputs.environment }}*."
failureText=":octocat: <${{ env.GITHUB_SERVER_URL }}/${{ env.GITHUB_REPOSITORY }}/actions/runs/${{ env.GITHUB_RUN_ID }}|Versie ${{ inputs.version }}> niet uitgerold naar *${{ inputs.environment }}*."
cancelledText=":octocat: <${{ env.GITHUB_SERVER_URL }}/${{ env.GITHUB_REPOSITORY }}/actions/runs/${{ env.GITHUB_RUN_ID }}|Versie ${{ inputs.version }}> uitrol naar *${{ inputs.environment }}* geannuleerd."
status="${{ (contains(needs.*.result, 'cancelled') && 'cancelled') || (contains(needs.*.result, 'failure') && 'failure') || 'success' }}"
if [ "$status" = 'success' ]; then
color='good'
text=$successText
elif [ "$status" = 'failure' ]; then
color='danger'
text=$failureText
elif [ "$status" = "cancelled" ]; then
color='warning'
text=$cancelledText
fi
curl "${{ secrets.SLACK_WEBHOOK_URL }}" -X "POST" --header "Content-Type: application/json" \
--data "{attachments: [{text: '$text', color: '$color'}]}"

0 comments on commit 34785e1

Please sign in to comment.