Skip to content

Commit

Permalink
improve version command
Browse files Browse the repository at this point in the history
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
  • Loading branch information
Adphi committed Nov 1, 2023
1 parent 8e0aabd commit b225353
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ bin
**/node_modules
**/build
docs

dist/
completions/
32 changes: 31 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
MODULE = go.linka.cloud/artifact-registry

GITHUB_REPO = linka-cloud/artifact-registry

PROJECT = artifact-registry
REPOSITORY = linkacloud

Expand All @@ -22,7 +24,10 @@ install: build-ui

DOCKER_BUILDX_ARGS := build --pull --load --build-arg VERSION=$(VERSION)

docker: docker-build docker-push
docker: docker-build docker-scan docker-push

docker-scan:
@trivy image --severity "HIGH,CRITICAL" --exit-code 100 $(REPOSITORY)/$(PROJECT):$(VERSION)

.PHONY: docker-build
docker-build:
Expand All @@ -39,8 +44,33 @@ ifneq ($(TAG),)
@docker image push $(REPOSITORY)/$(PROJECT):latest
endif

.PHONY: completions
completions:
@rm -rf completions
@mkdir -p completions
@for shell in bash zsh fish powershell; do \
go run ./cmd/lkar completion $$shell > completions/lkar.$$shell; \
done

.PHONY: cli-docs
cli-docs:
@rm -rf ./docs/{lkar,lkard}
@go run -tags=docs ./cmd/lkar docs ./docs/lkar
@go run -tags=docs ./cmd/lkard docs ./docs/lkard

PHONY: build-snapshot
build-snapshot: build-ui
@VERSION=$(VERSION) REPO=$(GITHUB_REPO) goreleaser build --snapshot --clean --parallelism 8

.PHONY: release-snapshot
release-snapshot: build-ui
@VERSION=$(VERSION) REPO=$(GITHUB_REPO) goreleaser release --snapshot --clean --skip=sign,publish,announce --parallelism 8

.PHONY: build
build: build-ui
@VERSION=$(VERSION) REPO=$(GITHUB_REPO) goreleaser build --clean --parallelism 8

.PHONY: release
release: build-ui
@VERSION=$(VERSION) REPO=$(GITHUB_REPO) goreleaser release --clean --parallelism 8

1 change: 1 addition & 0 deletions cmd/lkar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var (
Short: "An OCI based Artifact Registry",
SilenceUsage: true,
PersistentPreRunE: setup,
Version: artifact_registry.Version,
}
)

Expand Down
7 changes: 5 additions & 2 deletions cmd/lkar/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ import (
var (
cmdVersion = &cobra.Command{
Use: "version",
Short: "Print the version and build date of lk-artifact-registry",
Short: "Print the version informations and exit",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("%s\n%s\n", artifact_registry.Version, artifact_registry.BuildDate)
fmt.Printf("Version: %s\n", artifact_registry.Version)
fmt.Printf("Commit: %s\n", artifact_registry.Commit)
fmt.Printf("Date: %s\n", artifact_registry.Date)
fmt.Printf("Repo: https://github.com/%s\n", artifact_registry.Repo)
},
}
)
Expand Down
9 changes: 7 additions & 2 deletions cmd/lkard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ var (
Short: "An OCI based Artifact Registry",
Args: cobra.MaximumNArgs(1),
SilenceUsage: true,
Version: artifact_registry.Version,
Run: func(cmd *cobra.Command, args []string) {
if aesKey == "" {
logrus.Fatalf("environment variable $%s must be set", EnvKey)
Expand Down Expand Up @@ -156,9 +157,13 @@ var (
},
}
cmdVersion = &cobra.Command{
Use: "version",
Use: "version",
Short: "Print the version informations and exit",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("%s (%s)\n", artifact_registry.Version, artifact_registry.BuildDate)
fmt.Printf("Version: %s\n", artifact_registry.Version)
fmt.Printf("Commit: %s\n", artifact_registry.Commit)
fmt.Printf("Date: %s\n", artifact_registry.Date)
fmt.Printf("Repo: https://github.com/%s\n", artifact_registry.Repo)
},
}
)
Expand Down
6 changes: 4 additions & 2 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package artifact_registry

var (
Version = "dev"
BuildDate = ""
Version = "0.0.0-dev"
Commit = "none"
Date = ""
Repo = "linka-cloud/artifact-registry"
)

0 comments on commit b225353

Please sign in to comment.