Skip to content

Commit

Permalink
Change: Use is-lastest-tag action in container build workflow
Browse files Browse the repository at this point in the history
This code has been generalized into an own action.
  • Loading branch information
bjoernricks authored and nichtsfrei committed Jul 10, 2023
1 parent 9abad60 commit 131b1c1
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,15 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: greenbone/actions/is-latest-tag@v2
id: latest
- name: 'set IS_VERSION_TAG'
run: |
echo "IS_VERSION_TAG=${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') }}" >> $GITHUB_ENV
# set defaults
echo "IS_LATEST_TAG=false" >> $GITHUB_ENV
- name: 'set IS_LATEST_TAG'
if: ( env.IS_VERSION_TAG )
run: |
# find the latest version that is not ourself
export LATEST_VERSION=$(git tag -l | grep -v '${{ github.ref_name }}' | sort -r --version-sort)
# get major minor patch versions
IFS='.' read -r latest_major latest_minor latest_patch << EOF
$LATEST_VERSION
EOF
IFS='.' read -r tag_major tag_minor tag_patch << EOF
${{ github.ref_name }}
EOF
# remove leading v
latest_major=$(echo $latest_major | cut -c2-)
tag_major=$(echo $tag_major | cut -c2-)
echo "$tag_major >= $latest_major"
if [[ $tag_major -ge $latest_major && ($tag_minor -ne 0 || $tag_patch -ne 0) ]]; then
# set this tag to latest and stable
echo "IS_LATEST_TAG=true" >> $GITHUB_ENV
fi
- name: 'Setup meta information (IS_VERSION_TAG: ${{ env.IS_VERSION_TAG }}, IS_LATEST_TAG: ${{ env.IS_LATEST_TAG }} )'
- name: 'Setup meta information (IS_VERSION_TAG: ${{ env.IS_VERSION_TAG }}, IS_LATEST_TAG: ${{ steps.latest.outputs.is-latest-tag }} )'
id: meta
uses: docker/metadata-action@v4
with:
Expand All @@ -51,8 +34,8 @@ jobs:
flavor: latest=false # no auto latest container tag for git tags
tags: |
# when IS_LATEST_TAG is set create a stable and a latest tag
type=raw,value=latest,enable=${{ env.IS_LATEST_TAG }}
type=raw,value=stable,enable=${{ env.IS_LATEST_TAG }}
type=raw,value=latest,enable=${{ steps.latest.outputs.is-latest-tag == 'true' }}
type=raw,value=stable,enable=${{ steps.latest.outputs.is-latest-tag == 'true' }}
# if tag version is set than create a version tags
type=semver,pattern={{version}},enable=${{ env.IS_VERSION_TAG }}
type=semver,pattern={{major}}.{{minor}},enable=${{ env.IS_VERSION_TAG }}
Expand Down

0 comments on commit 131b1c1

Please sign in to comment.