Why github.ref_name is empty? #64528
-
Select Topic AreaQuestion BodySuddenly my jobs started failing because The jobs are triggered when a new release is created. Here's the workflow code: https://github.com/tablelandnetwork/go-tableland/actions/runs/5927734903/workflow |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 5 replies
-
|
The github.ref_name context variable is only available when the workflow is triggered by a push event to a branch or tag. Since your workflow is triggered by a release creation event, the github.ref_name context variable will be empty. To get the tag name in this case, you can use the GITHUB_REF context variable. The GITHUB_REF variable contains the full ref that triggered the workflow, including the branch or tag name. For example, if the workflow is triggered by a release creation event for the tag v1.2.3, the GITHUB_REF variable will be set to refs/tags/v1.2.3. You can then use the GITHUB_REF variable to get the tag name by removing the refs/tags/ prefix. For example:
You can update your workflow to use the GITHUB_REF variable as follows: This workflow will now print the tag name when a new release is created. |
Beta Was this translation helpful? Give feedback.
-
|
I used |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
This has not happened to us in a while. Today, I had it happen again for a single workflow run. Our release pipeline passes
Hopefully this does not happen again, but wanted to throw out here in case others are having the same inconsistencies again. |
Beta Was this translation helpful? Give feedback.
-
|
What works for me more consitently for both branch: |
Beta Was this translation helpful? Give feedback.
-
|
We can see that this is still a popular discussion we want to add additional info as to why the github.ref may be empty so we can guide users to the correct documentation. Following @arafajs reply It's important to note that the behavior of
We recommend reviewing the GitHub Docs on default environment variables for a deeper understanding of variable behavior across different events. Acknowledging the users experiencing inconsistencies we have shared this feedback with our internal teams. |
Beta Was this translation helpful? Give feedback.
-
|
I also found |
Beta Was this translation helpful? Give feedback.
We can see that this is still a popular discussion we want to add additional info as to why the github.ref may be empty so we can guide users to the correct documentation.
Following @arafajs reply It's important to note that the behavior of
github.ref_namedepends on the event that triggers the workflow. For instance:pushevents,github.ref_namecorresponds to the branch or tag that was pushed.releaseevents, the release tag can be accessed viagithub.event.release.tag_name, whilegithub.ref_namemight not always provide the expected value.pull_request, the variable behaves differently, often pointing to the merge branch or base branch.We recommend re…