3131 value : 5d
3232 - name : dockerfile
3333 value : Dockerfile
34+ - name : prefetch-input
35+ value : " "
3436 - name : path-context
3537 value : .
3638 pipelineSpec :
@@ -84,10 +86,10 @@ spec:
8486 description : Execute the build with network isolation
8587 name : hermetic
8688 type : string
87- - default : " "
88- description : Build dependencies to be prefetched by Cachi2
89+ - description : Build dependencies to be prefetched by Cachi2
8990 name : prefetch-input
9091 type : string
92+ default : " "
9193 - default : " "
9294 description : Image tag expiration time, time values could be something like 1h, 2d, 3w for hours, days, and weeks, respectively.
9395 name : image-expires-after
@@ -176,6 +178,65 @@ spec:
176178 workspaces :
177179 - name : basic-auth
178180 workspace : git-auth
181+ - name : get-version
182+ params :
183+ - name : url
184+ value : $(params.git-url)
185+ - name : revision
186+ value : $(params.revision)
187+ runAfter :
188+ - clone-repository
189+ taskSpec :
190+ description : Extract version from git repository by cloning it
191+ params :
192+ - name : url
193+ description : Git repository URL
194+ type : string
195+ - name : revision
196+ description : Git revision to checkout
197+ type : string
198+ results :
199+ - name : version
200+ description : Git version/tag
201+ steps :
202+ - name : clone-and-get-version
203+ image : quay.io/konflux-ci/appstudio-utils:ab6b0b8e40e440158e7288c73aff1cf83a2cc8a9@sha256:24179f0efd06c65d16868c2d7eb82573cce8e43533de6cea14fec3b7446e0b14
204+ env :
205+ - name : GIT_URL
206+ value : $(params.url)
207+ - name : GIT_REVISION
208+ value : $(params.revision)
209+ script : |
210+ #!/usr/bin/env bash
211+ set -eo pipefail
212+
213+ # Create temporary directory
214+ WORKDIR=$(mktemp -d)
215+ cd "$WORKDIR"
216+
217+ # Clone repository with tags
218+ echo "Cloning repository..."
219+ # Use unshallow clone to get full history and tags for git describe
220+ git clone --no-single-branch "$GIT_URL" .
221+
222+ # Checkout the specific revision
223+ git checkout "$GIT_REVISION"
224+
225+ # Fetch all tags explicitly
226+ git fetch origin --tags
227+
228+ # Get version using git describe (same logic as Makefile)
229+ # Try to get the closest tag, or use commit SHA as fallback
230+ VERSION=$(git describe --tags --always 2>/dev/null || echo "v0.0.0-SNAPSHOT")
231+
232+ printf "%s" "$VERSION" > $(results.version.path)
233+ echo "Version: $VERSION"
234+ echo "Commit ID: $GIT_REVISION"
235+ when :
236+ - input : $(tasks.init.results.build)
237+ operator : in
238+ values :
239+ - " true"
179240 - name : prefetch-dependencies
180241 params :
181242 - name : input
@@ -220,6 +281,8 @@ spec:
220281 value : $(tasks.clone-repository.results.commit)
221282 - name : BUILD_ARGS
222283 value :
284+ - COMMIT_ID=$(params.revision)
285+ - VERSION_ID=$(tasks.get-version.results.version)
223286 - $(params.build-args[*])
224287 - name : BUILD_ARGS_FILE
225288 value : $(params.build-args-file)
@@ -233,6 +296,7 @@ spec:
233296 value : $(params.buildah-format)
234297 runAfter :
235298 - prefetch-dependencies
299+ - get-version
236300 taskRef :
237301 params :
238302 - name : name
0 commit comments