修改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"
on:
push:
branches: [ "main", "dev" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main", "dev" ]
workflow_dispatch:
schedule:
- cron: '32 12 * * 5'
# push:
# branches: [ "main", "dev" ]
# pull_request:
# branches: [ "main", "dev" ]
# schedule:
# - cron: '32 12 * * 5'
jobs:
analyze:
@ -39,34 +39,34 @@ jobs:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2

View File

@ -1,8 +1,9 @@
name: go-update
on:
workflow_dispatch:
schedule:
- cron: "1 2 * * 5"
# schedule:
# - cron: "1 2 * * 5"
jobs:
go:
runs-on: ubuntu-latest
@ -26,7 +27,7 @@ jobs:
go get -u
go mod download
- name: Git push
- name: Git push
run: |
git init
git config --local user.name "github-actions[bot]"
@ -38,7 +39,7 @@ jobs:
git commit -m "update go.mod $(date +%Y.%m.%d.%H.%M)"
#git push -f -u origin _autoaction
git push -u origin _autoaction
# 删除无用 workflow runs;
- name: Delete workflow runs
uses: GitRML/delete-workflow-runs@main

View File

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

View File

@ -1,6 +1,7 @@
name: release-tag-version
on:
workflow_dispatch:
push:
tags:
- "v0.*"
@ -9,20 +10,38 @@ jobs:
Build:
name: build-binary
runs-on: ubuntu-latest
env:
TZ: Asia/Shanghai
steps:
- name: Hello world
run: |
uname -a
- uses: actions/checkout@v4
- run: git fetch --unshallow --quiet --tags --force
- uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version-file: 'server/go.mod'
cache-dependency-path: 'server/go.sum'
- uses: actions/setup-node@v4
with:
node-version: '16'
cache: 'yarn'
cache-dependency-path: 'web/yarn.lock'
Docker:
name: build-docker
- # https://github.com/docker/setup-qemu-action
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

3
.gitignore vendored
View File

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

View File

@ -1,32 +1,61 @@
#https://goreleaser.com/static/schema.json
# release --skip=publish
# 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
dist: godist
dist: dist
before:
hooks:
# You may remove this if you don't use go modules.
#- go mod tidy
# you may remove this if you don't need go generate
#- go generate ./...
- pwd
# - cmd: go mod tidy
# dir:
# "{{ dir .Dist}}"
# output: true
# - cmd: go generate
# dir:
# "{{ dir .Dist}}"
# output: true
builds:
- id: "build"
#main: .
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:
- 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 .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 }}
{{- if eq .Os "linux" }}
{{- if eq .Arch "arm64" }}CC=aarch64-linux-gnu-gcc{{- end }}
{{- if eq .Arch "arm" }}CC=arm-linux-gnueabi-gcc{{- end }}
{{- 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 }}
{{- end }}
goos:
- linux
@ -34,9 +63,22 @@ builds:
#- windows
goarch:
- amd64
- arm64
- arm
#- arm64
# 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:
- id: "archive1"

View File

@ -1,5 +1,7 @@
#!/bin/bash
github_action=$1
set -x
function RETVAL() {
rt=$1
@ -12,32 +14,53 @@ function RETVAL() {
#当前目录
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 "编译前端项目"
cd $cpath/web
#国内可替换源加快速度
#npx browserslist@latest --update-db
#npm install --registry=https://registry.npm.taobao.org
#npm install
#npm run build
if [ "$github_action" == "github_action" ]; then
yarn install --registry=https://registry.npmmirror.com
else
yarn install
fi
yarn install --registry=https://registry.npmmirror.com
yarn run build
RETVAL $?
echo "编译二进制文件"
cd $cpath/server
rm -rf ui
cp -rf $cpath/web/ui .
#国内可替换源加快速度
export GOPROXY=https://goproxy.io
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
go mod tidy
go build -o anylink "$flags" -ldflags "$ldflags"
exit 0
fi
#github action
go mod tidy
go build -v -o anylink -trimpath -ldflags "-s -w -X main.CommitId=$(git rev-parse HEAD)"
RETVAL $?
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

View File

@ -1,6 +1,6 @@
#!/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
#docker login -u bjdgyc

View File

@ -2,6 +2,12 @@ package base
const (
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
import (
"errors"
"fmt"
"io"
"os"
@ -17,8 +16,6 @@ import (
)
var (
// 提交id
CommitId string
// pass明文
passwd string
// 生成otp
@ -60,6 +57,15 @@ func execute() {
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 {
os.Exit(0)
}
@ -106,19 +112,28 @@ func initCmd() {
cobra.OnInitialize(func() {
linkViper.AutomaticEnv()
conf := linkViper.GetString("conf")
_, err := os.Stat(conf)
if errors.Is(err, os.ErrNotExist) {
// 没有配置文件,不做处理
panic(err)
}
linkViper.SetConfigFile(conf)
err = linkViper.ReadInConfig()
if err != nil {
panic("config file err:" + err.Error())
}
//ver := linkViper.GetBool("version")
//if ver {
// printVersion()
// os.Exit(0)
//}
//
//return
//
//conf := linkViper.GetString("conf")
//_, 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() {
fmt.Printf("%s v%s build on %s [%s, %s] commit_id(%s) \n",
APP_NAME, APP_VER, runtime.Version(), runtime.GOOS, runtime.GOARCH, CommitId)
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, Date, CommitId)
}

View File

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

1
version Normal file
View File

@ -0,0 +1 @@
0.10.3