-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(slack): add a workflow about github status
- Loading branch information
1 parent
ae4fda6
commit 8894111
Showing
5 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# Slack Github Actions Status Workflow | ||
|
||
This workflow provides a standardized interface for sending GitHub Actions deployment status messages to Slack channels, with a predefined message format that includes repository, environment, and deployment details. | ||
|
||
## Usage | ||
|
||
```yaml | ||
jobs: | ||
notify: | ||
uses: ZeroGachis/.github/.github/workflows/send_slack_gha_status.yaml@v4 | ||
with: | ||
channel_id: "C0123456789" | ||
environment_name: production | ||
status: success # Optional, defaults to "success" | ||
secrets: inherit | ||
``` | ||
## Inputs | ||
### Required Inputs | ||
| Input | Description | | ||
| ------------------ | ---------------------------------------------------------------------------------- | | ||
| `channel_id` | Slack channel ID to send the message to (Can be find in Channel info in Slack app) | | ||
| `environment_name` | Target environment for Vault configuration | | ||
|
||
### Optional Inputs | ||
|
||
| Input | Default | Description | | ||
| --------------------------- | --------- | ------------------------------------------------------------ | | ||
| `vault_url` | - | Vault server URL | | ||
| `vault_github_actions_role` | - | Role to use for Vault authentication | | ||
| `status` | "success" | Deployment status ("success" or any other value for failure) | | ||
|
||
## Features | ||
|
||
- 🚀 Standardized deployment status messages | ||
- 📊 Rich message formatting with repository and deployment details | ||
- 👤 Automatic inclusion of triggering user | ||
- 🔗 Direct links to workflow run and commit | ||
- 🎨 Color-coded status indicators | ||
- 🔒 Secure credential management via HashiCorp Vault | ||
- 🌐 Environment-specific configuration | ||
|
||
## Example Usage | ||
|
||
### Basic Status Message | ||
|
||
```yaml | ||
jobs: | ||
notify-success: | ||
uses: ZeroGachis/.github/.github/workflows/send_slack_gha_status.yaml@v4 | ||
with: | ||
channel_id: "C0123456789" | ||
environment_name: staging | ||
status: success | ||
secrets: inherit | ||
``` | ||
|
||
### Failure Status Message | ||
|
||
```yaml | ||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Deploy application | ||
run: ./deploy.sh | ||
notify-failure: | ||
needs: deploy | ||
if: failure() | ||
uses: ZeroGachis/.github/.github/workflows/send_slack_gha_status.yaml@v4 | ||
with: | ||
channel_id: "C0123456789" | ||
environment_name: production | ||
status: failure | ||
secrets: inherit | ||
``` | ||
|
||
This example shows how to automatically send a failure notification when a job fails. The `if: failure()` condition ensures the notification is only sent if the `deploy` job fails. | ||
|
||
### Message Example | ||
|
||
 | ||
|
||
_Example of a successful deployment status message in Slack_ | ||
|
||
 | ||
|
||
_Example of a failed deployment status message in Slack_ | ||
|
||
### Message Format | ||
|
||
The message includes: | ||
|
||
- Repository name and link | ||
- Environment name | ||
- Deployment status (with emoji indicators) | ||
- Triggering user | ||
- Links to workflow run and commit | ||
- Color-coded status (green for success, red for failure) | ||
|
||
 | ||
|
||
_Example of a deployment status message in Slack_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
name: Send Slack Github Status | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
channel_id: | ||
required: true | ||
type: string | ||
environment_name: | ||
required: true | ||
type: string | ||
vault_url: | ||
required: false | ||
type: string | ||
vault_github_actions_role: | ||
required: false | ||
type: string | ||
status: | ||
required: false | ||
type: string | ||
default: "success" | ||
|
||
jobs: | ||
send-slack-gha-status: | ||
uses: ZeroGachis/.github/.github/workflows/send_slack_notif.yaml@feature/pla-2052 | ||
with: | ||
environment_name: ${{ inputs.environment_name }} | ||
vault_url: ${{ inputs.VAULT_URL || vars.VAULT_URL || vars.PULLREQUEST_VAULT_URL }} | ||
vault_github_actions_role: ${{ inputs.vault_github_actions_role || vars.VAULT_GITHUB_ACTIONS_ROLE }} | ||
payload: | | ||
{ | ||
"channel": ${{ inputs.channel_id }}, | ||
"attachments": [ | ||
{ | ||
"color": "${{ inputs.status == 'success' && '2eb67d' || 'e01e5a' }}", | ||
"blocks": [ | ||
{ | ||
"type": "header", | ||
"text": { | ||
"type": "plain_text", | ||
"text": "${{ inputs.status == 'success' && '✅' || '🔥' }} Deployment Status: ${{ github.event.repository.name }}", | ||
"emoji": true | ||
} | ||
}, | ||
{ | ||
"type": "section", | ||
"text": { | ||
"type": "mrkdwn", | ||
"text": "*Repository:* <${{ github.event.repository.html_url }}|${{ github.event.repository.name }}>\n*Environment:* `${{ inputs.environment_name }}`" | ||
} | ||
}, | ||
{ | ||
"type": "divider" | ||
}, | ||
{ | ||
"type": "section", | ||
"fields": [ | ||
{ | ||
"type": "mrkdwn", | ||
"text": "*Status:*\n${{ inputs.status == 'success' && '✅ Success' || '🔥 Failure' }}" | ||
}, | ||
{ | ||
"type": "mrkdwn", | ||
"text": "*Triggered by:*\n👤 `${{ github.actor }}`" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "section", | ||
"fields": [ | ||
{ | ||
"type": "mrkdwn", | ||
"text": "*Workflow:*\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Workflow Run ↗️>" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters