boinger/confvis
GitHub: boinger/confvis
将分散的代码质量指标(覆盖率、安全评分、复杂度等)加权聚合为单一综合评分,并提供徽章、仪表盘和 CI 门禁能力。
Stars: 2 | Forks: 0
# confvis [](https://github.com/marketplace/actions/confvis) [](https://pkg.go.dev/github.com/boinger/confvis)
大多数仓库将代码健康度展示为一面由独立的通过/失败徽章组成的墙——CI、覆盖率、安全性、复杂度、技术债务——每一项都在孤立地报告。没有什么能表达哪些信号最重要,或者它们之间有何关联。每次查看 README 或 PR 时,你都要在脑海中权衡十几个指标。
confvis 用显式的加权聚合取而代之。你声明重要的因素——覆盖率、安全评分、复杂度,以及你现有工具已生成的任何指标——为每个因素分配权重和阈值,confvis 会计算出一个综合评分。这种加权是有意为之且受版本控制的,而非隐式的。
输出结果——仪表盘徽章、扁平徽章、迷你趋势图、HTML 仪表板、GitHub PR 检查——都是该评分的产物。使用 `--fail-under` 来基于最低分数设置 CI 门禁,或使用 `--fail-on-regression` 来对比存储的基线并捕捉质量漂移。
**一次加权评估:**
[](./badges/dashboard/index.html)
**而不是独立解读所有这些:**
[](https://github.com/boinger/confvis/actions/workflows/ci.yml)
[](https://codecov.io/gh/boinger/confvis)
[](https://sonarcloud.io/summary/overall?id=boinger_confvis)
[](https://sonarcloud.io/summary/overall?id=boinger_confvis)
[](https://sonarcloud.io/summary/overall?id=boinger_confvis)
[](https://sonarcloud.io/summary/overall?id=boinger_confvis)
[](https://sonarcloud.io/summary/overall?id=boinger_confvis)
[](https://sonarcloud.io/summary/overall?id=boinger_confvis)
[](https://sonarcloud.io/summary/overall?id=boinger_confvis)
[](https://sonarcloud.io/summary/overall?id=boinger_confvis)
[](https://sonarcloud.io/summary/overall?id=boinger_confvis)
[](https://sonarcloud.io/summary/overall?id=boinger_confvis)
[](https://sonarcloud.io/summary/overall?id=boinger_confvis)
[](https://coveralls.io/github/boinger/confvis?branch=main)
[](https://github.com/boinger/confvis/actions/workflows/security.yml)
[](https://github.com/boinger/confvis/security)
[](https://github.com/boinger/confvis/security)
[](https://github.com/boinger/confvis/security)
## 安装
### GitHub Action(推荐用于 CI/CD)
```
- uses: boinger/confvis@v1
with:
config: confidence.json
output: badge.svg
```
查看 [GitHub Action 文档](docs/github-action.md)了解所有选项。
### CLI 安装
```
go install github.com/boinger/confvis/cmd/confvis@latest
```
或者从源码构建:
```
git clone https://github.com/boinger/confvis.git
cd confvis
go build -o confvis ./cmd/confvis
```
验证安装:
```
confvis --version
```
## 快速开始
### 1. 从你的工具获取指标
confvis 从你已在使用的工具中拉取指标:
```
# 从 Codecov 获取覆盖率
export CODECOV_TOKEN=your_token
confvis fetch codecov -p owner/repo -o coverage.json
# 从 SonarQube 获取代码质量 (self-hosted 或 SaaS)
export SONARQUBE_URL=https://sonar.example.com
export SONARQUBE_TOKEN=squ_xxx
confvis fetch sonarqube -p myproject -o quality.json
# 加权聚合并生成徽章 + 仪表盘
confvis aggregate -c coverage.json:60 -c quality.json:40 -o ./output
```
**其他集成:** GitHub Actions, Snyk, Trivy——请参阅 [Sources](docs/sources.md)。
### 2. 理解输出
每个获取的报告包含:
```
{
"title": "Code Coverage",
"score": 87,
"threshold": 80,
"factors": [
{"name": "Line Coverage", "score": 89, "weight": 70},
{"name": "Branch Coverage", "score": 82, "weight": 30}
]
}
```
- **score**: 指标值 (0-100),根据加权因素自动计算
- **threshold**: 最低可接受分数——徽章显示通过/失败状态
- **factors**: 带有权重的贡献指标细分
`aggregate` 命令(来自步骤 1)将多个报告组合成一个加权的总体分数。完整规范请参阅 [Schema Reference](docs/schema.md)。
**自定义指标?** 为 confvis 未直接获取的指标创建你自己的 JSON/YAML。或者编写一个新模块(请发送 PR 给我!)。
### 3. 嵌入到你的 README
```

```
## 配置文件
创建一个 `.confvis.yaml` 来设置默认值并避免重复的标志:
```
gauge:
style: github
fail_under: 80
badge_type: gauge
sources:
sonarqube:
url: https://sonar.example.com
snyk:
org: my-org-id
```
配置从当前目录的 `.confvis.yaml` 或 `~/.config/confvis/` 加载。优先级:配置 < 环境变量 < 标志。
完整文档请参阅 [CLI Reference](docs/cli-reference.md#configuration-file)。
## CI/CD 集成
使用 `confvis gate` 进行仅 CI 的通过/失败门禁(无需生成徽章),或者在你还需要徽章输出时使用 `confvis gauge`。这两个命令都可以通过 [GitHub Action](docs/github-action.md) 使用,通过 `command: gate` 或 `command: gauge` 指定:
```
# CI gate: 如果分数低于 75 则构建失败
confvis gate -c confidence.json --fail-under 75
# 在 main 分支保存基线 (存储在 git ref 中,无需文件)
confvis baseline save -c confidence.json
# CI gate: 与存储的基线相比,若倒退则失败
confvis gate -c confidence.json --fail-on-regression --compare-baseline
# 或者当您还需要徽章时使用 gauge
confvis gauge -c confidence.json --compare-baseline --fail-on-regression -o badge.svg
# 用于清洁 CI 日志的安静模式 (仅退出码)
confvis gate -c confidence.json --fail-under 75 -q
```
在 GitHub Actions 中,`gate` 会自动将 `gate_result=pass|fail` 和 `gate_score=` 写入 `$GITHUB_OUTPUT`,使结果可供下游步骤使用,无需 `continue-on-error`。[GitHub Action](docs/github-action.md) 也将这些暴露为 action 输出(`gate_result`, `gate_score`)以及通用的 `score`/`passed` 映射。
支持 stdin/stdout 用于管道工作流:
```
# 从另一个工具通过管道传入
metrics-tool export | confvis gauge -c - -o badge.svg
# 直接写入 stdout
confvis gauge -c confidence.json -o - > badge.svg
```
## 外部数据源
confvis 可以直接从外部系统获取指标:
```
# 从 SonarQube 获取 (代码质量)
export SONARQUBE_URL=https://sonar.example.com
export SONARQUBE_TOKEN=squ_xxx
confvis fetch sonarqube -p myproject -o confidence.json
# 从 Codecov 获取 (覆盖率)
export CODECOV_TOKEN=xxx
confvis fetch codecov -p myorg/myrepo -o confidence.json
# 从 GitHub Actions 获取 (CI/CD)
export GITHUB_TOKEN=xxx
confvis fetch github-actions -p myorg/myrepo -o confidence.json
# 从 Snyk 获取 (安全)
export SNYK_TOKEN=xxx
confvis fetch snyk --org my-org-id -p my-project-id -o confidence.json
# 从 Trivy 获取 (本地安全扫描)
confvis fetch trivy -p . -o security.json
# 直接通过管道传送到徽章生成
confvis fetch sonarqube -p myproject -o - | confvis gauge -c - -o badge.svg
```
有关可用数据源及其配置的详细信息,请参阅 [Sources Documentation](docs/sources.md)。
## 命令
### `confvis fetch`
从外部数据源获取指标。
```
confvis fetch -p -o
标签:Anchore, API集成, EVTX分析, GitHub Actions, GitHub Marketplace, Go, Homebrew安装, Ruby工具, 云安全监控, 互联网扫描, 代码健康度, 代码复杂度, 可观测性, 可视化仪表盘, 多模态安全, 安全评分, 工程生产力, 度量聚合, 开源框架, 徽章生成, 技术债务, 持续集成, 数据管道, 日志审计, 测试覆盖率, 自动笔记, 质量门禁, 趋势分析, 软件工程, 软件开发, 重构, 静态分析