How to fetch tag message in github actions

I want to capture the github tag message in Github Actions.

If user pushes tag with some message e.g.

git tag -a 1.0.0 -m "Test Message"

than, I would like to capture that message(“Test Message”) inside the github actions.

Any help or reference is much appreciated.

For a one-line message you can use:

git tag -l --format='%(contents:subject)' 1.0.0

With a multiline message this will give you just the title line. For more formatting options check the formatting options described here:

Thank you for the reply.
I found the issue. It was related to the git version which we were using on self-hosted runner. When I verified the CHECKOUT log, I found that because of the older version, github actions was downloading the repo using Rest API instead of cloning it.

  git version 2.17.1
Deleting the contents of <YOUR REPO>
**The repository will be downloaded using the GitHub REST API**
To create a local Git repository instead, add Git 2.18 or higher to the PATH
Downloading the archive
Writing archive to disk
Extracting the archive

Therefore, my actions was not able to the run the git command. I have upgraded the version and it fixed the issue.

1 Like

Sorry, I commented too early that solution worked. Following command works fine on my local. However, on build machine it doesn’t:

git tag -l --format='%(contents:subject)' 1.0.0

it returns git commit message instead of git tag message “Test Message”.

That’s odd… I wonder if the behavior is different between Git versions, intentionally or due to a bug?

So, I tried to increasing the fetch-depth as well by setting it up as 0 at checkout step. But that didn’t help even. However, I have used the following command before the command that you helped me with and it worked. :slight_smile:

git fetch --depth=1 origin +refs/tags/:refs/tags/

So, final solution is :

git fetch --depth=1 origin +refs/tags/*:refs/tags/*
git tag -l --format='%(contents:subject)' 1.0.0
1 Like