修改readme

This commit is contained in:
bjdgy 2024-01-29 00:09:48 +08:00
parent 13de601474
commit 911b96cc74
12 changed files with 205 additions and 91 deletions

View File

@ -12,14 +12,14 @@
name: "CodeQL" name: "CodeQL"
on: on:
push: workflow_dispatch:
branches: [ "main", "dev" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main", "dev" ]
schedule: # push:
- cron: '32 12 * * 5' # branches: [ "main", "dev" ]
# pull_request:
# branches: [ "main", "dev" ]
# schedule:
# - cron: '32 12 * * 5'
jobs: jobs:
analyze: analyze:

View File

@ -1,8 +1,9 @@
name: go-update name: go-update
on: on:
workflow_dispatch: workflow_dispatch:
schedule: # schedule:
- cron: "1 2 * * 5" # - cron: "1 2 * * 5"
jobs: jobs:
go: go:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -1,10 +1,12 @@
name: Go name: Go
on: on:
push: workflow_dispatch:
branches: [ "main", "dev" ]
pull_request: # push:
branches: [ "main", "dev" ] # branches: [ "main", "dev" ]
# pull_request:
# branches: [ "main", "dev" ]
jobs: jobs:

View File

@ -1,6 +1,7 @@
name: release-tag-version name: release-tag-version
on: on:
workflow_dispatch:
push: push:
tags: tags:
- "v0.*" - "v0.*"
@ -9,20 +10,38 @@ jobs:
Build: Build:
name: build-binary name: build-binary
runs-on: ubuntu-latest runs-on: ubuntu-latest
env:
TZ: Asia/Shanghai
steps: steps:
- name: Hello world
run: |
uname -a
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- run: git fetch --unshallow --quiet --tags --force
- uses: actions/setup-go@v4 - uses: actions/setup-go@v4
with: with:
go-version: '1.20' go-version: '1.20'
go-version-file: 'server/go.mod'
cache-dependency-path: 'server/go.sum' cache-dependency-path: 'server/go.sum'
- uses: actions/setup-node@v4 - uses: actions/setup-node@v4
with: with:
node-version: '16' node-version: '16'
cache: 'yarn'
cache-dependency-path: 'web/yarn.lock'
Docker: - # https://github.com/docker/setup-qemu-action
name: build-docker name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: build
run: |
mkdir server/ui
touch server/ui/index.html
sudo apt-get install -y -q gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
aarch64-linux-gnu-gcc -v
aarch64-linux-gnu-g++ -v
bash build.sh github_action
# Docker:
# name: build-docker

1
.gitignore vendored
View File

@ -4,4 +4,3 @@ anylink-deploy
anylink-deploy.tar.gz anylink-deploy.tar.gz
dist dist
godist

View File

@ -1,32 +1,61 @@
#https://goreleaser.com/static/schema.json #https://goreleaser.com/static/schema.json
# release --skip=publish
# goreleaser build --skip=validate --clean --debug # goreleaser build --skip=validate --clean --debug
# GOPROXY=https://goproxy.cn
# docker run -it --rm -v $PWD:/app -v /go:/go -w /app --platform=linux/arm64
# docker run -it --rm -v $PWD:/app -v /go:/go -w /app goreleaser/goreleaser-cross build --skip=validate --clean --debug
# docker run -it --rm -v $PWD:/app -v /go:/go -w /app bjdgyc/dcross goreleaser build --skip=validate --clean --debug
version: 1 version: 1
dist: godist dist: dist
before: before:
hooks: hooks:
# You may remove this if you don't use go modules. - pwd
#- go mod tidy # - cmd: go mod tidy
# you may remove this if you don't need go generate # dir:
#- go generate ./... # "{{ dir .Dist}}"
# output: true
# - cmd: go generate
# dir:
# "{{ dir .Dist}}"
# output: true
builds: builds:
- id: "build" - id: "build"
#main: . #main: .
dir: ./server dir: ./server
hooks:
pre:
- cmd: go mod tidy
dir: ./server
output: true
- cmd: go generate
dir: ./server
output: true
# {{- if eq .Arch "amd64" }}CC=x86_64-linux-gnu-gcc CXX=x86_64-linux-gnu-g++{{- end }}
env: env:
- CGO_ENABLED=1 - CGO_ENABLED=1
- >- - >-
{{- if eq .Os "linux" }}
{{- if eq .Arch "amd64" }}CC=x86_64-linux-musl-gcc{{- end }}
{{- if eq .Arch "arm64" }}CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++{{- end }}
{{- end }}
{{- if eq .Os "darwin" }} {{- if eq .Os "darwin" }}
{{- if eq .Arch "amd64"}}CC=o64-clang{{- end }} {{- if eq .Arch "amd64"}}CC=o64-clang{{- end }}
{{- if eq .Arch "arm64"}}CC=aarch64-apple-darwin20.2-clang{{- end }} {{- if eq .Arch "arm64"}}CC=oa64-clang{{- end }}
{{- end }} {{- end }}
{{- if eq .Os "linux" }} {{- if eq .Os "windows" }}
{{- if eq .Arch "amd64"}}CC=x86_64-w64-mingw32-gcc{{- end }}
{{- if eq .Arch "arm64"}}CC=aarch64-linux-gnu-gcc{{- end }} {{- if eq .Arch "arm64"}}CC=aarch64-linux-gnu-gcc{{- end }}
{{- if eq .Arch "arm" }}CC=arm-linux-gnueabi-gcc{{- end }}
{{- end }} {{- end }}
goos: goos:
- linux - linux
@ -34,9 +63,22 @@ builds:
#- windows #- windows
goarch: goarch:
- amd64 - amd64
- arm64 #- arm64
- arm # https://go.dev/wiki/MinimumRequirements
goamd64:
- v1
command: build
flags:
- -trimpath
- -tags osusergo,netgo,sqlite_omit_load_extension
ldflags:
# go tool link -help
# go tool compile -help
# -linkmode external
# -extld=$CC
# -fpic 作为动态链接库的时候 需要添加
- -s -w -extldflags '-static' -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=dcross
archives: archives:
- id: "archive1" - id: "archive1"

View File

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
github_action=$1
set -x set -x
function RETVAL() { function RETVAL() {
rt=$1 rt=$1
@ -12,20 +14,21 @@ function RETVAL() {
#当前目录 #当前目录
cpath=$(pwd) cpath=$(pwd)
ver=`cat server/base/app_ver.go | grep APP_VER | awk '{print $3}' | sed 's/"//g'` #ver=`cat server/base/app_ver.go | grep APP_VER | awk '{print $3}' | sed 's/"//g'`
ver=$(cat version)
echo "当前版本 $ver" echo "当前版本 $ver"
echo "编译前端项目" echo "编译前端项目"
cd $cpath/web cd $cpath/web
#国内可替换源加快速度 #国内可替换源加快速度
#npx browserslist@latest --update-db #npx browserslist@latest --update-db
#npm install --registry=https://registry.npm.taobao.org if [ "$github_action" == "github_action" ]; then
#npm install
#npm run build
yarn install --registry=https://registry.npmmirror.com yarn install --registry=https://registry.npmmirror.com
yarn run build else
yarn install
fi
yarn run build
RETVAL $? RETVAL $?
@ -33,11 +36,31 @@ echo "编译二进制文件"
cd $cpath/server cd $cpath/server
rm -rf ui rm -rf ui
cp -rf $cpath/web/ui . cp -rf $cpath/web/ui .
flags="-v -trimpath -extldflags '-static' -tags osusergo,netgo,sqlite_omit_load_extension"
ldflags="-s -w -X main.appVer=$ver -X main.commitId=$(git rev-parse HEAD) -X main.date=$(date --iso-8601=seconds)"
if [ "$github_action" == "github_action" ]; then
echo "github_action"
else
#国内可替换源加快速度 #国内可替换源加快速度
export GOPROXY=https://goproxy.io export GOPROXY=https://goproxy.io
go mod tidy go mod tidy
go build -v -o anylink -trimpath -ldflags "-s -w -X main.CommitId=$(git rev-parse HEAD)" go build -o anylink "$flags" -ldflags "$ldflags"
RETVAL $? exit 0
fi
#github action
go mod tidy
go build -o anylink_amd64 "$flags" -ldflags "$ldflags"
#arm64交叉编译
CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ go build -o anylink_arm64 "$flags" -ldflags "$ldflags"
./anylink_amd64 -v
./anylink_arm64 -v
exit 0
cd $cpath cd $cpath

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
ver=`cat server/base/app_ver.go | grep APP_VER | awk '{print $3}' | sed 's/"//g'` ver=`cat server/base/app_ver.go | grep "APP_VER" | awk '{print $3}' | sed 's/"//g'`
echo $ver echo $ver
#docker login -u bjdgyc #docker login -u bjdgyc

View File

@ -2,6 +2,12 @@ package base
const ( const (
APP_NAME = "AnyLink" APP_NAME = "AnyLink"
// APP_VER app版本号 )
APP_VER = "0.10.2"
var (
// APP_VER app版本号
APP_VER = "0.0.1"
// 提交id
CommitId string
Date string
) )

View File

@ -1,7 +1,6 @@
package base package base
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -17,8 +16,6 @@ import (
) )
var ( var (
// 提交id
CommitId string
// pass明文 // pass明文
passwd string passwd string
// 生成otp // 生成otp
@ -60,6 +57,15 @@ func execute() {
envs[rr.Key().String()] = rr.Value().Index(0).String() envs[rr.Key().String()] = rr.Value().Index(0).String()
} }
//移动配置解析代码
conf := linkViper.GetString("conf")
linkViper.SetConfigFile(conf)
err = linkViper.ReadInConfig()
if err != nil {
// 没有配置文件,直接报错
panic("config file err:" + err.Error())
}
if !runSrv { if !runSrv {
os.Exit(0) os.Exit(0)
} }
@ -106,19 +112,28 @@ func initCmd() {
cobra.OnInitialize(func() { cobra.OnInitialize(func() {
linkViper.AutomaticEnv() linkViper.AutomaticEnv()
conf := linkViper.GetString("conf")
_, err := os.Stat(conf) //ver := linkViper.GetBool("version")
if errors.Is(err, os.ErrNotExist) { //if ver {
// 没有配置文件,不做处理 // printVersion()
panic(err) // os.Exit(0)
} //}
//
linkViper.SetConfigFile(conf) //return
err = linkViper.ReadInConfig() //
if err != nil { //conf := linkViper.GetString("conf")
panic("config file err:" + err.Error()) //_, err := os.Stat(conf)
} //if errors.Is(err, os.ErrNotExist) {
// // 没有配置文件,不做处理
// panic("conf stat err:" + err.Error())
//}
//
//
//linkViper.SetConfigFile(conf)
//err = linkViper.ReadInConfig()
//if err != nil {
// panic("config file err:" + err.Error())
//}
}) })
} }
@ -164,6 +179,6 @@ func initToolCmd() *cobra.Command {
} }
func printVersion() { func printVersion() {
fmt.Printf("%s v%s build on %s [%s, %s] commit_id(%s) \n", fmt.Printf("%s v%s build on %s [%s, %s] %s commit_id(%s)\n",
APP_NAME, APP_VER, runtime.Version(), runtime.GOOS, runtime.GOARCH, CommitId) APP_NAME, APP_VER, runtime.Version(), runtime.GOOS, runtime.GOARCH, Date, CommitId)
} }

View File

@ -20,11 +20,17 @@ import (
var uiData embed.FS var uiData embed.FS
// 程序版本 // 程序版本
var CommitId string var (
appVer string
commitId string
date string
)
func main() { func main() {
base.CommitId = CommitId
admin.UiData = uiData admin.UiData = uiData
base.APP_VER = appVer
base.CommitId = commitId
base.Date = date
base.Start() base.Start()
handler.Start() handler.Start()

1
version Normal file
View File

@ -0,0 +1 @@
0.10.3