Skip to content

Commit b130f82

Browse files
committed
给项目添加批处理的命令行工具
1 parent cc6564d commit b130f82

File tree

9 files changed

+372
-39
lines changed

9 files changed

+372
-39
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 }}

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) ./...

README.md

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,47 @@
1+
[![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/go-xlan/clang-format/release.yml?branch=main&label=BUILD)](https://github.com/go-xlan/clang-format/actions/workflows/release.yml?query=branch%3Amain)
2+
[![GoDoc](https://pkg.go.dev/badge/github.com/go-xlan/clang-format)](https://pkg.go.dev/github.com/go-xlan/clang-format)
3+
[![Coverage Status](https://img.shields.io/coveralls/github/go-xlan/clang-format/main.svg)](https://coveralls.io/github/go-xlan/clang-format?branch=main)
4+
[![Supported Go Versions](https://img.shields.io/badge/Go-1.22-lightgrey.svg)](https://go.dev/)
5+
[![GitHub Release](https://img.shields.io/github/release/go-xlan/clang-format.svg)](https://github.com/go-xlan/clang-format/releases)
6+
[![Go Report Card](https://goreportcard.com/badge/github.com/go-xlan/clang-format)](https://goreportcard.com/report/github.com/go-xlan/clang-format)
7+
18
# clang-format
29

3-
Go wrapper for clang-format with Protocol Buffers formatting capabilities.
10+
Go package for clang-format with Protocol Buffers and C/C++ batch formatting capabilities.
411

512
---
613

14+
<!-- TEMPLATE (EN) BEGIN: LANGUAGE NAVIGATION -->
715
## CHINESE README
816

917
[中文说明](README.zh.md)
18+
<!-- TEMPLATE (EN) END: LANGUAGE NAVIGATION -->
1019

1120
## Key Features
1221

13-
🎯 **Intelligent Proto Formatting**: Smart clang-format wrapper with Google style defaults
14-
**Dual Operation Modes**: Both preview (DryRun) and in-place formatting support
22+
🎯 **Intelligent Proto Formatting**: Smart clang-format package with Google style defaults
23+
**Two Operation Modes**: Both preview (DryRun) and in-place formatting support
1524
🔄 **Batch Processing**: Recursive project-wide .proto file formatting
1625
🌍 **Configurable Styles**: Customizable formatting styles with JSON configuration
1726
📋 **Comprehensive Logging**: Detailed operation logs with structured output
1827

19-
## Install
28+
## Installation
29+
30+
### Get the Package
2031

2132
```bash
22-
go install github.com/go-xlan/clang-format@latest
33+
go get github.com/go-xlan/clang-format@latest
34+
```
35+
36+
### Get CLI Command
37+
38+
```bash
39+
go install github.com/go-xlan/clang-format/cmd/clang-format-batch@latest
2340
```
2441

2542
## Prerequisites
2643

27-
Install clang-format on your system:
44+
Setup clang-format as requirement:
2845

2946
```bash
3047
# macOS
@@ -37,7 +54,25 @@ sudo apt-get install clang-format
3754
clang-format --version
3855
```
3956

40-
## Usage
57+
## Quick Start
58+
59+
### Command Line Usage
60+
61+
```bash
62+
# Format all .proto files in current project
63+
clang-format-batch --extensions=".proto"
64+
65+
# Format C/C++ files
66+
clang-format-batch --extensions=".c,.cpp,.h"
67+
68+
# Format multiple file types
69+
clang-format-batch --extensions=".proto,.c,.cpp,.h"
70+
71+
# Use short flag
72+
clang-format-batch -e ".proto,.cc,.hh"
73+
```
74+
75+
## Library Usage
4176

4277
### Protocol Buffers Formatting (Primary Use Case)
4378

@@ -97,7 +132,7 @@ must.Done(clangformat.Format(execConfig, "example.cpp", style))
97132

98133
- `NewStyle()` - Creates default Google-based style configuration
99134
- `DryRun(config, path, style)` - Preview formatting without file modification
100-
- `Format(config, path, style)` - Apply formatting directly to file
135+
- `Format(config, path, style)` - Use formatting on file
101136

102137
### protoformat Package
103138

@@ -111,13 +146,14 @@ must.Done(clangformat.Format(execConfig, "example.cpp", style))
111146
```go
112147
type Style struct {
113148
BasedOnStyle string // "Google", "LLVM", "Chromium", etc.
114-
IndentWidth int // Number of spaces for indentation
149+
IndentWidth int // Count of spaces for indentation
115150
ColumnLimit int // Maximum line length (0 = no limit)
116-
AlignConsecutiveAssignments bool // Align assignments at equal signs
151+
AlignConsecutiveAssignments bool // Align assignments at assignment signs
117152
}
118153
```
119154

120155
<!-- TEMPLATE (EN) BEGIN: STANDARD PROJECT FOOTER -->
156+
<!-- VERSION 2025-09-06 04:53:24.895249 +0000 UTC -->
121157

122158
## 📄 License
123159

@@ -132,26 +168,26 @@ Contributions are welcome! Report bugs, suggest features, and contribute code:
132168
- 🐛 **Found a bug?** Open an issue on GitHub with reproduction steps
133169
- 💡 **Have a feature idea?** Create an issue to discuss the suggestion
134170
- 📖 **Documentation confusing?** Report it so we can improve
135-
- 🚀 **Need new features?** Share your use cases to help us understand requirements
136-
-**Performance issue?** Help us optimize by reporting slow operations
171+
- 🚀 **Need new features?** Share the use cases to help us understand requirements
172+
-**Performance issue?** Help us optimize through reporting slow operations
137173
- 🔧 **Configuration problem?** Ask questions about complex setups
138-
- 📢 **Follow project progress?** Watch the repo for new releases and features
139-
- 🌟 **Success stories?** Share how this package improved your workflow
140-
- 💬 **General feedback?** All suggestions and comments are welcome
174+
- 📢 **Follow project progress?** Watch the repo to get new releases and features
175+
- 🌟 **Success stories?** Share how this package improved the workflow
176+
- 💬 **Feedback?** We welcome suggestions and comments
141177

142178
---
143179

144180
## 🔧 Development
145181

146182
New code contributions, follow this process:
147183

148-
1. **Fork**: Fork the repo on GitHub (using the webpage interface).
184+
1. **Fork**: Fork the repo on GitHub (using the webpage UI).
149185
2. **Clone**: Clone the forked project (`git clone https://github.com/yourname/repo-name.git`).
150186
3. **Navigate**: Navigate to the cloned project (`cd repo-name`)
151187
4. **Branch**: Create a feature branch (`git checkout -b feature/xxx`).
152-
5. **Code**: Implement your changes with comprehensive tests
188+
5. **Code**: Implement the changes with comprehensive tests
153189
6. **Testing**: (Golang project) Ensure tests pass (`go test ./...`) and follow Go code style conventions
154-
7. **Documentation**: Update documentation for user-facing changes and use meaningful commit messages
190+
7. **Documentation**: Update documentation to support client-facing changes and use significant commit messages
155191
8. **Stage**: Stage changes (`git add .`)
156192
9. **Commit**: Commit changes (`git commit -m "Add feature xxx"`) ensuring backward compatible code
157193
10. **Push**: Push to the branch (`git push origin feature/xxx`).
@@ -163,7 +199,7 @@ Please ensure tests pass and include relevant documentation updates.
163199

164200
## 🌟 Support
165201

166-
Welcome to contribute to this project by submitting pull requests and reporting issues.
202+
Welcome to contribute to this project via submitting merge requests and reporting issues.
167203

168204
**Project Support:**
169205

@@ -172,7 +208,7 @@ Welcome to contribute to this project by submitting pull requests and reporting
172208
- 📝 **Write tech blogs** about development tools and workflows - we provide content writing support
173209
- 🌟 **Join the ecosystem** - committed to supporting open source and the (golang) development scene
174210

175-
**Happy Coding with this package!** 🎉
211+
**Have Fun Coding with this package!** 🎉
176212

177213
<!-- TEMPLATE (EN) END: STANDARD PROJECT FOOTER -->
178214

README.zh.md

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,47 @@
1+
[![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/go-xlan/clang-format/release.yml?branch=main&label=BUILD)](https://github.com/go-xlan/clang-format/actions/workflows/release.yml?query=branch%3Amain)
2+
[![GoDoc](https://pkg.go.dev/badge/github.com/go-xlan/clang-format)](https://pkg.go.dev/github.com/go-xlan/clang-format)
3+
[![Coverage Status](https://img.shields.io/coveralls/github/go-xlan/clang-format/main.svg)](https://coveralls.io/github/go-xlan/clang-format?branch=main)
4+
[![Supported Go Versions](https://img.shields.io/badge/Go-1.22-lightgrey.svg)](https://go.dev/)
5+
[![GitHub Release](https://img.shields.io/github/release/go-xlan/clang-format.svg)](https://github.com/go-xlan/clang-format/releases)
6+
[![Go Report Card](https://goreportcard.com/badge/github.com/go-xlan/clang-format)](https://goreportcard.com/report/github.com/go-xlan/clang-format)
7+
18
# clang-format
29

3-
clang-format 的 Go 封装工具,专为 Protocol Buffers 格式化而设计。
10+
clang-format 的 Go 封装工具,支持 Protocol Buffers 和 C/C++ 批量格式化功能。
11+
12+
---
413

14+
<!-- TEMPLATE (ZH) BEGIN: LANGUAGE NAVIGATION -->
515
## 英文文档
616

717
[ENGLISH README](README.md)
18+
<!-- TEMPLATE (ZH) END: LANGUAGE NAVIGATION -->
819

920
## 核心特性
1021

11-
🎯 **智能 Proto 格式化**: 智能的 clang-format 包装器,默认使用 Google 样式
12-
**双重操作模式**: 支持预览(DryRun)和就地格式化两种模式
22+
🎯 **智能 Proto 格式化**: 智能的 clang-format ,默认使用 Google 样式
23+
**两种操作模式**: 支持预览(DryRun)和就地格式化两种模式
1324
🔄 **批量处理**: 递归的项目级 .proto 文件格式化
1425
🌍 **可配置样式**: 支持 JSON 配置的自定义格式化样式
1526
📋 **全面日志**: 详细的操作日志和结构化输出
1627

1728
## 安装
1829

30+
### 获取包
31+
32+
```bash
33+
go get github.com/go-xlan/clang-format@latest
34+
```
35+
36+
### 获取 CLI 命令
37+
1938
```bash
20-
go install github.com/go-xlan/clang-format@latest
39+
go install github.com/go-xlan/clang-format/cmd/clang-format-batch@latest
2140
```
2241

2342
## 前置要求
2443

25-
在系统中安装 clang-format:
44+
作为必要条件配置 clang-format:
2645

2746
```bash
2847
# macOS
@@ -35,7 +54,25 @@ sudo apt-get install clang-format
3554
clang-format --version
3655
```
3756

38-
## 使用方法
57+
## 快速开始
58+
59+
### 命令行使用
60+
61+
```bash
62+
# 格式化当前项目中的所有 .proto 文件
63+
clang-format-batch --extensions=".proto"
64+
65+
# 格式化 C/C++ 文件
66+
clang-format-batch --extensions=".c,.cpp,.h"
67+
68+
# 格式化多种文件类型
69+
clang-format-batch --extensions=".proto,.c,.cpp,.h"
70+
71+
# 使用短标志
72+
clang-format-batch -e ".proto,.cc,.hh"
73+
```
74+
75+
## 库使用方法
3976

4077
### Protocol Buffers 格式化(主要功能)
4178

@@ -116,6 +153,7 @@ type Style struct {
116153
```
117154

118155
<!-- TEMPLATE (ZH) BEGIN: STANDARD PROJECT FOOTER -->
156+
<!-- VERSION 2025-09-06 04:53:24.895249 +0000 UTC -->
119157

120158
## 📄 许可证类型
121159

@@ -135,7 +173,7 @@ MIT 许可证。详见 [LICENSE](LICENSE)。
135173
- 🔧 **配置困扰?** 询问复杂设置的相关问题
136174
- 📢 **关注进展?** 关注仓库以获取新版本和功能
137175
- 🌟 **成功案例?** 分享这个包如何改善工作流程
138-
- 💬 **意见反馈** 欢迎所有建议和宝贵意见
176+
- 💬 **反馈意见** 欢迎提出建议和意见
139177

140178
---
141179

@@ -170,7 +208,7 @@ MIT 许可证。详见 [LICENSE](LICENSE)。
170208
- 📝 **撰写博客**关于开发工具和工作流程 - 我们提供写作支持
171209
- 🌟 **加入生态** - 致力于支持开源和(golang)开发场景
172210

173-
**使用这个包快乐编程** 🎉
211+
**使用这个包编程快乐** 🎉
174212

175213
<!-- TEMPLATE (ZH) END: STANDARD PROJECT FOOTER -->
176214

0 commit comments

Comments
 (0)