Skip to content

Commit 029e967

Browse files
feat: 添加 GitHub Actions workflows
添加了两个 GitHub Actions 工作流: 1. CI Workflow (ci.yml): - 代码检查 (golangci-lint) - 运行测试和覆盖率 - 构建验证 2. Release Workflow (release.yml): - 跨平台构建 (Linux, macOS, Windows) - 支持多架构 (amd64, arm64) - 自动生成 SHA256 校验和 - 自动创建 GitHub Release - 支持 tag 触发自动发布 支持的平台: - Linux: amd64, arm64 - macOS: amd64 (Intel), arm64 (Apple Silicon) - Windows: amd64 使用方法: 1. 推送代码到 main/develop 分支触发 CI 2. 创建 tag (如 v0.2.0) 触发发布流程 git tag v0.2.0 git push origin v0.2.0
1 parent 24298b4 commit 029e967

File tree

2 files changed

+237
-0
lines changed

2 files changed

+237
-0
lines changed

.github/workflows/ci.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
lint:
11+
name: Lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v5
19+
with:
20+
go-version: '1.23'
21+
cache: true
22+
23+
- name: Run golangci-lint
24+
uses: golangci/golangci-lint-action@v6
25+
with:
26+
version: latest
27+
args: --timeout=5m
28+
29+
test:
30+
name: Test
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v4
35+
36+
- name: Set up Go
37+
uses: actions/setup-go@v5
38+
with:
39+
go-version: '1.23'
40+
cache: true
41+
42+
- name: Run tests
43+
run: go test -v -race -coverprofile=coverage.out ./...
44+
45+
- name: Upload coverage
46+
uses: codecov/codecov-action@v4
47+
with:
48+
files: ./coverage.out
49+
fail_ci_if_error: false
50+
51+
build:
52+
name: Build
53+
runs-on: ubuntu-latest
54+
steps:
55+
- name: Checkout code
56+
uses: actions/checkout@v4
57+
58+
- name: Set up Go
59+
uses: actions/setup-go@v5
60+
with:
61+
go-version: '1.23'
62+
cache: true
63+
64+
- name: Build
65+
run: |
66+
make build
67+
./bin/gitlab-cli --version

.github/workflows/release.yml

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
tags: [ 'v*' ]
7+
paths:
8+
- 'cmd/**'
9+
- 'internal/**'
10+
- 'pkg/**'
11+
- 'go.mod'
12+
- 'go.sum'
13+
pull_request:
14+
branches: [ main ]
15+
paths:
16+
- 'cmd/**'
17+
- 'internal/**'
18+
- 'pkg/**'
19+
- 'go.mod'
20+
- 'go.sum'
21+
22+
env:
23+
BINARY_NAME: gitlab-cli
24+
25+
jobs:
26+
build:
27+
name: Build Binary
28+
runs-on: ${{ matrix.os }}
29+
strategy:
30+
matrix:
31+
include:
32+
# Linux
33+
- os: ubuntu-latest
34+
goos: linux
35+
goarch: amd64
36+
artifact_name: gitlab-cli-linux-amd64
37+
- os: ubuntu-latest
38+
goos: linux
39+
goarch: arm64
40+
artifact_name: gitlab-cli-linux-arm64
41+
# macOS
42+
- os: macos-latest
43+
goos: darwin
44+
goarch: amd64
45+
artifact_name: gitlab-cli-darwin-amd64
46+
- os: macos-latest
47+
goos: darwin
48+
goarch: arm64
49+
artifact_name: gitlab-cli-darwin-arm64
50+
# Windows
51+
- os: ubuntu-latest
52+
goos: windows
53+
goarch: amd64
54+
artifact_name: gitlab-cli-windows-amd64.exe
55+
56+
permissions:
57+
contents: read
58+
59+
steps:
60+
- name: Checkout code
61+
uses: actions/checkout@v4
62+
63+
- name: Set up Go
64+
uses: actions/setup-go@v5
65+
with:
66+
go-version: '1.23'
67+
cache: true
68+
69+
- name: Get version info
70+
id: version
71+
run: |
72+
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
73+
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
74+
else
75+
echo "version=dev-${GITHUB_SHA::8}" >> $GITHUB_OUTPUT
76+
fi
77+
echo "commit=${GITHUB_SHA::8}" >> $GITHUB_OUTPUT
78+
echo "date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
79+
80+
- name: Build binary
81+
env:
82+
GOOS: ${{ matrix.goos }}
83+
GOARCH: ${{ matrix.goarch }}
84+
CGO_ENABLED: 0
85+
run: |
86+
go build \
87+
-ldflags="-s -w -X main.Version=${{ steps.version.outputs.version }}" \
88+
-o "${{ matrix.artifact_name }}" \
89+
./cmd/gitlab-cli
90+
91+
- name: Generate checksum
92+
run: |
93+
if [[ "${{ matrix.os }}" == "macos-latest" ]]; then
94+
shasum -a 256 "${{ matrix.artifact_name }}" > "${{ matrix.artifact_name }}.sha256"
95+
else
96+
sha256sum "${{ matrix.artifact_name }}" > "${{ matrix.artifact_name }}.sha256"
97+
fi
98+
99+
- name: Upload artifact
100+
uses: actions/upload-artifact@v4
101+
with:
102+
name: ${{ matrix.artifact_name }}
103+
path: |
104+
${{ matrix.artifact_name }}
105+
${{ matrix.artifact_name }}.sha256
106+
retention-days: 30
107+
108+
release:
109+
name: Create Release
110+
runs-on: ubuntu-latest
111+
needs: build
112+
if: startsWith(github.ref, 'refs/tags/')
113+
114+
permissions:
115+
contents: write
116+
117+
steps:
118+
- name: Checkout code
119+
uses: actions/checkout@v4
120+
121+
- name: Download all artifacts
122+
uses: actions/download-artifact@v4
123+
with:
124+
path: dist/
125+
126+
- name: Prepare release assets
127+
run: |
128+
mkdir -p release
129+
find dist/ -type f -exec cp {} release/ \;
130+
ls -lah release/
131+
132+
- name: Create Release
133+
uses: softprops/action-gh-release@v2
134+
with:
135+
files: release/*
136+
draft: false
137+
prerelease: false
138+
generate_release_notes: true
139+
body: |
140+
## GitLab CLI ${{ github.ref_name }}
141+
142+
GitLab 用户和项目自动化管理工具
143+
144+
### 安装
145+
146+
下载对应平台的二进制文件,解压后即可使用:
147+
148+
```bash
149+
# Linux (amd64)
150+
wget https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/gitlab-cli-linux-amd64
151+
chmod +x gitlab-cli-linux-amd64
152+
sudo mv gitlab-cli-linux-amd64 /usr/local/bin/gitlab-cli
153+
154+
# macOS (arm64, Apple Silicon)
155+
wget https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/gitlab-cli-darwin-arm64
156+
chmod +x gitlab-cli-darwin-arm64
157+
sudo mv gitlab-cli-darwin-arm64 /usr/local/bin/gitlab-cli
158+
```
159+
160+
### 验证安装
161+
162+
```bash
163+
gitlab-cli --version
164+
```
165+
166+
### 文档
167+
168+
- [快速开始](https://github.com/${{ github.repository }}/blob/main/docs/QUICKSTART.md)
169+
- [完整文档](https://github.com/${{ github.repository }}/blob/main/docs/README.md)
170+
- [架构设计](https://github.com/${{ github.repository }}/blob/main/docs/ARCHITECTURE.md)

0 commit comments

Comments
 (0)