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

Note that environment variables must be passed in ${{ env.MY_VAR }} format #5

Merged
merged 2 commits into from
Jan 7, 2025

Conversation

bradymholt
Copy link
Member

@bradymholt bradymholt commented Jan 7, 2025

Note that environment variables must be passed in ${{ env.MY_VAR }} format in the README. We'd like to support $MY_VAR format as well but will circle back for that.

@bradymholt bradymholt changed the title Note that environment variables must be passed in ${{ env.MY_VAR }} format Note that environment variables must be passed in ${{ env.MY_VAR }} format Jan 7, 2025
@bradymholt bradymholt requested a review from dbertram January 7, 2025 16:30
@dbertram
Copy link
Member

dbertram commented Jan 7, 2025

I found some additional info on the $ENV_VAR vs ${{ env.ENV_VAR }} syntax here: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#using-contexts-to-access-environment-variable-values

You can access env variable values using runner environment variables or using contexts.

So the $ENV_VAR is a "runner environment variable" and are expected to work in run steps and are processed by the shell you are using on the runner (i.e., bash in our case).

The ${{ env.ENV_VAR }} is using the "env context", which sounds like the generally more "works everywhere" way of doing it:

The instructions in the other parts of a workflow are processed by GitHub Actions and are not sent to the runner. You can use either runner environment variables or contexts in run steps, but in the parts of a workflow that are not sent to the runner you must use contexts to access variable values.

...so I'm not entirely sure how this worked before, other than previously the slack-post-message-action code was using double strings and the bash shell, so perhaps that's why the "runner environment variable" syntax was working?

I ended up changing slack-post-message-action to use bash ansi C quoting so that callers could include things like single quotes, but presumably that also meant the $ENV_VAR syntax stopped being interpolated.

README.md Outdated Show resolved Hide resolved
Co-authored-by: Dane Bertram <dane@ynab.com>
@bradymholt bradymholt merged commit 488233d into main Jan 7, 2025
1 check passed
@bradymholt bradymholt deleted the env-var-format branch January 7, 2025 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants