Skip to content

Commit 94c61ae

Browse files
committed
feat: adding version command to cli
1 parent 00e7cae commit 94c61ae

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

.github/workflows/release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
GOARCH: ${{ matrix.arch }}
3535
run: |
3636
cd cmd/gitops
37-
go build -ldflags="-s -w" .
37+
go build -ldflags="-s -w -X 'main.version=${{ github.ref_name }}'" .
3838
- name: Upload binaries to release
3939
uses: svenstaro/upload-release-action@v2
4040
with:
@@ -69,5 +69,7 @@ jobs:
6969
with:
7070
platforms: linux/amd64
7171
push: true
72+
build-args: |
73+
GITOPS_VERSION=${{ github.ref_name }}
7274
tags: ghcr.io/mxcd/gitops/${{ matrix.image }}:${{ github.ref_name }}
7375
file: docker/${{ matrix.image }}/Dockerfile

cmd/gitops/main.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@ import (
1515
"github.com/urfave/cli/v2"
1616
)
1717

18+
var version = "development"
19+
1820
func main() {
21+
cli.VersionFlag = &cli.BoolFlag{
22+
Name: "version",
23+
Aliases: []string{},
24+
Usage: "print only the version",
25+
}
26+
1927
app := &cli.App{
20-
Name: "gitpos",
21-
Usage: "GitOps CLI",
28+
Name: "gitpos",
29+
Version: version,
30+
Usage: "GitOps CLI",
2231
Flags: []cli.Flag{
2332
&cli.StringFlag{
2433
Name: "root-dir",

docker/gitops/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
FROM golang:1.24-alpine3.20 AS builder
22
RUN apk add --no-cache git
33

4+
ARG GITOPS_VERSION="development"
5+
46
WORKDIR /usr/src
57
COPY go.mod /usr/src/go.mod
68
COPY go.sum /usr/src/go.sum
@@ -10,7 +12,7 @@ COPY cmd cmd
1012
COPY internal internal
1113

1214
WORKDIR /usr/src/cmd/gitops
13-
RUN go build -o gitops -ldflags="-s -w" .
15+
RUN go build -o gitops -ldflags="-s -w 'main.version=${GITOPS_VERSION}'" .
1416

1517
FROM alpine:3.20
1618
WORKDIR /usr/bin

0 commit comments

Comments
 (0)