Skip to content

Commit

Permalink
skip if newer version is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
bakito committed Jul 6, 2024
1 parent c5a9745 commit 53a1fcb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,23 @@ $(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool Binaries
DEEPCOPY_GEN ?= $(LOCALBIN)/deepcopy-gen
GINKGO ?= $(LOCALBIN)/ginkgo
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
GORELEASER ?= $(LOCALBIN)/goreleaser
OAPI_CODEGEN ?= $(LOCALBIN)/oapi-codegen
SEMVER ?= $(LOCALBIN)/semver

## Tool Versions
DEEPCOPY_GEN_VERSION ?= v0.30.2
GORELEASER_VERSION ?= v2.0.1
OAPI_CODEGEN_VERSION ?= v2.3.0

## Tool Installer
.PHONY: deepcopy-gen
deepcopy-gen: $(DEEPCOPY_GEN) ## Download deepcopy-gen locally if necessary.
$(DEEPCOPY_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/deepcopy-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/deepcopy-gen@$(DEEPCOPY_GEN_VERSION)
.PHONY: ginkgo
ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.
$(GINKGO): $(LOCALBIN)
Expand All @@ -48,6 +56,10 @@ $(GOLANGCI_LINT): $(LOCALBIN)
goreleaser: $(GORELEASER) ## Download goreleaser locally if necessary.
$(GORELEASER): $(LOCALBIN)
test -s $(LOCALBIN)/goreleaser || GOBIN=$(LOCALBIN) go install github.com/goreleaser/goreleaser/v2@$(GORELEASER_VERSION)
.PHONY: oapi-codegen
oapi-codegen: $(OAPI_CODEGEN) ## Download oapi-codegen locally if necessary.
$(OAPI_CODEGEN): $(LOCALBIN)
test -s $(LOCALBIN)/oapi-codegen || GOBIN=$(LOCALBIN) go install github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@$(OAPI_CODEGEN_VERSION)
.PHONY: semver
semver: $(SEMVER) ## Download semver locally if necessary.
$(SEMVER): $(LOCALBIN)
Expand All @@ -57,10 +69,14 @@ $(SEMVER): $(LOCALBIN)
.PHONY: update-toolbox-tools
update-toolbox-tools:
@rm -f \
$(LOCALBIN)/deepcopy-gen \
$(LOCALBIN)/ginkgo \
$(LOCALBIN)/golangci-lint \
$(LOCALBIN)/goreleaser \
$(LOCALBIN)/oapi-codegen \
$(LOCALBIN)/semver
toolbox makefile -f $(LOCALDIR)/Makefile \
github.com/goreleaser/goreleaser/v2
k8s.io/code-generator/cmd/deepcopy-gen@github.com/kubernetes/code-generator \
github.com/goreleaser/goreleaser/v2 \
github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen
## toolbox - end
14 changes: 14 additions & 0 deletions pkg/fetcher/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/bakito/toolbox/version"
"github.com/cavaliergopher/grab/v3"
"github.com/go-resty/resty/v2"
"golang.org/x/mod/semver"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -190,6 +191,12 @@ func (f *fetcher) handleTool(client *resty.Client, ver map[string]string, tmp st
}
}
}

if isNewer(currentVersion, tool.Version) {
log.Printf("✅ Skipping since newer version is instlled\n")
return nil
}

if tool.Version == currentVersion {
if configVersion != "" {
log.Printf("✅ Skipping since already configured version %s\n", configVersion)
Expand All @@ -207,6 +214,13 @@ func (f *fetcher) handleTool(client *resty.Client, ver map[string]string, tmp st
return nil
}

func isNewer(toolVersion string, currentVersion string) bool {
if !semver.IsValid(toolVersion) || !semver.IsValid(currentVersion) {
return true
}
return semver.Compare(toolVersion, currentVersion) > 0
}

func (f *fetcher) downloadViaGithub(tb *types.Toolbox, tool *types.Tool, ghr *types.GithubRelease, tmp string) error {
matching := findMatching(tb, tool.Name, ghr.Assets)
tool.CouldNotBeFound = true
Expand Down

0 comments on commit 53a1fcb

Please sign in to comment.