@@ -16,24 +16,47 @@ jobs:
16
16
# Allow list of models
17
17
include :
18
18
- backend_dir_name : segment_anything_model
19
- backend_tag_name : sam-v0
19
+ backend_tag_prefix : sam-
20
20
- backend_dir_name : llm_interactive
21
- backend_tag_name : llm-v8
21
+ backend_tag_prefix : llm-
22
22
- backend_dir_name : the_simplest_backend
23
- backend_tag_name : simplebackend-v0
23
+ backend_tag_prefix : simplebackend-
24
24
env :
25
25
IMAGE_NAME : heartexlabs/label-studio-ml-backend
26
26
examples_dir : label_studio_ml/examples
27
27
backend_dir_name : ${{ matrix.backend_dir_name }}
28
- backend_tag_name : ${{ matrix.backend_tag_name }}
28
+ backend_tag_prefix : ${{ matrix.backend_tag_prefix }}
29
29
steps :
30
30
- uses : actions/checkout@v4
31
31
with :
32
32
ref : " ${{ env.GITHUB_SHA }}"
33
33
fetch-depth : 0
34
34
35
- - name : Set up Docker Buildx
36
-
35
+ - name : Calculate version
36
+ id : version
37
+ env :
38
+ BRANCH_NAME : " ${{ github.event.pull_request.head.ref || github.ref_name }}"
39
+ PREFIX : " ${{ env.backend_tag_prefix }}"
40
+ run : |
41
+ set -xueo pipefail
42
+ MAX_TAG_LENGTH=50
43
+ pretty_branch_name="$(echo -n "${BRANCH_NAME#refs/heads/}" | sed 's#/#-#g' | sed 's#_#-#g'| sed 's#\.#-#g' | tr '[:upper:]' '[:lower:]')"
44
+ echo "pretty_branch_name=$pretty_branch_name" >> $GITHUB_OUTPUT
45
+ timestamp="$(date +'%Y%m%d.%H%M%S')"
46
+ echo "timestamp=$timestamp" >> $GITHUB_OUTPUT
47
+ short_sha="$(git rev-parse --short HEAD)"
48
+ echo "short_sha=$short_sha" >> $GITHUB_OUTPUT
49
+ long_sha="$(git rev-parse HEAD)"
50
+ echo "sha=$long_sha" >> $GITHUB_OUTPUT
51
+ short_sha_length="$(echo $short_sha | awk '{print length}')"
52
+ timestamp_length="$(echo $timestamp | awk '{print length}')"
53
+ prefix_length="$(echo $PREFIX | awk '{print length}')"
54
+ short_branch="$(echo $pretty_branch_name | cut -c1-$((MAX_TAG_LENGTH - 2 - short_sha_length - timestamp_length - prefix_length)))"
55
+ echo "short_branch=$short_branch" >> $GITHUB_OUTPUT
56
+ image_version="${PREFIX}${timestamp}-${short_branch}-${short_sha}"
57
+ echo "image_version=$image_version" >> $GITHUB_OUTPUT
58
+ image_branch_version="${PREFIX}${short_branch}"
59
+ echo "image_branch_version=$image_branch_version" >> $GITHUB_OUTPUT
37
60
38
61
- name : Check for Changes in Directory
39
62
id : check_changes
@@ -48,20 +71,43 @@ jobs:
48
71
echo "skip=false" >> $GITHUB_OUTPUT
49
72
fi
50
73
74
+ - name : Set up Docker Buildx
75
+
76
+
51
77
- name : Login to DockerHub
52
78
if : ${{ steps.check_changes.outputs.skip != 'true' && !github.event.pull_request.head.repo.fork }}
53
79
54
80
with :
55
81
username : ${{ vars.DOCKERHUB_USERNAME }}
56
82
password : ${{ secrets.DOCKERHUB_TOKEN }}
57
83
84
+ - name : Calculate Docker tags
85
+ id : calculate-docker-tags
86
+ uses : actions/github-script@v7
87
+ env :
88
+ IMAGE_NAME : " ${{ env.IMAGE_NAME }}"
89
+ TAGS : " ${{ steps.version.outpust.image_version }},${{ steps.version.outpust.image_branch_version }}"
90
+ with :
91
+ script : |
92
+ const raw_tags_input = process.env.TAGS;
93
+ const image_name = process.env.IMAGE_NAME;
94
+
95
+ const tags = raw_tags_input
96
+ .split(',')
97
+ .map(x => x.trim())
98
+ .map(x => `${image_name}:${x}`)
99
+ .join(',');
100
+ console.log(tags);
101
+ core.setOutput("tags", tags);
102
+
103
+
58
104
- name : Push Docker image
59
105
if : steps.check_changes.outputs.skip != 'true'
60
106
61
107
id : docker_build_and_push
62
108
with :
63
- context : ${{ env.examples_dir }}/${{ env.backend_dir_name }}
109
+ context : " ${{ env.examples_dir }}/${{ env.backend_dir_name }}"
64
110
push : true
65
- tags : ${{ env.IMAGE_NAME }}:${{ env.backend_tag_name }}
111
+ tags : " ${{ steps.calculate-docker-tags.outputs.tags }}"
66
112
cache-from : type=gha
67
113
cache-to : type=gha,mode=max
0 commit comments