Skip to content

Commit

Permalink
feat: update 'kclvm version' by git tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
zong-zhe committed May 10, 2023
1 parent b06ad46 commit a3d08f1
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 4 deletions.
11 changes: 11 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This is an example .goreleaser.yml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
builds:
- id: kpm
main: ./kpm.go
ldflags:
- "-X main.version={{.Version}}"
4 changes: 3 additions & 1 deletion kpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"kusionstack.io/kpm/pkg/settings"
)

var version string

func main() {
reporter.InitReporter()
setting, err := settings.Init()
Expand All @@ -20,7 +22,7 @@ func main() {
app := cli.NewApp()
app.Name = "kpm"
app.Usage = "kpm is a kcl package manager"
app.Version = "v0.0.1"
app.Version = version
app.UsageText = "kpm <command> [arguments]..."
app.Commands = []*cli.Command{
cmd.NewInitCmd(),
Expand Down
5 changes: 4 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
VERSION := $(shell git describe --tags)
LDFLAGS := -X main.version=$(VERSION)

build:
go build kpm.go
go build -ldflags "$(LDFLAGS)" kpm.go

COVER_FILE ?= coverage.out
SOURCE_PATHS ?= ./pkg/...
Expand Down
4 changes: 2 additions & 2 deletions scripts/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ set -o pipefail
GO111MODULE=on go install github.com/onsi/ginkgo/v2/ginkgo@v2.0.0

# Build kpm binary
go build -o ./bin/kpm .

LDFLAGS="-X main.version=test_version"
go build -ldflags "$LDFLAGS" -o ./bin/kpm

# Run e2e
set +e
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/test_suites/kpm/no_args/version/test_suite.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
KPM_HOME=""
KCLVM_VENDOR_HOME=""
1 change: 1 addition & 0 deletions test/e2e/test_suites/kpm/no_args/version/test_suite.input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kpm --version
Empty file.
1 change: 1 addition & 0 deletions test/e2e/test_suites/kpm/no_args/version/test_suite.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kpm version test_version

0 comments on commit a3d08f1

Please sign in to comment.