Get the current pushed tag in Github Actions
As far as I know there is no tag variable. However, it can be extracted from GITHUB_REF
which contains the checked out ref, e.g. refs/tags/v1.2.3
Try this workflow. It creates a new environment variable with the extracted version that you can use in later steps.
on:
push:
tags:
- 'v*.*.*'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Test
run: |
echo $RELEASE_VERSION
echo ${{ env.RELEASE_VERSION }}
Alternatively, use set-output
:
on:
push:
tags:
- 'v*.*.*'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set output
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Check output
env:
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
run: |
echo $RELEASE_VERSION
echo ${{ steps.vars.outputs.tag }}
What worked for me:
run: echo "GIT_TAG=`echo $(git describe --tags --abbrev=0)`" >> $GITHUB_ENV
GitHub Contexts provides github.ref_name
. You can use it like this: ${{github.ref_name}}
.
Here is an example of this use in the artifact file name, which may be similar to the file path use that you asked about:
- name: Create tag artifact
uses: actions/upload-artifact@v2
with:
name: ${{github.ref_name}}
path: Release