Github context is not properly referenced within the JSON payload template
Description
Github context is not properly referenced when using the workflow_run
What type of issue is this? (place an x in one of the [ ])
- [x] bug
- [ ] enhancement (feature request)
- [ ] question
- [ ] documentation related
- [ ] example code related
- [x] testing related
- [ ] discussion
Requirements (place an x in each of the [ ])
- [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
- [x] I've read and agree to the Code of Conduct.
- [x] I've searched for any related issues and avoided creating a duplicate issue.
Bug Report
Create a workflow_run github action
Reproducible in:
package version: v1.18.0 node version: v16.13.0 OS version(s):
Steps to reproduce:
- create a Github Action running on the
workflow_runevents - add a json template that uses
${{github.event.workflow_run.name}}for example - fire the event, and the json template will not properly replace the github context
Example of my JSON template
{
"text": "[Codebase News] - Pipeline is 🔴",
"attachments": [
{
"color": "#000",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Pipeline is 🔴 on `master`."
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Workflow `${{github.event.workflow_run.name}}` requires extra attention. :warning:"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "More info here ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.github.event.workflow_run.run_id}}"
}
]
}
]
}
]
}
Expected result:
I would expect for the JSON file to have in hand the entire provided github context corresponding to the workflow_run event triggers.
Actual result:
As you can see ${{github.event.workflow_run.name}} did not work as expected
Also the regular github context did not work as well, here

Side Node:
I looked into this issue https://github.com/slackapi/slack-github-action/issues/51, and was aware that the problem got fixed, but I tested it multiple times, it was not properly fixed.
Currently facing the same problem.
@yousseftarekkh i was able to see github context variables message data in my slack message . i have done following changes in payload json by adding spaces between context variables
{
"text": "[Codebase News] - Pipeline is 🔴",
"attachments": [
{
"color": "#000",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Pipeline is 🔴 on `master`."
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Workflow `${{ github.event.workflow_run.name }}` requires extra attention. :warning:"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "More info here ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.run_id }}"
}
]
}
]
}
]
}
i have received below message in slack
regarding github.event.workflow_run.name that is bug .
When using a payload template, slack-action gets the github.context from actions/toolkit and replaces the variables in the template.
You will find that there is no github.event.* and github.repository in the toolkit, you can get github.serverUrl but not github.server_url.
I have the same problem with the following snippet in the payload file:
{
"type": "button",
"text": {
"type": "plain_text",
"text": "▶️ Check running actions"
},
"style": "primary",
"url": "https://github.com/my-company/platform/actions?query=branch%3A${{ env.BRANCH_NAME }}"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "📑 Open PR"
},
"url": "https://github.com/my-company/platform/pull/${{ steps.head-ref-match.outputs.group1 }}"
},
Neither my custom env variable in {{ env.BRANCH_NAME }} nor referencing another step output with ${{ steps.head-ref-match.outputs.group1 }} seems to work. If I use them in payload text within the workflow file directly it works.
Any workaround for this?
This bug its horrible please release a bugfix

The most basic and important thing of this app (sending messages with github info) not working
This makes me want to switch off from Slack
I am seeing the same issue here. The payload-file-path template does not replace the env vars in the JSON template.
It looks like razor54 has a fix ready to go for this. Seems like the payload-file-path functionality is basically broken until this gets resolved.
Workflow code
- name: Workflow init slack message
id: slack-init-msg
uses: slackapi/[email protected]
env:
STATUS: "Success"
BRANCH: "DMZ-000_Test_stuff"
APP_NAME: "My_sweet_app"
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
channel-id: "my-test-channel"
payload-file-path: ./.github/slack-msg-payloads/init-msg.json
Template JSON file
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Deployment of ${{ env.APP_NAME }} to ${{ env.ENVIRO }} started",
"emoji": true
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "*Workflow URL:* `${{ env.WORKFLOW_URL }}`\n*BRANCH:* `${{ env.BRANCH }}`\n*Triggered by:* `${{ github.actor }}`"
}
]
},
{
"type": "divider"
}
],
"attachments": [
{
"color": "#0328fc",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "This area will be updated with the workflow progress, stay tuned!\n*Workflow status:* ${{ env.STATUS }}"
}
}
]
}
]
}
Output in Slack

any news on this? experiencing the same issue using a slack webhook and a json payload in a template file
We fixed this in #200; assigning to the 1.24 milestone, which we will release shortly.
Release v1.24.0 is out!