@@ -124,12 +124,15 @@ build-web:
124124 FROM +code-generator
125125 ARG WORKDIR= /frontend/apps/voices
126126 ARG UPLOAD_DEBUG_SYMBOLS= false
127+ ARG tag= 'latest'
128+
129+ DO +PARSE_BUILD_ARGS --tag = $tag
127130
128131 DO flutter-ci+BUILD_WEB \
129132 --WORKDIR = $WORKDIR \
130133 --BUILD_MODE = '--release' \
131- --BUILD_NAME = '0.1.0' \
132- --BUILD_NUMBER = $(date +%s ) \
134+ --BUILD_NAME = $(cat build_name) \
135+ --BUILD_NUMBER = $(cat build_number ) \
133136 --TARGET = lib/configs/main_web.dart \
134137 --UPLOAD_DEBUG_SYMBOLS = $UPLOAD_DEBUG_SYMBOLS \
135138 --SENTRY_ORG = 'iohk-j4' \
@@ -158,3 +161,48 @@ docker:
158161 ARG tag= "latest"
159162
160163 SAVE IMAGE ${container }:${tag }
164+
165+ # This function centralizes logic behind parsing tag into build_name and build_number.
166+ #
167+ # Defaults:
168+ # - build_name -> 0.1.0
169+ # - build_number -> timestamp
170+ #
171+ # It follows conditions:
172+ # - if tag has prefix <project>/vx.x.x but prefix is different then voices, uses defaults.
173+ # - extracts build_name out of vx.x.x, for v0.0.1 it will be 0.0.1
174+ # - extracts build_number from part after "+". eg v0.0.1+10 will result with 10
175+ # - if allow_build_name_suffix is true, looks for suffixes after build_number and appends to name
176+ #
177+ # Saves build_name and build_number inside respective files.
178+ PARSE_BUILD_ARGS :
179+ FUNCTION
180+ ARG tag= 'latest'
181+ ARG allow_build_name_suffix= true
182+
183+ RUN bash -c '\
184+ set -e; \
185+
186+ _build_name=""
187+ _build_number=""
188+
189+ if echo "$tag" | grep -q "/" && ! echo "$tag" | grep -q "^voices/"; then
190+ echo "Invalid prefix found in tag ' \' '$tag' \' '. Using default values."
191+ else
192+ _build_name=$(echo "$tag" | sed -n "s|.*v\( [0-9]\+\. [0-9]\+\. [0-9]\+\) .*|\1 |p"); \
193+
194+ if echo "$tag" | grep -q "+"; then \
195+ _build_number=$(echo "$tag" | cut -d"+" -f2 | cut -d"-" -f1); \
196+ fi; \
197+
198+ if [ "$allow_build_name_suffix" = "true" ]; then
199+ _suffix=$(echo "$tag" | sed -n "s/.*\( -\S\+\) /\1 /p");
200+ _build_name="${_build_name}${_suffix}";
201+ fi; \
202+ fi
203+
204+ FINAL_BUILD_NAME=${_build_name:-"0.1.0"}; \
205+ FINAL_BUILD_NUMBER=${_build_number:-$(date +%s)}; \
206+ echo -n "$FINAL_BUILD_NAME" > build_name; \
207+ echo -n "$FINAL_BUILD_NUMBER" > build_number; \
208+ '
0 commit comments