Skip to content

Commit 93f578c

Browse files
committed
chore: 优化makefile
1 parent 5886a04 commit 93f578c

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed

.github/workflows/build.yml

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ jobs:
2323
mkdir -p assets/dash/dashboard/apps/web-ele/dist
2424
touch assets/dash/dashboard/apps/web-ele/dist/index.html
2525
make init
26-
make generate
2726
make build
2827
2928
- name: Test

Makefile

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
MODULE := $(shell go list -m)
22
MODULE_NAME := $(lastword $(subst /, ,$(MODULE)))
33
BUILD := $(shell git rev-parse --short HEAD)@$(shell date +%s)
4-
CURRENT_OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
5-
CURRENT_ARCH := $(shell uname -m | tr '[:upper:]' '[:lower:]')
4+
CURRENT_OS := $(shell uname | tr "[A-Z]" "[a-z]")
5+
CURRENT_ARCH := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')
66

77
DOCKER_IMAGE ?= ghcr.io/tbxark/$(MODULE_NAME)
88
DOCKER_FILE := cmd/app/Dockerfile
@@ -66,16 +66,16 @@ dash: ## Build dash
6666
build: ## Build binary
6767
$(GO_BUILD) -o ./build/$(CURRENT_OS)_$(CURRENT_ARCH)/ ./...
6868

69-
.PHONY: build-linux-amd
70-
build-linux-amd: ## Build linux amd64 binary
71-
GOOS=linux GOARCH=amd64 $(GO_BUILD) -o ./build/linux_x86/ ./...
69+
.PHONY: build-linux-amd64
70+
build-linux-amd64: ## Build linux amd64 binary
71+
GOOS=linux GOARCH=amd64 $(GO_BUILD) -o ./build/linux_amd64/ ./...
7272

73-
.PHONY: build-linux-arm
74-
build-linux-arm: ## Build linux arm64 binary
73+
.PHONY: build-linux-arm64
74+
build-linux-arm64: ## Build linux arm64 binary
7575
GOOS=linux GOARCH=arm64 $(GO_BUILD) -o ./build/linux_arm64/ ./...
7676

7777
.PHONY: build-all
78-
build-all: build-linux-amd build-linux-arm ## Build all arch binary
78+
build-all: build-linux-amd64 build-linux-arm64 ## Build all arch binary
7979

8080
.PHONY: build-docker
8181
build-docker: ## Build docker image

scripts/install.sh

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env sh
2+
3+
set -u
4+
5+
type curl > /dev/null || { echo "curl: not found"; exit 1; }
6+
7+
set -e
8+
9+
10+
bin="sphere"
11+
repo="TBXark/sphere"
12+
dest_dir="/usr/local/bin"
13+
14+
get_latest_release() {
15+
local repo="$1"
16+
curl -sSL "https://api.github.com/repos/${repo}/releases/latest" | \
17+
awk 'BEGIN{FS=": |,|\""}; /tag_name/{print $5}'
18+
}
19+
20+
version="$(get_latest_release "${repo}")" # v1.2.0
21+
22+
# if args has version override it and not eq "latest"
23+
if test $# -eq 1; then
24+
if test "$1" != "latest"; then
25+
version="$1"
26+
27+
echo "Install ${version}"
28+
fi
29+
fi
30+
31+
platform="$(uname | tr "[A-Z]" "[a-z]")" # Linux => linux
32+
arch="$(uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')" # x86_64 => amd64, aarch64 => arm64
33+
package="${bin}_${platform}_${arch}.tar.gz"
34+
package_url="https://github.com/${repo}/releases/download/${version}/${package}"
35+
bin_path="${dest_dir}/${bin}"
36+
tmp_dir="$(mktemp -d)"
37+
38+
trap "rm -r ${tmp_dir}" EXIT
39+
40+
if test -e "${bin_path}"; then
41+
current_version="v$("${bin_path}" -v | awk '{print $NF}')"
42+
if test "${current_version}" = "${version}"; then
43+
echo "${bin} is already updated, no need to upgrade."
44+
exit 0
45+
else
46+
echo "There is a new version of ${bin}, starting to upgrade from ${current_version} to ${version}."
47+
fi
48+
fi
49+
cd "${tmp_dir}"
50+
curl -sSL "${package_url}" | tar xzf -
51+
52+
if test $(id -u) -eq 0; then
53+
mv "${bin}" "${dest_dir}"
54+
else
55+
sudo mv "${bin}" "${dest_dir}"
56+
fi
57+
58+
mkdir -p ~/.${bin}
59+
60+
echo "${bin} ${version} has been installed."

0 commit comments

Comments
 (0)