Upon creating a release in GitHub I trigger a GitHub action. In this action, I would like to get some data from the release, is this possible? For example, I would like to get the tag and then use this tag as the NuGet package version. Is there a way to get this data from the job?
GitHub action release tag
Asked Answered
You can use ${{ github.ref }}
or ${{ github.event.release.tag_name }}
Example:
name: Release
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: NameOfYourArtifact
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: TODO
draft: true
prerelease: false
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: NameOfYourArtifact.exe
asset_name: NameOfYourArtifact.exe
asset_content_type: application/octet-stream
This action is executed when a new tag is created with a name like v*.
To trigger the action:
git push origin v1.0.0
great example thanks. I see github.ref returns 'refs/tags/1.9.9' in my case, do I then apply regex to remove the 'ref/tags' part? –
Sarson
It depends, if you use it in
release_name
the refs/tags is trimmed automatically, if you want to use it in a custom step, you may want to extract it with regex. –
Fob Ah it's in ${{ github.event.release.tag_name }} –
Sarson
github.ref_name returns the branch name on my action.
© 2022 - 2025 — McMap. All rights reserved.