添加功能
CI / Build binary CI (push) Successful in 11s Details
docker build / build (push) Successful in 44m3s Details

This commit is contained in:
huoxue1 2023-09-05 19:35:54 +08:00
parent c77704d26f
commit 9f25a90ae5
7 changed files with 69 additions and 117 deletions

47
.gitea/workflows/ci.yml Normal file
View File

@ -0,0 +1,47 @@
name: CI
on: [push, pull_request]
env:
BINARY_PREFIX: "qinglong-go_"
BINARY_SUFFIX: ""
COMMIT_ID: "${{ github.sha }}"
PR_PROMPT: "::warning:: Build artifact will not be uploaded due to the workflow is trigged by pull request."
LD_FLAGS: "-w -s"
VERSION: "action"
HTTP_PROXY: "http://172.17.0.1:7890"
HTTPS_PROXY: "http://172.17.0.1:7890"
GOPROXY: "https://goproxy.cn,direct"
jobs:
build:
name: Build binary CI
runs-on: ubuntu-latest
container:
image: node:16-bullseye
# 持久化工具目录
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: setup go
uses: https://github.com/actions/setup-go@v4
with:
go-version: '1.20'
- name: Fetch all tags
run: git fetch --force --tags
- name: Run GoReleaser
uses: https://huoxue.link:12300/huoxue1/goreleaser-action@master
with:
version: latest
args: build --snapshot
env:
GITEA_TOKEN: ${{ secrets.TOKEN }}
# - name: upload-artifact
# uses: actions/upload-artifact@v3
# with:
# name: my-artifact
# path: dist/*/*

View File

@ -1,64 +0,0 @@
name: CI
on: [push, pull_request]
env:
BINARY_PREFIX: "qinglong-go_"
BINARY_SUFFIX: ""
COMMIT_ID: "${{ github.sha }}"
PR_PROMPT: "::warning:: Build artifact will not be uploaded due to the workflow is trigged by pull request."
LD_FLAGS: "-w -s"
VERSION: "action"
jobs:
build:
name: Build binary CI
runs-on: ubuntu-latest
strategy:
matrix:
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/amd64, darwin/arm64
goos: [linux, windows, darwin]
goarch: ["386", amd64, arm, arm64]
exclude:
- goos: darwin
goarch: arm
- goos: darwin
goarch: "386"
- goos: windows
goarch: arm64
- goos: windows
goarch: arm
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Fetch all tags
run: git fetch --force --tags
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.20"
- name: Build binary file
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
IS_PR: ${{ !!github.head_ref }}
CGO_ENABLED: 0
run: |
if [ $GOOS = "windows" ]; then export BINARY_SUFFIX="$BINARY_SUFFIX.exe"; fi
if $IS_PR ; then echo $PR_PROMPT; fi
export BINARY_NAME="$BINARY_PREFIX$GOOS_$GOARCH$BINARY_SUFFIX"
export LD_FLAGS="-w -s -X github.com/huoxue1/qinglong-go/service/config.VERSION=${VERSION}"
go mod tidy
go build -o "output/$BINARY_NAME" -trimpath -ldflags "$LD_FLAGS" ./
- name: Upload artifact
uses: actions/upload-artifact@v2
if: ${{ !github.head_ref }}
with:
name: ${{ matrix.goos }}_${{ matrix.goarch }}
path: output/

View File

@ -11,21 +11,9 @@ builds:
- GO111MODULE=on
goos:
- linux
- darwin
goarch:
- 386
- amd64
- arm
- arm64
goarm:
- 7
ignore:
- goos: darwin
goarch: arm
- goos: darwin
goarch: 386
- goos: windows
goarch: arm
mod_timestamp: "{{ .CommitTimestamp }}"
flags:
- -trimpath
@ -38,34 +26,12 @@ builds:
goos:
- windows
goarch:
- 386
- amd64
goarm:
- 7
mod_timestamp: "{{ .CommitTimestamp }}"
flags:
- -trimpath
ldflags:
- -s -w -X github.com/huoxue1/qinglong-go/service/config.VERSION.VERSION=v{{.Version}}
- id: docker
env:
- CGO_ENABLED=0
- GO111MODULE=on
goos:
- linux
goarch:
- 386
- amd64
- arm
- arm64
goarm:
- 7
mod_timestamp: "{{ .CommitTimestamp }}"
flags:
- -trimpath
ldflags:
- -s -w -X github.com/huoxue1/qinglong-go/service/config.VERSION.VERSION=v{{.Version}}
checksum:
name_template: "{{ .ProjectName }}_checksums.txt"
changelog:
@ -97,14 +63,9 @@ archives:
- goos: windows
format: zip
nfpms:
- license: AGPL 3.0
homepage: https://github.com/johlanse/study_xxqg
file_name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
formats:
- deb
- rpm
maintainer: johlanse
builds:
- nowin
- win
release:
gitea:
owner: "huoxue1"
name: "qinglong-go"
name_template: "{{.ProjectName}}-v{{.Version}} {{.Env.USER}}"
disable: false

View File

@ -14,20 +14,28 @@ func Api(group *gin.RouterGroup) {
http.MethodDelete,
http.MethodPut,
http.MethodOptions,
}, "/:path", handle())
}, "/:path", handle(false))
group.Match([]string{
http.MethodGet,
http.MethodPost,
http.MethodDelete,
http.MethodPut,
http.MethodOptions,
}, "/log/:path", handle(true))
}
func handle() gin.HandlerFunc {
func handle(logEnable bool) gin.HandlerFunc {
return func(ctx *gin.Context) {
path := ctx.Param("path")
query := make(map[string]string)
ctx.ShouldBindQuery(&query)
_ = ctx.ShouldBindQuery(&query)
headers := make(map[string]string)
ctx.ShouldBindHeader(&headers)
_ = ctx.ShouldBindHeader(&headers)
body := make(map[string]any)
ctx.ShouldBind(&body)
data := server.Run(ctx, path, query, body, headers, false)
_ = ctx.ShouldBind(&body)
data := server.Run(ctx, path, query, body, headers, logEnable)
ctx.Writer.WriteHeader(200)
ctx.Writer.Header().Add("Content-Type", "application/json")
_, _ = ctx.Writer.WriteString(data)

View File

@ -97,8 +97,8 @@ func RunWithOption(ctx context.Context, option *RunOption) {
ch <- 1
return
}
go io.Copy(option.LogFile, stderrPipe)
go io.Copy(option.LogFile, stdoutPipe)
io.Copy(option.LogFile, stderrPipe)
io.Copy(option.LogFile, stdoutPipe)
err = cmd.Wait()
if err != nil {
ch <- 1