Skip to content

Commit

Permalink
Add send-slack-notification (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
meziantou authored Nov 5, 2024
1 parent 1a91b33 commit 703740d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ jobs:
secrets: inherit
```
## Send Slack notification
```yml
jobs:
sample:
steps:
- uses: gsoft-inc/wl-reusable-workflows/send-slack-notification@main
with:
webhook_url: ${{secrets.SLACK_WEBHOOK_URL_IDP_DEV_ALERTS}}
# Use either text or messageTemplate
text: Sample message
messageTemplate: "FailedJob" # Support "", "FailedJob"
```
## Terraform checks
This workflow runs TF-Lint to find issues in the code, Terraform-Docs to create a README and Terraform FMT to format the code.
Expand Down
34 changes: 34 additions & 0 deletions send-slack-notification/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "Post slack message"

inputs:
webhook_url:
required: true
text:
default: ""
messageTemplate:
description: "One of the supported template name: 'FailedJob'"
default: ""
type: choice
options:
- ""
- "FailedJob"

runs:
using: "composite"
steps:
- shell: pwsh
run: |
$text = $null
$template = "${{inputs.messageTemplate}}"
if ($template -eq "FailedJob") {
$text = "❌ ${{github.repository}}: The workflow '${{github.workflow}}' failed. Logs: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
}
if (-not $text) {
# Attempt to avoid escaping issue when the value contains quotes or PowerShell specific characters
$text = @"
${{toJson(inputs.text)}}
"@ | ConvertFrom-Json
}
Invoke-RestMethod -Uri "${{inputs.webhook_url}}" -Headers @{ "Content-Type" = "application/json" } -Method Post -Body (@{ text = $text } | ConvertTo-Json)

0 comments on commit 703740d

Please sign in to comment.