Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the current pushed tag in Github Actions

Is there a way to access the current tag that has been pushed in a Github Action? In CircleCI you can access this value with the $CIRCLE_TAG variable.

My Workflow yaml is being triggered by a tag like so:

on:   push:     tags:       - 'v*.*.*' 

And I want to use that version number as a file path later on in the workflow.

like image 975
Jon B Avatar asked Oct 01 '19 03:10

Jon B


People also ask

How do I get latest tags in GitHub Actions?

github action sets the git tag as an env var. run install & build. use chrislennon/action-aws-cli action to install aws cli using secrets for keys. run command to sync the build to a new S3 bucket using the tag env var as the dir name.

What are tags in GitHub Actions?

Introduction. In this post we will be creating a new Github Action to automatically tag commits when a pull request is merged. Git tags are specific points in a repository's history marked as being important, typically used to identify release versions.

How do I find my actions quota in GitHub?

Anyone can view GitHub Actions usage for their own personal account. In the upper-right corner of any page, click your profile photo, then click Settings. In the "Access" section of the sidebar, click Billing and plans. Under "GitHub Actions", view details of your minutes used.


1 Answers

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 }} 
like image 100
peterevans Avatar answered Sep 22 '22 08:09

peterevans