boinger/confvis

GitHub: boinger/confvis

将分散的代码质量指标(覆盖率、安全评分、复杂度等)加权聚合为单一综合评分,并提供徽章、仪表盘和 CI 门禁能力。

Stars: 2 | Forks: 0

# confvis [![GitHub Marketplace](https://img.shields.io/badge/Marketplace-confvis-blue?logo=github)](https://github.com/marketplace/actions/confvis) [![Go Reference](https://pkg.go.dev/badge/github.com/boinger/confvis.svg)](https://pkg.go.dev/github.com/boinger/confvis) 大多数仓库将代码健康度展示为一面由独立的通过/失败徽章组成的墙——CI、覆盖率、安全性、复杂度、技术债务——每一项都在孤立地报告。没有什么能表达哪些信号最重要,或者它们之间有何关联。每次查看 README 或 PR 时,你都要在脑海中权衡十几个指标。 confvis 用显式的加权聚合取而代之。你声明重要的因素——覆盖率、安全评分、复杂度,以及你现有工具已生成的任何指标——为每个因素分配权重和阈值,confvis 会计算出一个综合评分。这种加权是有意为之且受版本控制的,而非隐式的。 输出结果——仪表盘徽章、扁平徽章、迷你趋势图、HTML 仪表板、GitHub PR 检查——都是该评分的产物。使用 `--fail-under` 来基于最低分数设置 CI 门禁,或使用 `--fail-on-regression` 来对比存储的基线并捕捉质量漂移。 **一次加权评估:** [![confvis](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/445d823ffa063812.svg)](./badges/dashboard/index.html) **而不是独立解读所有这些:** [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/89f7ea349e063813.svg)](https://github.com/boinger/confvis/actions/workflows/ci.yml) [![Coverage](https://codecov.io/gh/boinger/confvis/graph/badge.svg)](https://codecov.io/gh/boinger/confvis) [![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=boinger_confvis&metric=alert_status)](https://sonarcloud.io/summary/overall?id=boinger_confvis) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=boinger_confvis&metric=security_rating)](https://sonarcloud.io/summary/overall?id=boinger_confvis) [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=boinger_confvis&metric=reliability_rating)](https://sonarcloud.io/summary/overall?id=boinger_confvis) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=boinger_confvis&metric=sqale_rating)](https://sonarcloud.io/summary/overall?id=boinger_confvis) [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=boinger_confvis&metric=vulnerabilities)](https://sonarcloud.io/summary/overall?id=boinger_confvis) [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=boinger_confvis&metric=bugs)](https://sonarcloud.io/summary/overall?id=boinger_confvis) [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=boinger_confvis&metric=code_smells)](https://sonarcloud.io/summary/overall?id=boinger_confvis) [![Duplicated Lines](https://sonarcloud.io/api/project_badges/measure?project=boinger_confvis&metric=duplicated_lines_density)](https://sonarcloud.io/summary/overall?id=boinger_confvis) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=boinger_confvis&metric=ncloc)](https://sonarcloud.io/summary/overall?id=boinger_confvis) [![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=boinger_confvis&metric=sqale_index)](https://sonarcloud.io/summary/overall?id=boinger_confvis) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=boinger_confvis&metric=coverage)](https://sonarcloud.io/summary/overall?id=boinger_confvis) [![Coveralls](https://coveralls.io/repos/github/boinger/confvis/badge.svg?branch=main)](https://coveralls.io/github/boinger/confvis?branch=main) [![CodeQL](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/f6a2f5daad063815.svg)](https://github.com/boinger/confvis/actions/workflows/security.yml) [![Gosec](https://img.shields.io/badge/gosec-passing-brightgreen?logo=go)](https://github.com/boinger/confvis/security) [![GitLeaks](https://img.shields.io/badge/gitleaks-passing-brightgreen?logo=git)](https://github.com/boinger/confvis/security) [![TruffleHog](https://img.shields.io/badge/trufflehog-passing-brightgreen?logo=git)](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 ``` ![Confidence](https://raw.githubusercontent.com/boinger/confvis/main/badge.svg) ``` ## 配置文件 创建一个 `.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 [source-specific-flags] ``` 支持的数据源:`codecov`, `dependabot`, `github-actions`, `grype`, `semgrep`, `snyk`, `sonarqube`, `trivy` ### `confvis generate` 同时生成 SVG 徽章和 HTML 仪表板。 ``` confvis generate -c confidence.json -o ./output [--dark] ``` 创建: - `output/badge.svg` - SVG 仪表盘徽章 - `output/dashboard/index.html` - 交互式 HTML 仪表板 ### `confvis gauge` 生成各种格式的仪表盘徽章。 ``` confvis gauge -c confidence.json -o badge.svg [--format svg|json|text|markdown|github-comment] [--badge-type gauge|flat] [--style github|minimal|corporate|high-contrast] [--dark] ``` 输出格式(默认:stdout 为 `text`,文件为 `svg`): - `svg`: SVG 仪表盘徽章图像 - `json`: 分数元数据 JSON - `text`: 仅分数数字(用于脚本) - `markdown`: 用于 PR 评论的 Markdown 表格 - `github-comment`: 带有 emoji 和可折叠部分的 GitHub 风格 Markdown 徽章类型: - `gauge`(默认):半圆形仪表盘 - `flat`: 兼容 Shields.io 的矩形徽章(支持 `--icon` 用于 SVG 路径数据) - `sparkline`: 显示分数历史的趋势线(使用 `--history-auto` 自动持久化) 示例迷你趋势图(此仓库的分数趋势): ![Trend](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/50965226ac063817.svg) 颜色风格:`github`(默认)、`minimal`、`corporate`、`high-contrast` ### `confvis gate` CI 门禁:检查阈值并在失败时以非零状态退出。不生成徽章——专为 CI 通过/失败门禁构建。 ``` # 如果分数低于阈值则失败 confvis gate -c confidence.json --fail-under 85 # 相对于基线倒退则失败 confvis gate -c confidence.json --fail-on-regression --compare-baseline # 组合:阈值 + 倒退 + 按因子 confvis gate -c confidence.json --fail-under 75 \ --fail-on-regression --compare-baseline \ --factor-threshold "Coverage:80" ``` 至少需要一个阈值标志(`--fail-under`、`--fail-on-regression` 或 `--factor-threshold`)。使用 `-q` 仅输出退出码,或 `-v` 查看按因素的细分。 ### `confvis aggregate` 将多个报告聚合成一个带有加权分数的单一仪表板。 ``` # 聚合多个报告 confvis aggregate -c api/confidence.json -c web/confidence.json -o ./output # 使用自定义权重 confvis aggregate -c api/confidence.json:60 -c web/confidence.json:40 -o ./output # 使用 glob patterns (monorepo) confvis aggregate -c "services/*/confidence.json" -o ./output ``` 创建: - `output/badge.svg` - 聚合 SVG 仪表盘徽章 - `output/dashboard/index.html` - 包含所有组件的多报告仪表板 - `output/.svg` - 每个报告的独立徽章 使用 `--fragment` 生成可嵌入的 HTML 片段(无 DOCTYPE 包装),用于 Confluence 或其他系统。 有关带有嵌入说明的工作示例,请参阅 [examples/dashboard](examples/dashboard)。 ### `confvis baseline` 管理用于 CI/CD 回归检测的基线。 ``` # 将当前分数保存为基线 (默认存储在 git ref 中) confvis baseline save -c confidence.json # 显示当前基线 confvis baseline show # 保存到文件而不是 git ref confvis baseline save -c confidence.json --file baseline.json ``` 将 `--compare-baseline` 与 `confvis gauge` 一起使用,以自动获取并与存储的基线进行比较。 ### `confvis check` 直接从 confidence 报告在 CI 平台上创建检查运行(check runs)。 ``` # 从 GitHub Actions 环境自动检测 confvis check github -c confidence.json # 显式选项 confvis check github -c confidence.json \ --owner myorg --repo myrepo --sha abc123 \ --token $GITHUB_TOKEN # 自定义检查名称 confvis check github -c confidence.json --name "Code Quality" ``` 在 GitHub Actions 中,大多数选项会从环境变量自动检测。需要 `checks: write` 权限。 ## JSON Schema | 字段 | 类型 | 必需 | 描述 | |-------|------|----------|-------------| | `title` | string | Yes | 报告标题 | | `score` | int | No* | 总体分数 (0-100),如果省略则自动计算 | | `threshold` | int | Yes | 最低通过分数 | | `description` | string | No | 报告描述 | | `thresholds` | object | No | 自定义颜色阈值 (`greenAbove`, `yellowAbove`) | | `factors` | array | No | 贡献因素细分 | *当省略且存在因素时,分数计算为加权平均值。 每个因素: | 字段 | 类型 | 必需 | 描述 | |-------|------|----------|-------------| | `name` | string | Yes | 因素名称 | | `score` | int | Yes | 因素分数 (0-100) | | `weight` | int | Yes | 在总体计算中的权重 | | `description` | string | No | 因素描述 | | `url` | string | No | 详细报告链接(在仪表板中可点击) | ## 文档 - [GitHub Action](docs/github-action.md) - [安装指南](docs/installation.md) - [CLI Reference](docs/cli-reference.md) - [Schema Reference](docs/schema.md) - [集成指南](docs/integration.md) - [External Sources](docs/sources.md) - [架构](docs/architecture.md) ## 示例 请参阅 [examples/](examples/) 目录了解: - GitHub Actions 工作流 - Makefile 集成 - 多数据源分数聚合 ## 许可证 MIT - 请参阅 [LICENSE](LICENSE)
标签:Anchore, API集成, EVTX分析, GitHub Actions, GitHub Marketplace, Go, Homebrew安装, Ruby工具, 云安全监控, 互联网扫描, 代码健康度, 代码复杂度, 可观测性, 可视化仪表盘, 多模态安全, 安全评分, 工程生产力, 度量聚合, 开源框架, 徽章生成, 技术债务, 持续集成, 数据管道, 日志审计, 测试覆盖率, 自动笔记, 质量门禁, 趋势分析, 软件工程, 软件开发, 重构, 静态分析