diff --git a/.goreleaser.yml b/.goreleaser.yml index c68e101..3b2f29b 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -6,6 +6,8 @@ builds: goarch: [amd64, arm64] env: [CGO_ENABLED=0] flags: [-mod=mod] + ldflags: + - -s -w -X main.Version={{ .Version }}-{{ .Github.sha }} release: prerelease: auto @@ -20,8 +22,8 @@ brews: owner: runpod name: homebrew-runpodctl commit_author: - name: rachfop - email: prachford@icloud.com + name: runpod + email: support@runpod.io checksum: name_template: "checksums.txt" diff --git a/cmd/croc/receive.go b/cmd/croc/receive.go index 7baa0d4..11415b5 100644 --- a/cmd/croc/receive.go +++ b/cmd/croc/receive.go @@ -48,15 +48,18 @@ var ReceiveCmd = &cobra.Command{ } sharedSecretCode := args[0] split := strings.Split(sharedSecretCode, "-") - if len(split) < 5 { - log.Fatalf("Malformed code %q: expected 5 parts separated by dashes, but got %v", sharedSecretCode, len(split)) + if len(split) < 2 { + log.Fatalf("Malformed code %q: expected at least 2 parts separated by dashes, but got %v. Please retry 'runpodctl send' to generate a valid code.", sharedSecretCode, len(split)) } - relayIndex, err := strconv.Atoi(split[4]) // relay index + relayIndex, err := strconv.Atoi(split[len(split)-1]) // relay index is the final split value if err != nil { - log.Fatalf("Malformed relay, please try again.") + log.Fatalf("Malformed relay, please retry 'runpodctl send' to generate a valid code.") } + if relayIndex < 0 || relayIndex >= len(relays) { + log.Fatalf("Relay index %d not found; please retry 'runpodctl send' to generate a valid code.", relayIndex) + } relay := relays[relayIndex] crocOptions := croc.Options{ diff --git a/main.go b/main.go index f73df96..57ad0d6 100644 --- a/main.go +++ b/main.go @@ -1,15 +1,19 @@ package main import ( - _ "embed" "strings" "github.com/runpod/runpodctl/cmd" ) -//go:embed version +// Version is set at build time via ldflags (see makefile and .goreleaser.yml) +// If not set, falls back to "dev" var Version string func main() { - cmd.Execute(strings.TrimRight(Version, "\r\n")) + version := Version + if version == "" { + version = "local-dev" + } + cmd.Execute(strings.TrimRight(version, "\r\n")) } diff --git a/makefile b/makefile index 8bdcad4..05ad86e 100644 --- a/makefile +++ b/makefile @@ -1,8 +1,12 @@ .PHONY: proto +# Git version and commit +VERSION = git describe --tags --exact-match HEAD 2>/dev/null || git describe --tags 2>/dev/null || echo "unknown" +COMMIT = git rev-parse HEAD 2>/dev/null || echo "unknown" -local: version - go build -o bin/runpodctl . +local: + @COMMIT=$$($(COMMIT)); \ + go build -mod=mod -ldflags "-s -w -X main.Version=dev-$$COMMIT" -o bin/runpodctl . release: buildall strip compress @@ -10,24 +14,32 @@ buildall: android-arm64 linux-amd64 darwin-arm64 windows-amd64 windows-arm64 dar compress: upx --best bin/* || true + strip: strip bin/* || true - -android-arm64: version - env GOOS=android GOARCH=arm64 go build -o bin/runpodctl-android-arm64 . -linux-amd64: version - env GOOS=linux GOARCH=amd64 go build -o bin/runpodctl-linux-amd64 . -darwin-arm64: version - env GOOS=darwin GOARCH=arm64 go build -o bin/runpodctl-darwin-arm64 . -windows-amd64: version - env GOOS=windows GOARCH=amd64 go build -o bin/runpodctl-windows-amd64.exe . -windows-arm64: version - env GOOS=windows GOARCH=arm64 go build -o bin/runpodctl-windows-arm64.exe . -darwin-amd64: version - env GOOS=darwin GOARCH=amd64 go build -o bin/runpodctl-darwin-amd64 . - -lint: version - golangci-lint run -version: - @test -f version || (echo "Error: version file not found" && exit 1) \ No newline at end of file +# Generic build function +define build-target + @VERSION=$$($(VERSION)); \ + COMMIT=$$($(COMMIT)); \ + env CGO_ENABLED=0 GOOS=$(1) GOARCH=$(2) go build -mod=mod -ldflags "-s -w -X main.Version=$$VERSION-$$COMMIT" -o bin/runpodctl-$(1)-$(2)$(3) . +endef + +# Platform-specific targets +android-arm64: + $(call build-target,android,arm64,) + +linux-amd64: + $(call build-target,linux,amd64,) + +darwin-arm64: + $(call build-target,darwin,arm64,) + +darwin-amd64: + $(call build-target,darwin,amd64,) + +windows-amd64: + $(call build-target,windows,amd64,.exe) + +windows-arm64: + $(call build-target,windows,arm64,.exe) \ No newline at end of file diff --git a/version b/version deleted file mode 100644 index 3afb685..0000000 --- a/version +++ /dev/null @@ -1 +0,0 @@ -v1.14.11