This action is a workaround for this open issue in the slack-github-action, specifically when expanding context related variables in a template file.
Name | Description | Optional |
---|---|---|
payload-file-path |
Path to JSON-formatted template file to fix | ✔️ * |
payload |
JSON string template file to fix | ✔️ * |
replacements |
Ad-hoc replacements to perform on the payload-file-path ; see Ad-hoc replacements |
✔️ |
channel-id |
Slack channel to send the message to | ❌ |
slack-bot-token |
Access token to the Slack API | ❌ |
Either
payload
orpayload-file-path
must be provided, the step will fail if none is provided.
Given the following workflow step:
name: Send notifications
uses: rapyuta-robotics/[email protected]
with:
payload-file-path: ./failure_notification.json
replacements: |
NOTIFICATION_HEADER=":warning: Failed ${{ github.sha }}"
NOTIFICATION_FOOTER="See <www.example.com>"
WRONG=This will not be replaced
channel-id: ABCDFG
slack-bot-token: ${{ secrets.SLACK_NOTIFICATIONS_APP_TOKEN }}
The input
replacements
may use any valid github action expression and they will be expanded to its corresponding values before running the replacement step; in this example,${{ github.sha }}
will be replaced by the commit sha before running the actual replacement.
This action will perfom the following steps:
- Take every new line under
ad-hoc-replacements
as a potential replacement in the template, in this case there will be 3 potential replacements. - Validate each potential candidate according to
/(.+?)="(.+?)"/
, if it doesn't match the regex, it will be skipped; in this caseWRONG=This will not be replaced
will be discarded as it is missing the quotation marks. - Every ocurrence of the first capture group preceeded by a percentage sign present in the template will be repaced by the second capture group, that is, every ocurrence of
%NOTIFICATION_HEADER
in the template will be replaced by:warning: Failed 1a6184908f91b86ba226f4436a7b0323fbc2820b
, and likewise ocurrences of%NOTIFICATION_FOOTER
will be replaced bySee <www.example.com>
.