From 81d03c5e2fc3fa8d2d79b3b9721aaaf608abdea7 Mon Sep 17 00:00:00 2001 From: Yariv Kenan Date: Wed, 24 Apr 2024 20:15:52 -0700 Subject: [PATCH 1/3] Add support for different architectures --- Makefile | 16 ++++++++++------ install.sh | 5 +++-- main.go | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 927f619..b9f0bcd 100644 --- a/Makefile +++ b/Makefile @@ -13,10 +13,12 @@ build-osx: ifneq ($(shell uname -s),Darwin) $(error this makefile assumes you're building from mac env) endif - GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -o bin/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-osx . + GOARCH=amd64 GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -o bin/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-osx-amd64 . + GOARCH=arm64 GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -o bin/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-osx-arm64 . build-linux: - docker run --rm -v $(shell pwd):/app -w /app golang:1.22-alpine /bin/sh -c "GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -o bin/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-linux ." + docker run --rm -v $(shell pwd):/app -w /app golang:1.22-alpine /bin/sh -c "GOARCH=arm64 GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -o bin/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-linux-aarch64 ." + docker run --rm -v $(shell pwd):/app -w /app golang:1.22-alpine /bin/sh -c "GOARCH=amd64 GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -o bin/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-linux-x86_64 ." clean: rm -rf ./bin @@ -32,10 +34,12 @@ test: verify-binaries: $(info running binaries verification on osx, alpine, debiand, centos) - ./bin/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-osx --version - docker run --rm -v $(shell pwd)/bin:/app -w /app alpine /app/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-linux --version - docker run --rm -v $(shell pwd)/bin:/app -w /app debian:buster /app/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-linux --version - docker run --rm -v $(shell pwd)/bin:/app -w /app centos:8 /app/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-linux --version + ./bin/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-osx-amd64 --version + ./bin/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-osx-arm64 --version + docker run --rm -v $(shell pwd)/bin:/app -w /app alpine /app/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-linux-aarch64 --version + docker run --rm -v $(shell pwd)/bin:/app -w /app alpine /app/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-linux-x86_64 --version + docker run --rm -v $(shell pwd)/bin:/app -w /app debian:buster /app/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-linux-aarch64 --version + docker run --rm -v $(shell pwd)/bin:/app -w /app debian:buster /app/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-linux-x86_64 --version compress-bin: find bin -type f -print -exec zip -j '{}'.zip '{}' \; diff --git a/install.sh b/install.sh index c501c28..c271020 100755 --- a/install.sh +++ b/install.sh @@ -12,12 +12,13 @@ pushd "$TMPDIR" > /dev/null mkdir -p complexity pushd complexity > /dev/null; distro=$(if [[ "$(uname -s)" == "Darwin" ]]; then echo "osx"; else echo "linux"; fi) + arch=$(uname -m) if [ -n "$1" ] then echo "Will download and install v$1" - curl -sSL --fail -o complexity.zip "https://github.com/apiiro/code-complexity/releases/download/v$1/complexity-$1-$distro.zip" + curl -sSL --fail -o complexity.zip "https://github.com/apiiro/code-complexity/releases/download/v$1/complexity-$1-$distro-$arch.zip" else - curl -s --fail https://api.github.com/repos/apiiro/code-complexity/releases/latest | grep "browser_download_url.*$distro.zip" | cut -d : -f 2,3 | tr -d \" | xargs curl -sSL --fail -o complexity.zip + curl -s --fail https://api.github.com/repos/apiiro/code-complexity/releases/latest | grep "browser_download_url.*$distro-$arch.zip" | cut -d : -f 2,3 | tr -d \" | xargs curl -sSL --fail -o complexity.zip fi unzip complexity.zip chmod +x complexity-* diff --git a/main.go b/main.go index e075749..d55fa30 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,7 @@ import ( "github.com/urfave/cli/v2" ) -const VERSION = "1.0.6" +const VERSION = "1.0.7" func main() { cli.AppHelpTemplate = From db310a66012633c1130ec39368f027945e2fb3ee Mon Sep 17 00:00:00 2001 From: Yariv Kenan Date: Wed, 24 Apr 2024 20:31:07 -0700 Subject: [PATCH 2/3] . --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b9f0bcd..f61d8de 100644 --- a/Makefile +++ b/Makefile @@ -13,12 +13,12 @@ build-osx: ifneq ($(shell uname -s),Darwin) $(error this makefile assumes you're building from mac env) endif - GOARCH=amd64 GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -o bin/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-osx-amd64 . + GOARCH=amd64 GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -o bin/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-osx-x86_64 . GOARCH=arm64 GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -o bin/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-osx-arm64 . build-linux: - docker run --rm -v $(shell pwd):/app -w /app golang:1.22-alpine /bin/sh -c "GOARCH=arm64 GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -o bin/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-linux-aarch64 ." docker run --rm -v $(shell pwd):/app -w /app golang:1.22-alpine /bin/sh -c "GOARCH=amd64 GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -o bin/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-linux-x86_64 ." + docker run --rm -v $(shell pwd):/app -w /app golang:1.22-alpine /bin/sh -c "GOARCH=arm64 GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -o bin/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-linux-aarch64 ." clean: rm -rf ./bin @@ -34,7 +34,7 @@ test: verify-binaries: $(info running binaries verification on osx, alpine, debiand, centos) - ./bin/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-osx-amd64 --version + ./bin/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-osx-x86_64 --version ./bin/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-osx-arm64 --version docker run --rm -v $(shell pwd)/bin:/app -w /app alpine /app/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-linux-aarch64 --version docker run --rm -v $(shell pwd)/bin:/app -w /app alpine /app/$(BINARY_NAME)-$(shell $(GOCMD) run . --version | cut -d" " -f 3)-linux-x86_64 --version From e624d841006b70f62fd972958ccd980cb30fa3ca Mon Sep 17 00:00:00 2001 From: Yariv Kenan Date: Wed, 24 Apr 2024 20:32:05 -0700 Subject: [PATCH 3/3] . --- install.sh | 5 ++--- install2.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100755 install2.sh diff --git a/install.sh b/install.sh index c271020..c501c28 100755 --- a/install.sh +++ b/install.sh @@ -12,13 +12,12 @@ pushd "$TMPDIR" > /dev/null mkdir -p complexity pushd complexity > /dev/null; distro=$(if [[ "$(uname -s)" == "Darwin" ]]; then echo "osx"; else echo "linux"; fi) - arch=$(uname -m) if [ -n "$1" ] then echo "Will download and install v$1" - curl -sSL --fail -o complexity.zip "https://github.com/apiiro/code-complexity/releases/download/v$1/complexity-$1-$distro-$arch.zip" + curl -sSL --fail -o complexity.zip "https://github.com/apiiro/code-complexity/releases/download/v$1/complexity-$1-$distro.zip" else - curl -s --fail https://api.github.com/repos/apiiro/code-complexity/releases/latest | grep "browser_download_url.*$distro-$arch.zip" | cut -d : -f 2,3 | tr -d \" | xargs curl -sSL --fail -o complexity.zip + curl -s --fail https://api.github.com/repos/apiiro/code-complexity/releases/latest | grep "browser_download_url.*$distro.zip" | cut -d : -f 2,3 | tr -d \" | xargs curl -sSL --fail -o complexity.zip fi unzip complexity.zip chmod +x complexity-* diff --git a/install2.sh b/install2.sh new file mode 100755 index 0000000..c271020 --- /dev/null +++ b/install2.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# USAGE: ./install.sh [version] +# will install the latest tool executable to your /usr/local/bin + +set -e + +echo "Installing..." + +TMPDIR=${TMPDIR:-"/tmp"} +pushd "$TMPDIR" > /dev/null + mkdir -p complexity + pushd complexity > /dev/null; + distro=$(if [[ "$(uname -s)" == "Darwin" ]]; then echo "osx"; else echo "linux"; fi) + arch=$(uname -m) + if [ -n "$1" ] + then + echo "Will download and install v$1" + curl -sSL --fail -o complexity.zip "https://github.com/apiiro/code-complexity/releases/download/v$1/complexity-$1-$distro-$arch.zip" + else + curl -s --fail https://api.github.com/repos/apiiro/code-complexity/releases/latest | grep "browser_download_url.*$distro-$arch.zip" | cut -d : -f 2,3 | tr -d \" | xargs curl -sSL --fail -o complexity.zip + fi + unzip complexity.zip + chmod +x complexity-* + cp -f complexity-* /usr/local/bin/complexity + popd > /dev/null + rm -rf complexity +popd > /dev/null + +echo "Done: $(complexity -v)"