Skip to content

Commit

Permalink
Fix tag release workflow (#690)
Browse files Browse the repository at this point in the history
* Create tag only if increased

---------

Signed-off-by: constanca <[email protected]>
Co-authored-by: Andrew Gizas <[email protected]>
  • Loading branch information
constanca-m and gizas authored Apr 18, 2024
1 parent b8e04ba commit 374e966
Showing 1 changed file with 52 additions and 19 deletions.
71 changes: 52 additions & 19 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,55 @@ jobs:

steps:

- uses: actions/checkout@v4

- name: Get version number
shell: bash
run: |
VERSION=$(grep -oE '[0-9]+\.[0-9]+\.[0-9]+(\-[a-zA-Z]+[0-9]+)?' share/version.py)
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "::notice::ESF version is $VERSION."
- name: Create tag
uses: actions/github-script@v7
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/lambda-v' + ${{ env.VERSION }},
sha: context.sha
})
- uses: actions/checkout@v4

- name: Get version number
shell: bash
run: |
VERSION=$(grep -oE '[0-9]+\.[0-9]+\.[0-9]+(\-[a-zA-Z]+[0-9]+)?' share/version.py)
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "::notice::ESF version is $VERSION."
- name: Check if version increased
shell: bash
run: |
git fetch --tags
# We will list all tags sorted by the version after the prefix lambda-v.
# We retrieve only the first line - that is, the most recent version.
# After that, we remove the prefix to only get the version number.
old_version=$(git tag --list --sort=-version:refname "lambda-v*" | awk 'NR==1{print $1}' | awk -F"lambda-v" '{ print $NF }')
# We now need to compare the current version inside version.py.
IFS='.' read -a new_numbers <<< ${{ env.VERSION }}
IFS='.' read -a old_numbers <<< $old_version
CREATE_TAG=false # only create tag if version increased
for i in 0 1 2
do
if [[ ${new_numbers[i]} > ${old_numbers[i]} ]]
then
CREATE_TAG==true
break
elif [[ ${new_numbers[i]} < ${old_numbers[i]} ]]
then
break
fi
done
echo "CREATE_TAG=${CREATE_TAG}" >> $GITHUB_ENV
echo "::notice::Latest version is $old_version."
echo "::notice::Current version is ${{ env.VERSION }}."
echo "::notice::The result for creating tag is $CREATE_TAG."
- name: Create tag
if: env.CREATE_TAG == 'true' # run only in case CREATE_TAG is true
uses: actions/github-script@v7
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/lambda-v' + "${{ env.VERSION }}",
sha: context.sha
})

0 comments on commit 374e966

Please sign in to comment.