https://github.com/pcvg/slack-notification-action
GitHub Action for Slack notifications
https://github.com/pcvg/slack-notification-action
Last synced: 7 months ago
JSON representation
GitHub Action for Slack notifications
- Host: GitHub
- URL: https://github.com/pcvg/slack-notification-action
- Owner: pcvg
- License: gpl-3.0
- Created: 2020-01-23T17:22:58.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-03-28T15:12:06.000Z (about 1 year ago)
- Last Synced: 2025-04-09T20:19:18.252Z (about 1 year ago)
- Language: TypeScript
- Size: 203 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Slack Notification Action
Send custom notifications to Slack from Github Actions. You can define the content of the message and the title in case of success or failure.
## 🚀 Running in GitHub Actions
Run this action in Github Actions by adding `pcvg/slack-notification-action@main` to your steps.
### Parameters
| Name | Meaning | Default | Required |
| --- | --- | --- | --- |
| `SLACK_WEBHOOK_URL` | Default webhook | X | true |
| `SLACK_FAILURE_WEBHOOK_URL` | Webhook in case of failure and cancellation | `SLACK_WEBHOOK_URL`| false |
| `TITLE_SUCCESS` | Title of the message in case of success | X | false |
| `TITLE_FAIL` | Title of the message in case of fail | X | false |
| `BODY_SUCCESS` | Message content in case of success | X | true |
| `BODY_FAIL` | Message content in case of fail | X | true |
### Example - How to use?
```yml
name: Notification example
on:
push:
branches:
- master
jobs:
slack-notify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Notify
if: always()
uses: pcvg/slack-notification-action@main
with:
SLACK_WEBHOOK_URL: https://hooks.slack.com/services/XXXX
SLACK_FAILURE_WEBHOOK_URL: https://hooks.slack.com/services/XXXX
TITLE_SUCCESS: "Your build was completed successfully."
TITLE_FAIL: "Your build failed."
BODY_SUCCESS: "The build started by ${{ github.actor }} in API service was completed successfully"
BODY_FAIL: "Failed - ${{ github.actor }}'s build failed - "
```
### Considerations
- `SLACK_WEBHOOK_URL` will be used as failure and success webhook if `SLACK_FAILURE_WEBHOOK_URL` is not defined.
- `SLACK_FAILURE_WEBHOOK_URL` it is used when the workflow fails or is canceled.
- You can get the webhook URL from [Slack Apps](https://app.slack.com/apps-manage/)
## ⚙️ Local dev
You can re-build locally.
Install dependencies:
$ npm i
Build:
$ npm run build
Run tests:
$ Coming soon!
Local testing:
```sh
INPUT_SLACK_WEBHOOK_URL='https://hooks.slack.com/services/XXXX' \
INPUT_SLACK_FAILURE_WEBHOOK_URL='https://hooks.slack.com/services/XXXX' \
INPUT_JOB_STATUS='success' \
INPUT_TITLE_SUCCESS='Build Success' \
INPUT_BODY_SUCCESS='Your build completed successfully!' \
INPUT_URL_WORKFLOW='https://github.com/test/repo/actions/runs/123' \
node dist/index.js
INPUT_SLACK_WEBHOOK_URL='https://hooks.slack.com/services/XXXX' \
INPUT_SLACK_FAILURE_WEBHOOK_URL='https://hooks.slack.com/services/XXXX' \
INPUT_TITLE_FAIL='Build Failed' \
INPUT_BODY_FAIL='Your build failed. Please check the logs.' \
INPUT_URL_WORKFLOW='https://github.com/test/repo/actions/runs/123' \
node dist/index.js
```
## ⚖️ License
This project is licensed under the GPL-3.0 License - see the [LICENSE](LICENSE) file for details