Skip to content

Commit 182903d

Browse files
rgerganovRadoslav Gerganov
authored andcommitted
ci : create git tags for released docker images
When releasing a docker image for build number X, we should also create the corresponding git tag. This allows users to easily checkout the corresponding source tree for given docker image.
1 parent 28c39da commit 182903d

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

.github/workflows/docker.yml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,40 +67,36 @@ jobs:
6767
username: ${{ github.repository_owner }}
6868
password: ${{ secrets.GITHUB_TOKEN }}
6969

70-
- name: Determine tag name
70+
- name: Determine source tag name
71+
id: srctag
72+
uses: ./.github/actions/get-tag-name
73+
env:
74+
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
75+
76+
- name: Determine image tag name
7177
id: tag
7278
shell: bash
7379
run: |
74-
BUILD_NUMBER="$(git rev-list --count HEAD)"
75-
SHORT_HASH="$(git rev-parse --short=7 HEAD)"
7680
REPO_OWNER="${GITHUB_REPOSITORY_OWNER@L}" # to lower case
7781
REPO_NAME="${{ github.event.repository.name }}"
7882
79-
# determine tag name postfix (build number, commit hash)
80-
if [[ "${{ env.GITHUB_BRANCH_NAME }}" == "master" ]]; then
81-
TAG_POSTFIX="-b${BUILD_NUMBER}"
82-
else
83-
SAFE_NAME=$(echo "${{ env.GITHUB_BRANCH_NAME }}" | tr '/' '-')
84-
TAG_POSTFIX="-${SAFE_NAME}-${SHORT_HASH}"
85-
fi
8683
# list all tags possible
8784
if [[ "${{ matrix.config.tag }}" == "cpu" ]]; then
8885
TYPE=""
8986
else
9087
TYPE="-${{ matrix.config.tag }}"
9188
fi
9289
PREFIX="ghcr.io/${REPO_OWNER}/${REPO_NAME}:"
93-
FULLTAGS="${PREFIX}full${TYPE},${PREFIX}full${TYPE}${TAG_POSTFIX}"
94-
LIGHTTAGS="${PREFIX}light${TYPE},${PREFIX}light${TYPE}${TAG_POSTFIX}"
95-
SERVERTAGS="${PREFIX}server${TYPE},${PREFIX}server${TYPE}${TAG_POSTFIX}"
90+
FULLTAGS="${PREFIX}full${TYPE},${PREFIX}full${TYPE}${{ steps.srctag.outputs.name }}"
91+
LIGHTTAGS="${PREFIX}light${TYPE},${PREFIX}light${TYPE}${{ steps.srctag.outputs.name }}"
92+
SERVERTAGS="${PREFIX}server${TYPE},${PREFIX}server${TYPE}${{ steps.srctag.outputs.name }}"
9693
echo "full_output_tags=$FULLTAGS" >> $GITHUB_OUTPUT
9794
echo "light_output_tags=$LIGHTTAGS" >> $GITHUB_OUTPUT
9895
echo "server_output_tags=$SERVERTAGS" >> $GITHUB_OUTPUT
9996
echo "full_output_tags=$FULLTAGS" # print out for debugging
10097
echo "light_output_tags=$LIGHTTAGS" # print out for debugging
10198
echo "server_output_tags=$SERVERTAGS" # print out for debugging
10299
env:
103-
GITHUB_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
104100
GITHUB_REPOSITORY_OWNER: '${{ github.repository_owner }}'
105101

106102
- name: Free Disk Space (Ubuntu)
@@ -176,3 +172,10 @@ jobs:
176172
# return to this if the experimental github cache is having issues
177173
#cache-to: type=local,dest=/tmp/.buildx-cache
178174
#cache-from: type=local,src=/tmp/.buildx-cache
175+
176+
- name: Create and push source tag
177+
env:
178+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
179+
run: |
180+
git tag ${{ steps.srctag.outputs.name }} || exit 0
181+
git push origin ${{ steps.srctag.outputs.name }} || exit 0

0 commit comments

Comments
 (0)