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

Github context is not properly referenced within the JSON payload template #84

Closed
5 of 10 tasks
ylkhayat opened this issue Apr 23, 2022 · 10 comments
Closed
5 of 10 tasks
Labels
bug Something isn't working
Milestone

Comments

@ylkhayat
Copy link

ylkhayat commented Apr 23, 2022

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

  • 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

Create a workflow_run github action

Reproducible in:

package version: v1.18.0
node version: v16.13.0
OS version(s):

Steps to reproduce:

  1. create a Github Action running on the workflow_run events
  2. add a json template that uses ${{github.event.workflow_run.name}} for example
  3. 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
image
Also the regular github context did not work as well, here
image

Side Node:

I looked into this issue #51, and was aware that the problem got fixed, but I tested it multiple times, it was not properly fixed.

@seratch seratch added the bug Something isn't working label Apr 26, 2022
@seratch seratch added this to the 1.19 milestone Apr 26, 2022
@seratch seratch modified the milestones: 1.19, 1.20 May 4, 2022
razor54 added a commit to razor54/slack-github-action that referenced this issue May 5, 2022
@FredericoIRodrigues
Copy link

Currently facing the same problem.

@nitintecg
Copy link
Contributor

nitintecg commented Jun 4, 2022

@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
image
regarding github.event.workflow_run.name that is bug .

@taofang2021
Copy link

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.

@seratch seratch modified the milestones: 1.20, 1.x Aug 15, 2022
@magnattic
Copy link

magnattic commented Aug 18, 2022

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?

razor54 added a commit to razor54/slack-github-action that referenced this issue Oct 21, 2022
@ivorsmorenburg
Copy link

This bug its horrible please release a bugfix
image

The most basic and important thing of this app (sending messages with github info) not working

@ivorsmorenburg
Copy link

This makes me want to switch off from Slack

@jr-surfline
Copy link

jr-surfline commented Dec 8, 2022

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
Screen Shot 2022-12-07 at 8 23 57 PM

@rd-florian-stagliano
Copy link

any news on this? experiencing the same issue using a slack webhook and a json payload in a template file

@filmaj
Copy link
Contributor

filmaj commented May 17, 2023

We fixed this in #200; assigning to the 1.24 milestone, which we will release shortly.

@filmaj filmaj modified the milestones: 1.x, 1.24 May 17, 2023
@filmaj
Copy link
Contributor

filmaj commented May 17, 2023

Release v1.24.0 is out!

@filmaj filmaj closed this as completed May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants