3131 value : 5d
3232 - name : dockerfile
3333 value : Dockerfile
34+ - name : version
35+ value : " "
36+ - name : prefetch-input
37+ value : " "
3438 - name : path-context
3539 value : .
3640 pipelineSpec :
@@ -84,10 +88,10 @@ spec:
8488 description : Execute the build with network isolation
8589 name : hermetic
8690 type : string
87- - default : " "
88- description : Build dependencies to be prefetched by Cachi2
91+ - description : Build dependencies to be prefetched by Cachi2
8992 name : prefetch-input
9093 type : string
94+ default : " "
9195 - default : " "
9296 description : Image tag expiration time, time values could be something like 1h, 2d, 3w for hours, days, and weeks, respectively.
9397 name : image-expires-after
@@ -176,6 +180,65 @@ spec:
176180 workspaces :
177181 - name : basic-auth
178182 workspace : git-auth
183+ - name : get-version
184+ params :
185+ - name : url
186+ value : $(params.git-url)
187+ - name : revision
188+ value : $(params.revision)
189+ runAfter :
190+ - clone-repository
191+ taskSpec :
192+ description : Extract version from git repository by cloning it
193+ params :
194+ - name : url
195+ description : Git repository URL
196+ type : string
197+ - name : revision
198+ description : Git revision to checkout
199+ type : string
200+ results :
201+ - name : version
202+ description : Git version/tag
203+ workspaces :
204+ - name : basic-auth
205+ description : Workspace for git authentication credentials
206+ optional : true
207+ steps :
208+ - name : clone-and-get-version
209+ image : quay.io/konflux-ci/appstudio-utils:ab6b0b8e40e440158e7288c73aff1cf83a2cc8a9@sha256:24179f0efd06c65d16868c2d7eb82573cce8e43533de6cea14fec3b7446e0b14
210+ env :
211+ - name : GIT_URL
212+ value : $(params.url)
213+ - name : GIT_REVISION
214+ value : $(params.revision)
215+ script : |
216+ #!/usr/bin/env bash
217+ set -eo pipefail
218+
219+ # Create temporary directory
220+ WORKDIR=$(mktemp -d)
221+ cd "$WORKDIR"
222+
223+ # Clone repository with tags
224+ echo "Cloning repository..."
225+ # Use unshallow clone to get full history and tags for git describe
226+ git clone --no-single-branch "$GIT_URL" .
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+ echo "Computed version: $VERSION"
233+ printf "%s" "$VERSION" > $(results.version.path)
234+ when :
235+ - input : $(tasks.init.results.build)
236+ operator : in
237+ values :
238+ - " true"
239+ workspaces :
240+ - name : basic-auth
241+ workspace : git-auth
179242 - name : prefetch-dependencies
180243 params :
181244 - name : input
@@ -206,6 +269,10 @@ spec:
206269 params :
207270 - name : IMAGE
208271 value : $(params.output-image)
272+ - name : revision
273+ value : $(params.revision)
274+ - name : version
275+ value : $(tasks.get-version.results.version)
209276 - name : DOCKERFILE
210277 value : $(params.dockerfile)
211278 - name : CONTEXT
@@ -220,6 +287,8 @@ spec:
220287 value : $(tasks.clone-repository.results.commit)
221288 - name : BUILD_ARGS
222289 value :
290+ - revision=$(params.revision)
291+ - version=$(tasks.get-version.results.version)
223292 - $(params.build-args[*])
224293 - name : BUILD_ARGS_FILE
225294 value : $(params.build-args-file)
@@ -233,6 +302,7 @@ spec:
233302 value : $(params.buildah-format)
234303 runAfter :
235304 - prefetch-dependencies
305+ - get-version
236306 taskRef :
237307 params :
238308 - name : name
0 commit comments