-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
262 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: 1- Release | ||
on: | ||
push: | ||
tags: | ||
- "v*" | ||
|
||
jobs: | ||
build: | ||
name: Package | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: "Check go version" | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.18 | ||
- name: Build | ||
run: | | ||
sudo apt update -y | ||
sudo apt install jq cloc protobuf-compiler \ | ||
gcc-mingw-w64-x86-64 \ | ||
gcc-arm-linux-gnueabi \ | ||
gcc-mips-linux-gnu \ | ||
gcc-aarch64-linux-gnu -y | ||
cloc ./ | ||
make | ||
bash ./release_pkg.sh | ||
# ------------------------------ | ||
- uses: ncipollo/release-action@v1 | ||
name: "Upload Files" | ||
with: | ||
artifacts: "__build/_release/*.zip" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,6 @@ go.sum | |
*.bin | ||
*.output | ||
profile* | ||
rulexc | ||
rulexc | ||
*.txt | ||
__build/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
APP=rulexc | ||
# 获取操作系统信息 | ||
distro=$(shell cat /etc/os-release | grep PRETTY_NAME | cut -d '"' -f 2) | ||
kernel=$(shell uname -r) | ||
cpu=$(shell uname -m) | ||
host=$(shell hostname) | ||
ip=$(shell hostname -I) | ||
memory=$(shell free -m | awk 'NR==2{printf "%.2fGB\n", $$2/1000}') | ||
disk=$(shell df -h | awk '$$NF=="/"{printf "%s\n", $$2}') | ||
|
||
|
||
.PHONY: all | ||
all: | ||
@echo "\e[41m[*] Distro \e[0m: \e[36m ${distro} \e[0m" | ||
@echo "\e[41m[*] Kernel \e[0m: \e[36m ${kernel} \e[0m" | ||
@echo "\e[41m[*] Cpu \e[0m: \e[36m ${cpu} \e[0m" | ||
@echo "\e[41m[*] Memory \e[0m: \e[36m ${memory} \e[0m" | ||
@echo "\e[41m[*] Host \e[0m: \e[36m ${host} \e[0m" | ||
@echo "\e[41m[*] IP \e[0m: \e[36m ${ip} \e[0m" | ||
@echo "\e[41m[*] Disk \e[0m: \e[36m ${disk} \e[0m" | ||
make build | ||
|
||
.PHONY: build | ||
build: | ||
CGO_ENABLED=1 GOOS=linux go build -v -ldflags "-s -w" -o ${APP} | ||
|
||
.PHONY: x64linux | ||
x64linux: | ||
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=gcc\ | ||
go build -ldflags "-s -w -linkmode external -extldflags -static" -o ${APP}-x64linux | ||
|
||
.PHONY: windows | ||
windows: | ||
GOOS=windows CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build -ldflags "-s -w" -buildmode=c-shared -o ${APP}.exe | ||
|
||
.PHONY: arm32 | ||
arm32: | ||
CGO_ENABLED=1 GOOS=linux GOARCH=arm CC=arm-linux-gnueabi-gcc\ | ||
go build -ldflags "-s -w -linkmode external -extldflags -static" -o ${APP}-arm32 | ||
|
||
.PHONY: arm64 | ||
arm64: | ||
CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc\ | ||
go build -ldflags "-s -w -linkmode external -extldflags -static" -o ${APP}-arm64 | ||
|
||
.PHONY: mips32 | ||
mips32: | ||
# sudo apt-get install gcc-mips-linux-gnu | ||
GOOS=linux GOARCH=mips CGO_ENABLED=1 CC=mips-linux-gnu-gcc\ | ||
go build -ldflags "-s -w -linkmode external -extldflags -static" -o ${APP}-mips32 | ||
|
||
.PHONY: mips64 | ||
mips64: | ||
# sudo apt-get install gcc-mips-linux-gnu | ||
GOOS=linux GOARCH=mips64 CGO_ENABLED=1 CC=mips-linux-gnu-gcc\ | ||
go build -ldflags "-s -w -linkmode external -extldflags -static" -o ${APP}-mips64 | ||
|
||
.PHONY: mipsel | ||
mipsle: | ||
# sudo apt-get install gcc-mipsel-linux-gnu | ||
GOOS=linux GOARCH=mipsle CGO_ENABLED=1 GOMIPS=softfloat CC=mipsel-linux-gnu-gcc\ | ||
go build -ldflags "-s -w -linkmode external -extldflags -static" -o ${APP}-mipsle | ||
|
||
.PHONY: run | ||
run: | ||
go run -race run | ||
|
||
.PHONY: test | ||
test: | ||
go test rulex/test -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
#! /bin/bash | ||
set -e | ||
|
||
RESPOSITORY="https://github.com/hootrhino" | ||
|
||
# __build | ||
create_pkg() { | ||
|
||
VERSION=$(git describe --tags --always --abbrev=0) | ||
echo "Create package: ${rulexc-$1-${VERSION}}" | ||
if [ "$1" == "x64windows" ]; then | ||
zip -r ../_release/rulexc-$1-${VERSION}.zip \ | ||
./rulexc.exe | ||
rm -rf ./rulexc.exe | ||
else | ||
zip -r ../_release/rulexc-$1-${VERSION}.zip \ | ||
./rulexc-* | ||
rm -rf ./rulexc-* | ||
fi | ||
} | ||
|
||
# | ||
make_zip() { | ||
if [ -n $1 ]; then | ||
create_pkg $1 | ||
else | ||
echo "Should have release target." | ||
exit 1 | ||
fi | ||
|
||
} | ||
|
||
# | ||
build_x64windows() { | ||
make windows | ||
} | ||
|
||
build_x64linux() { | ||
make x64linux | ||
} | ||
|
||
build_arm64linux() { | ||
make arm64 | ||
} | ||
|
||
build_arm32linux() { | ||
make arm32 | ||
} | ||
|
||
build_mips64linux() { | ||
make mips64 | ||
} | ||
|
||
build_mips32linux() { | ||
make mips32 | ||
} | ||
#------------------------------------------ | ||
cross_compile() { | ||
ARCHS=("x64windows" "x64linux" "arm64linux" "arm32linux") | ||
if [ ! -d "./_release/" ]; then | ||
mkdir -p ./_release/ | ||
else | ||
rm -rf ./_release/ | ||
mkdir -p ./_release/ | ||
fi | ||
cd rulexc | ||
for arch in ${ARCHS[@]}; do | ||
echo -e "\033[34m [★] Compile target =>\033[43;34m ["$arch"]. \033[0m" | ||
if [[ "${arch}" == "x64windows" ]]; then | ||
# sudo apt install gcc-mingw-w64-x86-64 -y | ||
build_x64windows $arch | ||
make_zip $arch | ||
echo -e "\033[33m [√] Compile target => ["$arch"] Ok. \033[0m" | ||
fi | ||
if [[ "${arch}" == "x86linux" ]]; then | ||
build_x86linux $arch | ||
make_zip $arch | ||
echo -e "\033[33m [√] Compile target => ["$arch"] Ok. \033[0m" | ||
|
||
fi | ||
if [[ "${arch}" == "x64linux" ]]; then | ||
build_x64linux $arch | ||
make_zip $arch | ||
echo -e "\033[33m [√] Compile target => ["$arch"] Ok. \033[0m" | ||
|
||
fi | ||
if [[ "${arch}" == "arm64linux" ]]; then | ||
# sudo apt install gcc-arm-linux-gnueabi -y | ||
build_arm64linux $arch | ||
make_zip $arch | ||
echo -e "\033[33m [√] Compile target => ["$arch"] Ok. \033[0m" | ||
|
||
fi | ||
if [[ "${arch}" == "arm32linux" ]]; then | ||
# sudo apt install gcc-arm-linux-gnueabi -y | ||
build_arm32linux $arch | ||
make_zip $arch | ||
echo -e "\033[33m [√] Compile target => ["$arch"] Ok. \033[0m" | ||
fi | ||
done | ||
cd .. | ||
} | ||
# | ||
# gen_changelog | ||
# | ||
gen_changelog() { | ||
PreviewVersion=$(git describe --tags --abbrev=0 $(git rev-list --tags --skip=1 --max-count=1)) | ||
CurrentVersion=$(git describe --tags --abbrev=0) | ||
echo "----------------------------------------------------------------" | ||
echo -e "\033[34m [★] Change log between\033[44;34m ["${PreviewVersion}"] <--> [${CurrentVersion}]. \033[0m" | ||
echo "----------------------------------------------------------------" | ||
ChangeLog=$(git log ${PreviewVersion}..${CurrentVersion} --pretty=format:"%h %ad | %s") | ||
printf "${ChangeLog}\n" | ||
echo ${ChangeLog} > ./ChangeLog.txt | ||
} | ||
|
||
# | ||
#----------------------------------- | ||
# | ||
init_env() { | ||
if [ ! -d "./__build/" ]; then | ||
mkdir -p ./__build/rulexc/ | ||
else | ||
rm -rf ./__build/ | ||
mkdir -p ./__build/rulexc/ | ||
fi | ||
} | ||
# | ||
# 检查是否安装了这些软件 | ||
# | ||
check_cmd() { | ||
DEPS=("git" "jq" "gcc" "make") | ||
for dep in ${DEPS[@]}; do | ||
echo -e "\033[34m [*] Check dependcy command: $dep. \033[0m" | ||
if ! [ -x "$(command -v $dep)" ]; then | ||
echo -e "\033[31m |x| Error: $dep is not installed. \033[0m" | ||
exit 1 | ||
else | ||
echo -e "\033[32m [√] $dep has been installed. \033[0m" | ||
fi | ||
done | ||
|
||
} | ||
# | ||
#----------------------------------- | ||
# | ||
check_cmd | ||
init_env | ||
cp -r $(ls | egrep -v '^__build$') ./__build/rulexc | ||
cd ./__build | ||
cross_compile | ||
gen_changelog |