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

values does not work on Slack App approach #171

Closed
5 of 10 tasks
DSdatsme opened this issue Jan 24, 2023 · 10 comments
Closed
5 of 10 tasks

values does not work on Slack App approach #171

DSdatsme opened this issue Jan 24, 2023 · 10 comments
Labels
question Further information is requested

Comments

@DSdatsme
Copy link

DSdatsme commented Jan 24, 2023

Description

The GitHub actions are giving an error for the values field when being used. I've copied the sample code from here
https://github.com/slackapi/slack-github-action/blob/main/example-workflows/Technique_2_Slack_App/JSON_payload.yml#L45-L47

I am using the OAuth approach (approach 2) of the slack bot to send notifications to slack.
Need to understand if I am missing something or if it's for another setup? because documentation does not mention anything about values field.

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 made 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

Reproducible in:

package version:
tested on

node version:

OS version(s): ubuntu-22.04 (github hosted runners)

Steps to reproduce:

  1. Copy the example code and run it

Expected result:

values field should work

Actual result:

getting error

Attachments:

Screenshot 2023-01-24 at 2 36 55 PM

Logs, screenshots, screencast, sample project, funny gif, etc.

@mwbrooks mwbrooks added the question Further information is requested label Jan 24, 2023
@mwbrooks
Copy link
Member

Hi @DSdatsme 👋🏻 Thanks for reaching out!

I don't see an immediately problem after looking over your code sample and I see you've already tried slackapi/[email protected].

I'm going to setup an example to recreate your problem and I'll get back to you shortly! Thanks for your patience 🙇🏻

@mwbrooks
Copy link
Member

Hi @DSdatsme 👋🏻 🌙

I've setup an example repository that uses the Slack GitHub Action in 2 ways:

  1. Send a message as a string
  2. Send a message as JSON payload

I can confirm that I was able to re-create your error with JSON Payload example.

I solved the problem by removing the values: | property and instead referencing the values using the GitHub Context syntax (${{ <context> }}):

Example: .github/workflows/slack-message-json.yml#L34-L36:

  "text": "${{ github.sha }}"
},
"url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"

I believe the examples are slightly out-of-date. They should not use the values: property and instead they should use the new ${{ github }} context syntax. I'll try to update those examples for us.

I'd recommend that you look at the examples in the README.md for Technique 2. They appear to be accurate and should unblock you.

Let me know how it goes!

@DSdatsme
Copy link
Author

Heya @mwbrooks ,
Thanks for the quick response on the issue.

My goal for using values block was to pass on GitHub workflow inputs (workflow parameters) to slack message.
something like {{ inputs.UserInput1 }}.
Currently, this action only supports github context, I thought values would be a good way to pass on other variables which are outside of github context.

@DSdatsme
Copy link
Author

Or maybe I'll have to wait for env context implementation(PR 159) which looks like blocked due to test cases.
As a temporary workaround, I've forked this repo and implemented the env context and started using it for my actions.

Will have to wait until either values or env context feature is released, and any other better workaround you could suggest.

@mwbrooks
Copy link
Member

Hey @DSdatsme, thanks for the response and background on why you wanted to use values.

Please checkout the Contexts documentation because GitHub Workflow inputs are also available: ${{ inputs }} and ${{ inputs. }}`

Let me know if that helps! It would be ideal if you can use this repo instead of maintaining your own fork 😄

@DSdatsme
Copy link
Author

Hey @mwbrooks ,
Currently, this slack action does not support inputs context.
Also, a lot of github context variables do not work when I used them in payload json. I am unsure whether it's an issue with reading the file or I am missing out something.

I've created a PR to your example repo to explain this with an example.
github.actor works whereas github.repository or github.run_id does not seem to work.

This is the payload template that I used

{
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \n GH actor: ${{ github.actor }},,,,,, GH Input: ${{ inputs.branch }}"
            }
        }

This is what I got as a slack message:
Screenshot 2023-01-30 at 11 53 52 AM

Unsure if you want to track it as a separate 2 issues or continue here.

  1. not all github context variables are working.
  2. support for inputs and other contexts.

@zimeg
Copy link
Member

zimeg commented Apr 4, 2024

@DSdatsme the issue around missing github context variables for payload-file-path are being tracked in #203!

@DSdatsme
Copy link
Author

DSdatsme commented Apr 5, 2024

Hey @zimeg , yes it's missing some context variables.
Thanks for mentioning the issue, I see other folks have also faced the same issue.

As I mentioned above, as a workaround, I am using this patched version for myself.
main...DSdatsme:slack-github-action:main

@zimeg
Copy link
Member

zimeg commented Nov 16, 2024

👋 Hello again! Refreshing myself on this issue, I noticed that #159 was moved to #200 and was included in the v1.24.0 release!

It's super neat to see you've been supporting this fix in the meantime! ❤️

I'll close this issue now that support is available in both places, and also wanted to share that @v2.0.0 was released and continues to support this, albeit with multiple changes to inputs 🔍

Please feel free to follow up with additional ideas on inputs or other questions! And to share a few more resources about expected inputs...

  1. not all github context variables are working.

This is unfortunately expected when using payload-file-path with payload-templated set to true. We've improved documentation for this case, and the expected values are available as the default GitHub event contexts.

  1. support for inputs and other contexts.

I'm interested in hearing more about this! Please feel free to open a new issue if you're still finding the current features aren't supporting your workflows. I'm not so familiar with values without references and am hoping env might be sufficient, but please let me know 🙏

@zimeg zimeg closed this as completed Nov 16, 2024
@DSdatsme
Copy link
Author

Thanks for the update @zimeg . For now, I think the env context is enough.
I'll open a new issue if I find strong reasons for values.

Just for a reference on values field:
The reason why values maybe useful for folks is that, it provides a way to pass on custom variables to the slack message template json.

For example:
If I want to send a URL to a template that I want to customize using existing variables like:

with:
   values:
       my_button: "URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"

Instead of building URL string templates in JSON, we could just pass the ${{ my_button }} variable to the message template.

This method would enable users to pass on dynamic variables like md5 hash, of a value instead of storing them in github contexts as env, or any other context type(which becomes available at the job level, that some folks may want to avoid).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants