@@ -132,6 +132,39 @@ jobs:
132132 pattern : " ${{ inputs.component }}-v?[0-9]{1,2}\\ .[0-9]{1,3}\\ .[0-9]{1,3}$"
133133 starting-tag : " "
134134
135+ - name : Define Last built SHA
136+ id : define-sha
137+ run : |
138+ echo -e "${BLUE}[ STEP - DEFINE LAST BUILT SHA ] > Defining last SHA${BLANK}"
139+ if [[ "${{ inputs.component }}" == '' ]]
140+ then
141+ git log -n 1 -- ${{ inputs.workingdir }}
142+ SHA=$(git log -n 1 --pretty=format:"%H" -- ${{ inputs.workingdir }})
143+ LAST_TAG_SHA="sha-${GITHUB_SHA:0:7}"
144+ else
145+ git log -n 1 -- ${{ inputs.workingdir }}
146+ SHA=$(git log -n 1 --pretty=format:"%H" -- ${{ inputs.workingdir }})
147+ LAST_TAG_SHA="${{ inputs.component }}-sha-${SHA:0:7}"
148+ fi
149+ if [[ "${SHA}" != ${{ github.sha }} ]]
150+ then
151+ echo -e "${YELLOW}[ INFO ] > Last sha is different from current sha ${PURPLE}${LAST_SHA}${BLANK}"
152+ echo "LAST_SHA=${SHA}" >> "$GITHUB_OUTPUT"
153+ else
154+ echo -e "${YELLOW}[ INFO ] > Last sha is same as current sha, using github.ref_name${BLANK}"
155+ fi
156+ echo -e "${YELLOW}[ INFO ] > Last sha tag is ${PURPLE}${LAST_TAG_SHA}${BLANK}"
157+ echo "LAST_TAG_SHA=${LAST_TAG_SHA}" >> "$GITHUB_OUTPUT"
158+ shell : bash
159+ env :
160+ RED : \033[1;31m
161+ GREEN : \033[1;32m
162+ YELLOW : \033[1;33m
163+ BLUE : \033[1;34m
164+ PURPLE : \033[1;35m
165+ CYAN : \033[1;36m
166+ BLANK : \033[0m
167+
135168 - name : Skopeo retag [ Artefact promotion ]
136169 uses : ixxeL-DevOps/gha-templates/.github/actions/skopeo-retag@main
137170 id : skopeo-retag
@@ -140,7 +173,7 @@ jobs:
140173 registry-url : ${{ inputs.registry-url }}
141174 registry-username : ${{ inputs.registry-username }}
142175 registry-password : ${{ secrets.registry-password }}
143- src-img : ${{ inputs.cache-registry }}/${{ inputs.img-name }}:sha- ${{ github. sha }}
176+ src-img : ${{ inputs.cache-registry }}/${{ inputs.img-name }}:${{ steps.define- sha.outputs.LAST_TAG_SHA }}
144177 dst-img : ${{ inputs.cache-registry }}/${{ inputs.img-name }}:${{ steps.svu.outputs.NEW_TAG }}
145178
146179 - name : Crane retag [ Artefact promotion ]
@@ -151,15 +184,15 @@ jobs:
151184 registry-url : ${{ inputs.registry-url }}
152185 registry-username : ${{ inputs.registry-username }}
153186 registry-password : ${{ secrets.registry-password }}
154- src-img : ${{ inputs.cache-registry }}/${{ inputs.img-name }}:sha- ${{ github. sha }}
187+ src-img : ${{ inputs.cache-registry }}/${{ inputs.img-name }}:${{ steps.define- sha.outputs.LAST_TAG_SHA }}
155188 dst-tag : ${{ steps.svu.outputs.NEW_TAG }}
156189
157190 - name : Git tag
158191 id : git-tag
159192 uses : ixxeL-DevOps/gha-templates/.github/actions/git-tag@main
160193 with :
161194 tag-value : ${{ steps.svu.outputs.NEW_TAG }}
162- commit-sha : ${{ github.ref_name }}
195+ commit-sha : ${{ steps.define-sha.outputs.LAST_SHA || github.ref_name }}
163196 git-workdir : ${{ inputs.git-workdir }}
164197 force-tag : " false"
165198
0 commit comments