Skip to content

Commit 3c264b4

Browse files
committed
feat(ci): add more tests
1 parent 2c73224 commit 3c264b4

6 files changed

Lines changed: 170 additions & 83 deletions

File tree

.github/workflows/libs/lint.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Lint Library
2+
on:
3+
workflow_call:
4+
inputs:
5+
commit_back:
6+
required: true
7+
type: boolean
8+
ref:
9+
required: true
10+
type: string
11+
go-version:
12+
required: false
13+
type: string
14+
default: '^1.25'
15+
fetch-depth:
16+
required: false
17+
type: number
18+
default: 0
19+
submodules:
20+
required: false
21+
type: string
22+
default: 'recursive'
23+
jobs:
24+
golangci:
25+
name: Run Lint
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Set up Go
29+
uses: actions/setup-go@master
30+
with:
31+
go-version: "${{ inputs.go-version }}"
32+
33+
- name: Check out code into the Go module directory
34+
uses: actions/checkout@master
35+
with:
36+
ref: ${{ inputs.ref }}
37+
fetch-depth: ${{ inputs.fetch-depth }}
38+
submodules: ${{ inputs.submodules }}
39+
40+
- name: Prepare Necessary Runtime Files
41+
run: |
42+
go generate main.go
43+
go mod tidy
44+
45+
- name: Run Lint
46+
uses: golangci/golangci-lint-action@master
47+
with:
48+
version: latest
49+
50+
- name: Commit back
51+
if: ${{ inputs.commit_back }}
52+
continue-on-error: true
53+
run: |
54+
git config --local user.name 'github-actions[bot]'
55+
git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com'
56+
git add --all
57+
git commit -m "chore(lint): 改进代码样式"
58+
59+
- name: Create Pull Request
60+
if: ${{ inputs.commit_back }}
61+
continue-on-error: true
62+
uses: peter-evans/create-pull-request@v8
63+
with:
64+
title: "chore(lint): 改进代码样式"

.github/workflows/libs/run.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Run Library
2+
on:
3+
workflow_call:
4+
inputs:
5+
ref:
6+
required: true
7+
type: string
8+
go-version:
9+
required: false
10+
type: string
11+
default: '^1.25'
12+
fetch-depth:
13+
required: false
14+
type: number
15+
default: 0
16+
submodules:
17+
required: false
18+
type: string
19+
default: 'recursive'
20+
jobs:
21+
real_run:
22+
name: Run on ${{ matrix.os }}
23+
runs-on: ${{ matrix.os }}
24+
timeout-minutes: 2
25+
strategy:
26+
matrix:
27+
os: [ubuntu-latest, windows-latest, macos-latest]
28+
fail-fast: true
29+
steps:
30+
- name: Set up Go
31+
uses: actions/setup-go@master
32+
with:
33+
go-version: "${{ inputs.go-version }}"
34+
35+
- name: Check out code into the Go module directory
36+
uses: actions/checkout@master
37+
with:
38+
ref: ${{ inputs.ref }}
39+
fetch-depth: ${{ inputs.fetch-depth }}
40+
submodules: ${{ inputs.submodules }}
41+
42+
- name: Prepare Necessary Runtime Files
43+
run: |
44+
go generate main.go
45+
go mod tidy
46+
47+
- name: Run the Program
48+
shell: bash
49+
run: |
50+
go run main.go > output.log 2>&1 &
51+
PID=$!
52+
FOUND=false
53+
for i in $(seq 1 60); do
54+
if grep -q '\[ws\] 连接到Websocket服务器' output.log 2>/dev/null; then
55+
FOUND=true
56+
break
57+
fi
58+
sleep 1
59+
done
60+
kill $PID 2>/dev/null || true
61+
wait $PID 2>/dev/null || true
62+
if [ "$FOUND" = true ]; then
63+
echo "Success: Found target output"
64+
exit 0
65+
else
66+
echo "Failure: Timeout after 60s without finding target output"
67+
cat output.log
68+
exit 1
69+
fi

.github/workflows/nightly.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: 最新版
22

3-
on: [push, pull_request]
3+
on:
4+
workflow_run:
5+
workflows: [PushLint, PullLint]
6+
types:
7+
- completed
48

59
env:
610
BINARY_PREFIX: "zbp_"
@@ -12,6 +16,7 @@ jobs:
1216
build:
1317
name: Build binary CI
1418
runs-on: ubuntu-latest
19+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
1520
strategy:
1621
matrix:
1722
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/amd64, darwin/arm64
@@ -32,7 +37,7 @@ jobs:
3237
- name: Setup Go environment
3338
uses: actions/setup-go@master
3439
with:
35-
go-version: '1.25'
40+
go-version: '^1.25'
3641
- name: Cache downloaded module
3742
uses: actions/cache@master
3843
continue-on-error: true

.github/workflows/pull.yml

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,16 @@ jobs:
2020
comment: "非法PR. 请`fork`后修改自己的仓库, 而不是向主仓库提交更改. 如果您确信您的PR是为了给主仓库新增功能或修复bug, 请更改默认PR标题. **注意**: 如果您再次触发本提示, 则有可能导致账号被封禁."
2121

2222
golangci:
23-
name: lint
24-
runs-on: ubuntu-latest
25-
steps:
26-
- name: Set up Go
27-
uses: actions/setup-go@master
28-
with:
29-
go-version: '1.24'
30-
31-
- name: Check out code into the Go module directory
32-
uses: actions/checkout@v4
33-
with:
34-
ref: ${{ github.event.pull_request.head.sha }}
35-
fetch-depth: 0
36-
37-
- name: Tidy Modules
38-
run: |
39-
go mod tidy
40-
go generate main.go
41-
42-
- name: golangci-lint
43-
uses: golangci/golangci-lint-action@master
44-
with:
45-
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
46-
version: latest
47-
48-
# Optional: working directory, useful for monorepos
49-
# working-directory: somedir
50-
51-
# Optional: golangci-lint command line arguments.
52-
# args: --issues-exit-code=0
53-
54-
# Optional: show only new issues if it's a pull request. The default value is `false`.
55-
# only-new-issues: true
56-
57-
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
58-
# skip-pkg-cache: true
59-
60-
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
61-
# skip-build-cache: true
23+
needs: close-pr
24+
if: ${{ !contains(github.event.pull_request.title, '.go') }}
25+
uses: ./.github/workflows/libs/lint.yml
26+
with:
27+
ref: ${{ github.event.pull_request.head.sha }}
28+
commit_back: false
29+
30+
runmain:
31+
needs: golangci
32+
if: ${{ !contains(github.event.pull_request.title, '.go') }}
33+
uses: ./.github/workflows/libs/run.yml
34+
with:
35+
ref: ${{ github.event.pull_request.head.sha }}

.github/workflows/push.yml

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,18 @@ on:
33
push:
44
branches:
55
- master
6+
tags:
7+
- 'v*'
68
jobs:
79
golangci:
8-
name: lint
9-
runs-on: ubuntu-latest
10-
steps:
11-
- name: Set up Go
12-
uses: actions/setup-go@master
13-
with:
14-
go-version: '1.25'
10+
uses: ./.github/workflows/libs/lint.yml
11+
with:
12+
ref: master
13+
commit_back: true
1514

16-
- name: Check out code into the Go module directory
17-
uses: actions/checkout@master
18-
with:
19-
ref: master
20-
fetch-depth: 0
21-
submodules: 'recursive'
22-
23-
- name: Prepare Necessary Runtime Files
24-
run: |
25-
go generate main.go
26-
go mod tidy
27-
28-
- name: Run Lint
29-
uses: golangci/golangci-lint-action@master
30-
with:
31-
version: latest
32-
33-
- name: Commit back
34-
if: ${{ !github.head_ref }}
35-
continue-on-error: true
36-
run: |
37-
git config --local user.name 'github-actions[bot]'
38-
git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com'
39-
git add --all
40-
git commit -m "chore(lint): 改进代码样式"
41-
42-
- name: Create Pull Request
43-
if: ${{ !github.head_ref }}
44-
continue-on-error: true
45-
uses: peter-evans/create-pull-request@v8
46-
with:
47-
title: "chore(lint): 改进代码样式"
15+
runmain:
16+
needs: golangci
17+
if: ${{ !contains(github.event.pull_request.title, '.go') }}
18+
uses: ./.github/workflows/libs/run.yml
19+
with:
20+
ref: master

.github/workflows/release.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
name: 发行版
22
on:
3-
push:
4-
tags:
5-
- 'v*'
3+
workflow_run:
4+
workflows: [最新版]
5+
types:
6+
- completed
67

78
jobs:
89
goreleaser:
910
runs-on: ubuntu-latest
11+
if: ${{ github.event.workflow_run.conclusion == 'success' && startsWith(github.event.workflow_run.head_branch, 'v') }}
1012
steps:
1113
- name: Checkout
1214
uses: actions/checkout@master

0 commit comments

Comments
 (0)