Skip to content

Commit 4e35911

Browse files
committed
追加些其他功能比如是否在git项目里
1 parent 25f74db commit 4e35911

File tree

20 files changed

+1831
-162
lines changed

20 files changed

+1831
-162
lines changed

.github/workflows/release.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: create-release
2+
3+
on:
4+
push:
5+
branches:
6+
- main # 监听 main 分支的 push 操作(编译和测试/代码检查)
7+
tags:
8+
- 'v*' # 监听以 'v' 开头的标签的 push 操作(发布 Release)
9+
10+
jobs:
11+
lint:
12+
name: lint
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-go@v5
17+
with:
18+
go-version: stable
19+
cache: true
20+
- name: golangci-lint
21+
uses: golangci/golangci-lint-action@v8
22+
with:
23+
version: latest
24+
args: --timeout=5m
25+
26+
test:
27+
runs-on: ubuntu-latest
28+
strategy:
29+
matrix:
30+
go: [ "1.22.x", "1.23.x", "1.24.x", "stable" ]
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- uses: actions/setup-go@v5
35+
with:
36+
go-version: ${{ matrix.go }}
37+
cache: true
38+
39+
- name: Run govulncheck
40+
uses: golang/govulncheck-action@v1
41+
with:
42+
go-version-input: ${{ matrix.go }}
43+
go-package: ./...
44+
continue-on-error: true # 报错时允许工作流继续执行,因为项目依赖的底层包也会有错,很难做到百分百没问题,只打印检测结果就行
45+
46+
- name: Run test
47+
run: make test COVERAGE_DIR=/tmp/coverage
48+
49+
- name: Upload test results
50+
uses: actions/upload-artifact@v4
51+
if: always()
52+
with:
53+
name: test-results-${{ matrix.go }}
54+
path: /tmp/coverage/
55+
retention-days: 30
56+
57+
- name: Send goveralls coverage
58+
uses: shogo82148/actions-goveralls@v1
59+
with:
60+
path-to-profile: /tmp/coverage/combined.txt
61+
flag-name: Go-${{ matrix.go }}
62+
parallel: true
63+
if: ${{ github.event.repository.fork == false }} # 仅在非 fork 时上传覆盖率
64+
65+
check-coverage:
66+
name: Check coverage
67+
needs: [ test ]
68+
runs-on: ubuntu-latest
69+
steps:
70+
- uses: shogo82148/actions-goveralls@v1
71+
with:
72+
parallel-finished: true
73+
if: ${{ github.event.repository.fork == false }} # 仅在非 fork 时检查覆盖率
74+
75+
# 代码质量分析
76+
code-analysis:
77+
name: CodeQL Analysis
78+
runs-on: ubuntu-latest
79+
permissions:
80+
actions: read
81+
contents: read
82+
security-events: write
83+
steps:
84+
- name: Checkout repository
85+
uses: actions/checkout@v4
86+
87+
- name: Initialize CodeQL
88+
uses: github/codeql-action/init@v3
89+
with:
90+
languages: go
91+
92+
- name: Auto Build
93+
uses: github/codeql-action/autobuild@v3
94+
95+
- name: Perform CodeQL Analysis
96+
uses: github/codeql-action/analyze@v3
97+
98+
# 发布 Release
99+
release:
100+
name: Release a new version
101+
needs: [ lint, test, check-coverage, code-analysis ]
102+
runs-on: ubuntu-latest
103+
# 仅在推送标签时执行 - && - 仅在非 fork 时执行发布
104+
if: ${{ github.event.repository.fork == false && success() && startsWith(github.ref, 'refs/tags/v') }}
105+
steps:
106+
# 1. 检出代码
107+
- name: Checkout code
108+
uses: actions/checkout@v4
109+
with:
110+
fetch-depth: 0 # 获取完整历史用于生成更好的 release notes
111+
112+
# 2. 创建 Release 和上传源码包
113+
- name: Create Release
114+
uses: softprops/action-gh-release@v2
115+
with:
116+
generate_release_notes: true
117+
env:
118+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 golang-X-language
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
COVERAGE_DIR ?= .coverage.out
2+
3+
# cp from: https://github.com/yyle88/gormrepo/blob/c31435669714611c9ebde6975060f48cd5634451/Makefile#L4
4+
test:
5+
@if [ -d $(COVERAGE_DIR) ]; then rm -r $(COVERAGE_DIR); fi
6+
@mkdir $(COVERAGE_DIR)
7+
make test-with-flags TEST_FLAGS='-v -race -covermode atomic -coverprofile $$(COVERAGE_DIR)/combined.txt -bench=. -benchmem -timeout 20m'
8+
9+
test-with-flags:
10+
@go test $(TEST_FLAGS) ./...

0 commit comments

Comments
 (0)