Skip to content

Commit 131b1c1

Browse files
bjoernricksnichtsfrei
authored andcommitted
Change: Use is-lastest-tag action in container build workflow
This code has been generalized into an own action.
1 parent 9abad60 commit 131b1c1

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

.github/workflows/container.yml

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,15 @@ jobs:
1515
steps:
1616
- name: Checkout repository
1717
uses: actions/checkout@v3
18+
- uses: greenbone/actions/is-latest-tag@v2
19+
id: latest
1820
- name: 'set IS_VERSION_TAG'
1921
run: |
2022
echo "IS_VERSION_TAG=${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') }}" >> $GITHUB_ENV
2123
# set defaults
2224
echo "IS_LATEST_TAG=false" >> $GITHUB_ENV
23-
- name: 'set IS_LATEST_TAG'
24-
if: ( env.IS_VERSION_TAG )
25-
run: |
26-
# find the latest version that is not ourself
27-
export LATEST_VERSION=$(git tag -l | grep -v '${{ github.ref_name }}' | sort -r --version-sort)
28-
# get major minor patch versions
29-
IFS='.' read -r latest_major latest_minor latest_patch << EOF
30-
$LATEST_VERSION
31-
EOF
32-
IFS='.' read -r tag_major tag_minor tag_patch << EOF
33-
${{ github.ref_name }}
34-
EOF
35-
# remove leading v
36-
latest_major=$(echo $latest_major | cut -c2-)
37-
tag_major=$(echo $tag_major | cut -c2-)
38-
echo "$tag_major >= $latest_major"
39-
if [[ $tag_major -ge $latest_major && ($tag_minor -ne 0 || $tag_patch -ne 0) ]]; then
40-
# set this tag to latest and stable
41-
echo "IS_LATEST_TAG=true" >> $GITHUB_ENV
4225
fi
43-
- name: 'Setup meta information (IS_VERSION_TAG: ${{ env.IS_VERSION_TAG }}, IS_LATEST_TAG: ${{ env.IS_LATEST_TAG }} )'
26+
- name: 'Setup meta information (IS_VERSION_TAG: ${{ env.IS_VERSION_TAG }}, IS_LATEST_TAG: ${{ steps.latest.outputs.is-latest-tag }} )'
4427
id: meta
4528
uses: docker/metadata-action@v4
4629
with:
@@ -51,8 +34,8 @@ jobs:
5134
flavor: latest=false # no auto latest container tag for git tags
5235
tags: |
5336
# when IS_LATEST_TAG is set create a stable and a latest tag
54-
type=raw,value=latest,enable=${{ env.IS_LATEST_TAG }}
55-
type=raw,value=stable,enable=${{ env.IS_LATEST_TAG }}
37+
type=raw,value=latest,enable=${{ steps.latest.outputs.is-latest-tag == 'true' }}
38+
type=raw,value=stable,enable=${{ steps.latest.outputs.is-latest-tag == 'true' }}
5639
# if tag version is set than create a version tags
5740
type=semver,pattern={{version}},enable=${{ env.IS_VERSION_TAG }}
5841
type=semver,pattern={{major}}.{{minor}},enable=${{ env.IS_VERSION_TAG }}

0 commit comments

Comments
 (0)