Skip to content

Commit 87f0344

Browse files
author
Raisa Varghese
committed
fix(RHTAP-5734): Display the commit id in the application version
- ldflags added for commit id - Makefile updated to have full commit id - Set the default value for image as <quay location>:<commit>/<latest> for mcp-server command Assisted-By: Cursor Signed-off-by: Raisa Varghese <[email protected]>
1 parent e16dac9 commit 87f0344

File tree

9 files changed

+91
-34
lines changed

9 files changed

+91
-34
lines changed

.goreleaser.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ builds:
1919
- amd64
2020
ldflags:
2121
- -X github.com/redhat-appstudio/tssc-cli/pkg/constants.Version={{.Version}}
22-
- -X github.com/redhat-appstudio/tssc-cli/pkg/constants.Commit={{.Commit}}
22+
- -X github.com/redhat-appstudio/tssc-cli/pkg/constants.CommitID={{.Commit}}

.tekton/tssc-cli-pull-request.yaml

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ spec:
3131
value: 5d
3232
- name: dockerfile
3333
value: Dockerfile
34-
- name: version
35-
value: ""
3634
- name: prefetch-input
3735
value: ""
3836
- name: path-context
@@ -200,10 +198,6 @@ spec:
200198
results:
201199
- name: version
202200
description: Git version/tag
203-
workspaces:
204-
- name: basic-auth
205-
description: Workspace for git authentication credentials
206-
optional: true
207201
steps:
208202
- name: clone-and-get-version
209203
image: quay.io/konflux-ci/appstudio-utils:ab6b0b8e40e440158e7288c73aff1cf83a2cc8a9@sha256:24179f0efd06c65d16868c2d7eb82573cce8e43533de6cea14fec3b7446e0b14
@@ -224,21 +218,25 @@ spec:
224218
echo "Cloning repository..."
225219
# Use unshallow clone to get full history and tags for git describe
226220
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
227227
228228
# Get version using git describe (same logic as Makefile)
229229
# Try to get the closest tag, or use commit SHA as fallback
230230
VERSION=$(git describe --tags --always 2>/dev/null || echo "v0.0.0-SNAPSHOT")
231231
232-
echo "Computed version: $VERSION"
233232
printf "%s" "$VERSION" > $(results.version.path)
233+
echo "Version: $VERSION"
234+
echo "Commit ID: $GIT_REVISION"
234235
when:
235236
- input: $(tasks.init.results.build)
236237
operator: in
237238
values:
238239
- "true"
239-
workspaces:
240-
- name: basic-auth
241-
workspace: git-auth
242240
- name: prefetch-dependencies
243241
params:
244242
- name: input
@@ -269,10 +267,6 @@ spec:
269267
params:
270268
- name: IMAGE
271269
value: $(params.output-image)
272-
- name: revision
273-
value: $(params.revision)
274-
- name: version
275-
value: $(tasks.get-version.results.version)
276270
- name: DOCKERFILE
277271
value: $(params.dockerfile)
278272
- name: CONTEXT
@@ -287,8 +281,8 @@ spec:
287281
value: $(tasks.clone-repository.results.commit)
288282
- name: BUILD_ARGS
289283
value:
290-
- revision=$(params.revision)
291-
- version=$(tasks.get-version.results.version)
284+
- COMMIT_ID=$(params.revision)
285+
- VERSION_ID=$(tasks.get-version.results.version)
292286
- $(params.build-args[*])
293287
- name: BUILD_ARGS_FILE
294288
value: $(params.build-args-file)

.tekton/tssc-cli-push.yaml

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ spec:
2828
value: quay.io/redhat-user-workloads/rhtap-shared-team-tenant/tssc-cli:{{revision}}
2929
- name: dockerfile
3030
value: Dockerfile
31-
- name: prefetch-input
32-
value: '{"type": "generic", "path": "."}'
3331
- name: path-context
3432
value: .
3533
pipelineSpec:
@@ -175,6 +173,65 @@ spec:
175173
workspaces:
176174
- name: basic-auth
177175
workspace: git-auth
176+
- name: get-version
177+
params:
178+
- name: url
179+
value: $(params.git-url)
180+
- name: revision
181+
value: $(params.revision)
182+
runAfter:
183+
- clone-repository
184+
taskSpec:
185+
description: Extract version from git repository by cloning it
186+
params:
187+
- name: url
188+
description: Git repository URL
189+
type: string
190+
- name: revision
191+
description: Git revision to checkout
192+
type: string
193+
results:
194+
- name: version
195+
description: Git version/tag
196+
steps:
197+
- name: clone-and-get-version
198+
image: quay.io/konflux-ci/appstudio-utils:ab6b0b8e40e440158e7288c73aff1cf83a2cc8a9@sha256:24179f0efd06c65d16868c2d7eb82573cce8e43533de6cea14fec3b7446e0b14
199+
env:
200+
- name: GIT_URL
201+
value: $(params.url)
202+
- name: GIT_REVISION
203+
value: $(params.revision)
204+
script: |
205+
#!/usr/bin/env bash
206+
set -eo pipefail
207+
208+
# Create temporary directory
209+
WORKDIR=$(mktemp -d)
210+
cd "$WORKDIR"
211+
212+
# Clone repository with tags
213+
echo "Cloning repository..."
214+
# Use unshallow clone to get full history and tags for git describe
215+
git clone --no-single-branch "$GIT_URL" .
216+
217+
# Checkout the specific revision
218+
git checkout "$GIT_REVISION"
219+
220+
# Fetch all tags explicitly
221+
git fetch origin --tags
222+
223+
# Get version using git describe (same logic as Makefile)
224+
# Try to get the closest tag, or use commit SHA as fallback
225+
VERSION=$(git describe --tags --always 2>/dev/null || echo "v0.0.0-SNAPSHOT")
226+
227+
printf "%s" "$VERSION" > $(results.version.path)
228+
echo "Version: $VERSION"
229+
echo "Commit ID: $GIT_REVISION"
230+
when:
231+
- input: $(tasks.init.results.build)
232+
operator: in
233+
values:
234+
- "true"
178235
- name: prefetch-dependencies
179236
params:
180237
- name: input
@@ -219,6 +276,8 @@ spec:
219276
value: $(tasks.clone-repository.results.commit)
220277
- name: BUILD_ARGS
221278
value:
279+
- COMMIT_ID=$(params.revision)
280+
- VERSION_ID=$(tasks.get-version.results.version)
222281
- $(params.build-args[*])
223282
- name: BUILD_ARGS_FILE
224283
value: $(params.build-args-file)

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
FROM registry.redhat.io/openshift4/ose-tools-rhel9@sha256:c1baccf320b0acaed693a07fd8df76758db0a38767ace30ccc79aed9ba8c4987 AS ose-tools
66
FROM registry.access.redhat.com/ubi9/go-toolset:9.7-1763038106 AS builder
77

8-
ARG revision
9-
ARG version
8+
ARG COMMIT_ID
9+
ARG VERSION_ID
1010

1111
USER root
1212
WORKDIR /workdir/tssc
@@ -25,7 +25,7 @@ COPY go.mod go.sum Makefile .goreleaser.yaml ./
2525
RUN tar -xvf ./image/gh_2.81.0_linux_amd64.tar.gz -C ./image
2626

2727
RUN make test
28-
RUN make GOFLAGS='-buildvcs=false' COMMIT=${revision} VERSION=${version}
28+
RUN make GOFLAGS='-buildvcs=false' COMMIT_ID=${COMMIT_ID} VERSION=${VERSION_ID}
2929

3030
#
3131
# Run

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ VERSION ?= $(shell \
5757
fi)
5858

5959
# Commit will be set at build time via git commit hash
60-
COMMIT ?= $(shell git rev-parse --short HEAD)
60+
COMMIT_ID ?= $(shell git rev-parse HEAD)
6161

6262
.EXPORT_ALL_VARIABLES:
6363

@@ -73,7 +73,7 @@ $(BIN): installer-tarball
7373
$(BIN):
7474
@echo "# Building '$(BIN)'"
7575
@[ -d $(BIN_DIR) ] || mkdir -p $(BIN_DIR)
76-
go build -ldflags "-X github.com/redhat-appstudio/tssc-cli/pkg/constants.Version=$(VERSION) -X github.com/redhat-appstudio/tssc-cli/pkg/constants.Commit=$(COMMIT)" -o $(BIN) $(CMD)
76+
go build -ldflags "-X github.com/redhat-appstudio/tssc-cli/pkg/constants.Version=$(VERSION) -X github.com/redhat-appstudio/tssc-cli/pkg/constants.CommitID=$(COMMIT_ID)" -o $(BIN) $(CMD)
7777

7878
.PHONY: build
7979
build: $(BIN)

go.sum

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,4 +587,4 @@ sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxO
587587
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 h1:jTijUJbW353oVOd9oTlifJqOGEkUw2jB/fXCbTiQEco=
588588
sigs.k8s.io/structured-merge-diff/v6 v6.3.0/go.mod h1:M3W8sfWvn2HhQDIbGWj3S099YozAsymCo/wrT5ohRUE=
589589
sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs=
590-
sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4=
590+
sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4=

pkg/constants/constants.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ var (
2020

2121
// Version is the application version, set at build time via ldflags.
2222
var Version = "v0.0.0-SNAPSHOT"
23-
var Commit = "unknown"
23+
24+
// CommitID is the commit ID of the application, set at build time via git commit hash.
25+
var CommitID = ""

pkg/flags/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (f *Flags) LoggerWith(l *slog.Logger) *slog.Logger {
6666

6767
// ShowVersion shows the application version and exits
6868
func (f *Flags) ShowVersion() {
69-
fmt.Printf("%s Version: %s\nCommit: %s\n", constants.AppName, constants.Version, constants.Commit)
69+
fmt.Printf("%s Version: %s\nCommit: %s\n", constants.AppName, constants.Version, constants.CommitID)
7070
}
7171

7272
// NewFlags instantiates the global flags with default values.

pkg/subcmd/mcpserver.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,7 @@ Starts the MCP server for the TSSC installer, using STDIO communication.
3939
// PersistentFlags adds flags to the command.
4040
func (m *MCPServer) PersistentFlags(cmd *cobra.Command) {
4141
p := cmd.PersistentFlags()
42-
var defaultImage string
43-
if constants.Commit == "unknown" || constants.Commit == "" {
44-
defaultImage = "quay.io/redhat-user-workloads/rhtap-shared-team-tenant/tssc-cli:latest"
45-
} else {
46-
defaultImage = fmt.Sprintf("quay.io/redhat-user-workloads/rhtap-shared-team-tenant/tssc-cli:on-pr-%s", constants.Commit)
47-
}
48-
p.StringVar(&m.image, "image", defaultImage, "container image for the installer\n")
42+
p.StringVar(&m.image, "image", m.image, "container image for the installer\n")
4943
}
5044

5145
// Cmd exposes the cobra instance.
@@ -111,6 +105,14 @@ func NewMCPServer(
111105
cfs: cfs,
112106
kube: kube,
113107
}
108+
109+
m.image = "quay.io/redhat-user-workloads/rhtap-shared-team-tenant/tssc-cli"
110+
// Set default image based on CommitID
111+
if constants.CommitID == "" {
112+
m.image = fmt.Sprintf("%s:latest", m.image)
113+
} else {
114+
m.image = fmt.Sprintf("%s:%s", m.image, constants.CommitID)
115+
}
114116
m.PersistentFlags(m.cmd)
115117
return m
116118
}

0 commit comments

Comments
 (0)