Non-existing ENV variables are reported with ??? instead of empty value
Description
If a env variable which is in payload is missing, ??? are sent instead of empty value. It would be nice to not put ??? which confuses people but leave it empty (like empty variable).
What type of issue is this? (place an x in one of the [ ])
- [x] bug
- [ ] enhancement (feature request)
- [ ] question
- [ ] documentation related
- [ ] example code related
- [ ] 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
Filling out the following details about bugs will help us solve your issue sooner.
Reproducible in:
package version: latest
Steps to reproduce:
- Configure Slack payload json to contain some ENV variable which won't be existing f.e ${{ env.ACTIONS_URL }}
- Configure this github action to send notifiation where json contain this ENV
- When you check Slack notification it will contain ??? instead of empty variable
Expected result:
Instead of ??? I would expect missing variable to be shown just empty value (bash behavior)
Actual result:
Instead of empty, we get confusing ???
Attachments:
For example:
CVS api-tests: Successful: ??? | Failed: ??? | Total: ???
Metrics api-tests: Successful: ??? | Failed: ??? | Total: ???
Hi @jprecuch, thanks for sharing this. It seems that an underlying module (Markup.js) does it when a given input is undefined (source). Perhaps, to customize the behavior, passing empty string values instead in context can help.
I wanted to work on this issue, but I am having some trouble reproducing this behavior. Here's what I have in my workflow:
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: ["main"]
pull_request:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Send custom JSON data to Slack workflow
id: slack
uses: slackapi/[email protected]
with:
payload: |
{
"text": "This is an invalid environment variable: ${{ env.SAMPLE_ENV_VAR }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "This is an invalid environment variable: ${{ env.SAMPLE_ENV_VAR }}"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
SAMPLE_ENV_VAR is the non-existing environment variable but I do not see ??? in the output:
Am I misunderstanding something?
I wanted to work on this issue, but I am having some trouble reproducing this behavior. ... Am I misunderstanding something?
yes. do it with payload-file-path.
- name: "Slack Notify: Deployment Complete"
uses: slackapi/slack-github-action@6c661ce58804a1a20f6dc5fbee7f0381b469e001
id: slack-notify
env:
SLACK_BOT_TOKEN: ${{ inputs.SlackBotToken }}
DEPLOYRELEASEBRANCH_APPNAME: ${{ inputs.AppName }}
DEPLOYRELEASEBRANCH_APPVERSION: ${{ inputs.AppVersion }}
DEPLOYRELEASEBRANCH_ENVIRONMENT: ${{ inputs.Environment }}
DEPLOYRELEASEBRANCH_JOBNAME: ${{ inputs.JobName }}
DEPLOYRELEASEBRANCH_JOBURL: ${{ inputs.JobUrl }}
DEPLOYRELEASEBRANCH_GITHUBACTOR: ${{ inputs.GithubActor }}
with:
channel-id: ${{ inputs.SlackChannelId }}
update-ts: ${{ inputs.MessageId }}
payload-file-path: ${{ github.action_path }}/slack-notification.json
Somewhat related, but missing github.* variables in the payload-file-path are also displayed as ???. This specific case is being tracked over in #203!
👋 I'm finding this can use magic syntax @seratch suggested to default to empty values from the workflow file! With the latest @v2 release, the following step might be useful:
- name: Share an update
uses: slackapi/[email protected]
with:
method: chat.postMessage
payload-file-path: ./example.json
payload-templated: true
token: ${{ secrets.SLACK_BOT_TOKEN }}
env:
COMMIT_HASH: ${{ github.sha || '' }} # This line has the blank default!
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID }}
With an example.json like so:
{
"channel": "${{ env.SLACK_CHANNEL_ID }}",
"text": "A commit landed: ${{ env.COMMIT_HASH }}"
}
If the github event was to not have the matching values, the empty string would be used!
This should also apply to the @v1 tags so I'll close this issue, but wanted to leave a few more notes for updating 📚
- The
payload-templatedvariable can be used for both types of payloads! - The
payload-templatedvariable replaces thepayload-file-path-parsedoption! - The
payload-templatedvariable must be true to replace templated variables!
Finding certain values in the GitHub context can also be a cause of confusion, and options available when replacing templatized variables are available from the default GitHub event.
I'll close this issue with the workaround, but please feel free to comment with other ideas or follow up questions about this. I'm super open to ideas for enhancement here 🙏