GitHub define GITHUB_REF_NAME as default environment variable
rlespinasse opened this issue ยท 7 comments
Describe the bug
GitHub releases a new environment variable: GITHUB_REF_NAME
.
Since this action also uses GITHUB_REF_NAME
name.
The GitHub version cannot be overwritten by this action, and the export is silently discarded.
The action version doesn't fill this variable the same way GitHub does.
And the current content doesn't match the content produced by this action (before the GitHub release) on pull request event.
On GitHub-side, GITHUB_REF_NAME
is GITHUB_REF
without the refs
prefix.
- pull-request event
GITHUB_REF
= refs/pull/42/merge - GitHub version of
GITHUB_REF_NAME
= 42/merge - Action version of
GITHUB_REF_NAME
= <Name of the head branch of PR 42>
To Reproduce
Use this action on a pull request-based workflow.
Expected behavior
GITHUB_REF_NAME
contains the branch behind the Pull request.
Since GitHub default environment variables cannot be overwritten, the GITHUB_REF_NAME
(of this action) will never be able to work as intended anymore.
This impacts the v3, and v4 series.
In order to fix that in the current series, we need to choose a new name for the GITHUB_REF_NAME
from this action.
I kind of mix between
- declaring it as a breaking change (and creating a v5 series)
- consider it a bug we can't fix and need to live with (and add a new feature to support the need behind the
GITHUB_REF_NAME
from this action)
In addition, if the current GITHUB_REF_NAME
from this action doesn't have existed prior to the GitHub version, this action would have exposed GITHUB_REF_NAME
and slug variables like others.
Another possibility would be to quit the GITHUB_
prefix which is not reserved anymore as stated by this note but the result is the same if GitHub starts using another GITHUB_
environment variable used in this action, we will have possibly the same kind of issue again.
This action uses GITHUB_
prefix in order to stay close to the associated GITHUB_
environment variable when the slugs ones are created
GITHUB_REF
GITHUB_REF_SLUG
GITHUB_REF_SLUG_URL
Instead of (for example)
GITHUB_REF
CI_REF_SLUG
CI_REF_SLUG_URL
But we will still need to choose a new name to avoid confusion between GITHUB_REF_NAME
and CI_REF_NAME
which ends the same way but have different behaviors in opposition of GITHUB_REF
and CI_REF
for example.
After some tests, when you define a new environment variable, the env
context and the shell environment variables contain the new variable with the same content.
steps:
- name: create NEW_ENVIRONMENT_VARIABLE using shell
run: echo "NEW_ENVIRONMENT_VARIABLE=SOME_VALUE" >>$GITHUB_ENV
shell: bash
- name: Echo from 'env.NEW_ENVIRONMENT_VARIABLE' will print 'SOME_VALUE'
run: echo "${{ env.NEW_ENVIRONMENT_VARIABLE }}"
shell: bash
- name: Echo from '$NEW_ENVIRONMENT_VARIABLE' will print 'SOME_VALUE'
run: echo "${NEW_ENVIRONMENT_VARIABLE}"
shell: bash
But the default environment variables are not available in the env
context, only in the shell environment variables
steps:
- name: Echo from 'env.GITHUB_REF_NAME' will print nothing
run: echo "${{ env.GITHUB_REF_NAME }}"
shell: bash
- name: Echo from '$GITHUB_REF_NAME' will print the branch or tag name
run: echo "${GITHUB_REF_NAME}"
shell: bash
When you used the rlespinasse/github-slug-action@v4
, the action basically does something like
steps:
- name: create GITHUB_REF_NAME using shell
run: echo "GITHUB_REF_NAME=SOME_VALUE" >>$GITHUB_ENV
shell: bash
But since a default environment variable cannot be overwritten, the shell environment variables remain unchanged, which is not the case in the env
context.
steps:
- name: create GITHUB_REF_NAME using shell
run: echo "GITHUB_REF_NAME=SOME_VALUE" >>$GITHUB_ENV
shell: bash
- name: Echo from 'env.GITHUB_REF_NAME' will print 'SOME_VALUE'
run: echo "${{ env.GITHUB_REF_NAME }}"
shell: bash
- name: Echo from '$GITHUB_REF_NAME' will print the branch or tag name
run: echo "${GITHUB_REF_NAME}"
shell: bash
Since the GITHUB_REF_NAME
variable GitHub behavior does not map exactly this action behavior, the variable content differs depending on which method you used to access it, but only on Pull Request-related events.
The v3 and the v4 aren't impacted in the same way.
- v3 is impacted only by the presence of GITHUB_REF_NAME as the default variable. (a.k.a
${{ env.GITHUB_REF_NAME }} != ${GITHUB_REF_NAME}
) and expose the slug variables as intended initially (based on${{ env.GITHUB_REF_NAME }}
) - v4 exposes the slug variables based on
${GITHUB_REF_NAME}
and doesn't work as intended due to another bug. Without this bug, v4 would act in the same way as v3.
To "fix" it, I choose to document this behavior in v3 and v4
- in the
GITHUB_REF_NAME
section - in the troubleshooting section
And I will also fix the bug in v4 to have the same v3 behavior.
In the near future, env.GITHUB_REF_NAME
behavior will move to another named variable
- v3
- will not have this new variable
- will mark
env.GITHUB_REF_NAME
as deprecated
- v4
- will have this new variable
- will mark
env.GITHUB_REF_NAME
as deprecated in profit to the new variable
- the next v5
- will have this new variable
env.GITHUB_REF_NAME
will behave in the same way as$GITHUB_REF_NAME
(like any other default variables used in this action)
This could have been detected much sooner with #77 ๐
๐ This issue has been resolved in version 4.2.4 ๐
The release is available on GitHub release
Your semantic-release bot ๐ฆ๐