Skip to content

Commit

Permalink
gha: normalize tag creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
baracudda committed Apr 5, 2024
1 parent cc5ad8e commit 7f9a185
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
43 changes: 23 additions & 20 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,41 @@ jobs:
build_cfg:
runs-on: ubuntu-latest
environment: default
env:
REF_NAME: ${{ github.ref_name }}
outputs:
VERSION_STR: ${{ steps.config_step.outputs.VERSION_STR }}
ALT_TAGS: ${{ steps.config_step.outputs.ALT_TAGS }}
steps:
- name: "Determine Version"
id: config_step
run: |-
if [[ ${{ github.ref_name }} =~ ^(v)([[:digit:]]+\..*)$ ]]; then
VERSION_STR=${BASH_REMATCH[2]}
else
VER_BUILD=$(date +%H%M)
# limit to only first 3 chars
VER_BUILD=${VER_BUILD:0:3}
# 'strict' semver segments cannot start with 0
VERSION_NUM="$(date +%y).$(date +%-m).$(date +%-d).${VER_BUILD#0}"
# recreate as INT, leaving 0's in place; creates a 'reasonable' 32-bit signed int.
VERSION_INT="$(date +%y)$(date +%m)$(date +%d)${VER_BUILD}"
VERSION_STR=${VERSION_NUM}
fi
echo "VERSION_STR=${VERSION_STR}" >> $GITHUB_OUTPUT
#VER_KIND = 'alpha' (not deployed) | 'dev' | 'beta' | 'gold'
VER_KIND=alpha
VER_BUILD=$(date +%H%M)
# limit to only first 3 chars
VER_BUILD=${VER_BUILD:0:3}
# 'strict' semver segments cannot start with 0
VERSION_NUM="$(date +%y).$(date +%-m).$(date +%-d).${VER_BUILD#0}"
# recreate as INT, leaving 0's in place; creates a 'reasonable' 32-bit signed int.
VERSION_INT="$(date +%y)$(date +%m)$(date +%d)${VER_BUILD}"
VERSION_STR=${VERSION_NUM}
ALT_TAGS=""
if [[ "${{ github.ref_name }}" == "develop" ]]; then
ALT_TAGS+=",ci-develop"
REF_NAME="${{ github.ref_name }}"
if [[ ${REF_NAME} =~ ^(v)([[:digit:]]+\..*)$ ]]; then
VER_KIND=gold
VERSION_STR=${BASH_REMATCH[2]}
else
ALT_TAGS=",ci-dev-${REF_NAME#**/}"
ALT_TAGS=""
if [[ "${REF_NAME}" == "develop" ]]; then
ALT_TAGS+=",ci-develop"
else
ALT_TAGS=",ci-dev-${REF_NAME#**/}"
fi
fi
echo "VERSION_STR=${VERSION_STR}" >> $GITHUB_OUTPUT
echo "ALT_TAGS=${ALT_TAGS}" >> $GITHUB_OUTPUT
echo "::notice::Version STR=${VERSION_STR}"
echo "::notice::Version KIND=${VER_KIND}, STR=${VERSION_STR}${ALT_TAGS}, INT=${VERSION_INT}"
#endjob build_cfg

trigger-build:
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/tag-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
runs-on: ubuntu-latest
outputs:
VERSION_STR: ${{ steps.config_step.outputs.VERSION_STR }}
VERSION_INT: ${{ steps.config_step.outputs.VERSION_INT }}
ALT_TAGS: ${{ steps.config_step.outputs.ALT_TAGS }}
permissions:
contents: write
steps:
Expand All @@ -22,13 +24,15 @@ jobs:
VER_BUILD=${VER_BUILD:0:3}
# 'strict' semver segments cannot start with 0
VERSION_NUM="$(date +%y).$(date +%-m).$(date +%-d).${VER_BUILD#0}"
# recreate as INT, leaving 0's in place; creates a 'reasonable' 32-bit signed int.
VERSION_INT="$(date +%y)$(date +%m)$(date +%d)${VER_BUILD}"
echo "VERSION_INT=${VERSION_INT}" >> $GITHUB_OUTPUT
VERSION_STR=${VERSION_NUM}
ALT_TAGS=",ci-main"
echo "VERSION_STR=${VERSION_STR}" >> $GITHUB_OUTPUT
echo "::notice::Version STR=${VERSION_STR}"
echo "ALT_TAGS=${ALT_TAGS}" >> $GITHUB_OUTPUT
echo "::notice::Version STR=${VERSION_STR}${ALT_TAGS}"
- name: "Create Release"
uses: softprops/action-gh-release@v1
Expand Down Expand Up @@ -67,7 +71,7 @@ jobs:
"dockerfile": "Dockerfile",
"arch_allowed": "amd64",
"name": "${{ github.repository }}",
"tag": "${{ needs.build_cfg.outputs.VERSION_STR }}",
"tag": "${{ needs.build_cfg.outputs.VERSION_STR }}${{ needs.build_cfg.outputs.ALT_TAGS }}",
"build_args": [
]
},
Expand Down

0 comments on commit 7f9a185

Please sign in to comment.