Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-existing ENV variables are reported with ??? instead of empty value #226

Closed
4 of 10 tasks
jprecuch opened this issue Jul 3, 2023 · 5 comments
Closed
4 of 10 tasks
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@jprecuch
Copy link

jprecuch commented Jul 3, 2023

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 [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • example code related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • 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:

  1. Configure Slack payload json to contain some ENV variable which won't be existing f.e ${{ env.ACTIONS_URL }}
  2. Configure this github action to send notifiation where json contain this ENV
  3. 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: ???
@seratch seratch added enhancement New feature or request good first issue Good for newcomers labels Jul 5, 2023
@seratch seratch added this to the 1.x milestone Jul 5, 2023
@seratch
Copy link
Member

seratch commented Jul 5, 2023

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.

@arunsathiya
Copy link

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/slack-github-action@v1.24.0
        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:

image

Am I misunderstanding something?

@airtonix
Copy link

airtonix commented Apr 4, 2024

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

@zimeg
Copy link
Member

zimeg commented Apr 4, 2024

Somewhat related, but missing github.* variables in the payload-file-path are also displayed as ???. This specific case is being tracked over in #203!

@zimeg
Copy link
Member

zimeg commented Nov 16, 2024

👋 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/slack-github-action@v2.0.0
  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-templated variable can be used for both types of payloads!
  • The payload-templated variable replaces the payload-file-path-parsed option!
  • The payload-templated variable 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 🙏

@zimeg zimeg closed this as completed Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants