Reputation: 13
I need to automatically capture the latest tag whenever I push changes to my private repository on the 'develop' branch and store it in a variable. How can I achieve this?
I attempted to use these commands to retrieve the tag, but I did not succeed using this approach.
name: get-tag-version
on:
push:
branches:
- develop
jobs:
get-tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: "0"
- name: catch tag
run: tags=$(git describe --tags --all)
- name: show tag
run: echo "$tag"
the cli returns this:
`Run echo "$tag"
echo "$tag"
shell: /usr/bin/bash -e {0}`
[SOLVED]
I managed to get the tag using these commands.
describe-tags:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Describe Tags
run: |
git fetch --prune --unshallow
latest_tag=$(git describe --tags --abbrev=0 HEAD~)
echo "Latest Tag: $latest_tag"
Thanks!
Upvotes: 1
Views: 1423
Reputation: 394
I believe variables are not shared between subsequent run steps, you'd have to you step outputs for that.
You can run multiple commands in one step:
run: |
tags=$(git describe --tags --all)
echo "$tags"
For stuff like this I highly recommend getting your desired behavior to work locally for quicker testing and easier debugging.
Upvotes: 1