Skip to content

Commit

Permalink
dev: add ci
Browse files Browse the repository at this point in the history
  • Loading branch information
wwhai committed Jun 23, 2023
1 parent 5120e3f commit 93f043c
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 6 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/1-auto-release.yml
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"
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ go.sum
*.bin
*.output
profile*
rulexc
rulexc
*.txt
__build/**
70 changes: 70 additions & 0 deletions Makefile
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
10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ func main() {
Usage: `|✿| 查看系统参数: rulexc system-info -host 127.0.0.1
|✿| 查看输入资源: rulexc inend-list -host 127.0.0.1
|✿| 查看输出资源: rulexc outend-list -host 127.0.0.1
|✿| 创建设备: rulexc device-create --config '[config]' -host 127.0.0.1
|✿| 创建设备: rulexc device-create --config [config] -host 127.0.0.1
|✿| 查看设备列表: rulexc device-list -host 127.0.0.1
|✿| 查看规则列表: rulexc rules-list -host 127.0.0.1
|✿| 创建输入资源: rulexc inend-create --config '[config]' -host 127.0.0.1
|✿| 创建输出资源: rulexc outend-create --config '[config]' -host 127.0.0.1
|✿| 创建规则脚本: rulexc rules-create --config '[config]' -host 127.0.0.1
|✿| 创建输入资源: rulexc inend-create --config [config] -host 127.0.0.1
|✿| 创建输出资源: rulexc outend-create --config [config] -host 127.0.0.1
|✿| 创建规则脚本: rulexc rules-create --config [config] -host 127.0.0.1
|✿| 创建用户: rulexc user-create --u [username] --p [password] -host 127.0.0.1
|✿| 删除用户: rulexc user-delete --u [username] -host 127.0.0.1
`,
Action: func(c *cli.Context) error {
fmt.Printf("[✘] Unknown command:%v, those below are valid supported commands:\n", c.Args().Slice())
fmt.Println("[✘] 请正确输入参数:", c.Args().Slice())
fmt.Println(c.App.Usage)
return nil
},
Expand Down
152 changes: 152 additions & 0 deletions release_pkg.sh
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

0 comments on commit 93f043c

Please sign in to comment.