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

View File

@ -14,20 +14,28 @@ func Api(group *gin.RouterGroup) {
http.MethodDelete, http.MethodDelete,
http.MethodPut, http.MethodPut,
http.MethodOptions, 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) { return func(ctx *gin.Context) {
path := ctx.Param("path") path := ctx.Param("path")
query := make(map[string]string) query := make(map[string]string)
ctx.ShouldBindQuery(&query) _ = ctx.ShouldBindQuery(&query)
headers := make(map[string]string) headers := make(map[string]string)
ctx.ShouldBindHeader(&headers) _ = ctx.ShouldBindHeader(&headers)
body := make(map[string]any) body := make(map[string]any)
ctx.ShouldBind(&body) _ = ctx.ShouldBind(&body)
data := server.Run(ctx, path, query, body, headers, false) data := server.Run(ctx, path, query, body, headers, logEnable)
ctx.Writer.WriteHeader(200) ctx.Writer.WriteHeader(200)
ctx.Writer.Header().Add("Content-Type", "application/json") ctx.Writer.Header().Add("Content-Type", "application/json")
_, _ = ctx.Writer.WriteString(data) _, _ = ctx.Writer.WriteString(data)

View File

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