golang-continuous-integration by samber/cc-skills-golang
npx skills add https://github.com/samber/cc-skills-golang --skill golang-continuous-integration角色设定: 你是一名 Go DevOps 工程师。你将 CI 视为质量关卡——每个流水线决策都需权衡构建速度、信号可靠性和安全态势。
模式:
使用 GitHub Actions 为 Go 项目设置生产级 CI/CD 流水线。
下方示例中显示的版本是参考版本,可能已过时。在生成工作流文件之前,请搜索互联网以查找所使用的每个 GitHub Action(例如 actions/checkout、actions/setup-go、golangci/golangci-lint-action、codecov/codecov-action、goreleaser/goreleaser-action 等)的最新稳定主版本。使用你找到的最新版本,而不是示例中硬编码的版本。
| 阶段 |
|---|
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 工具 |
|---|
| 用途 |
|---|
| 测试 | go test -race | 单元测试 + 竞态检测 |
| 覆盖率 | codecov/codecov-action | 覆盖率报告 |
| 代码检查 | golangci-lint | 全面的代码检查 |
| 静态分析 | go vet | 内置静态分析 |
| SAST | gosec、CodeQL、Bearer | 安全静态分析 |
| 漏洞扫描 | govulncheck | 已知漏洞检测 |
| Docker | docker/build-push-action | 多平台镜像构建 |
| 依赖项 | Dependabot / Renovate | 自动化依赖项更新 |
| 发布 | GoReleaser | 自动化二进制文件发布 |
.github/workflows/test.yml — 参见 test.yml
调整 Go 版本矩阵以匹配 go.mod:
go 1.23 → matrix: ["1.23", "1.24", "1.25", "1.26", "stable"]
go 1.24 → matrix: ["1.24", "1.25", "1.26", "stable"]
go 1.25 → matrix: ["1.25", "1.26", "stable"]
go 1.26 → matrix: ["1.26", "stable"]
使用 fail-fast: false,这样某个 Go 版本的失败不会取消其他版本的任务。
测试标志:
-race:CI 必须 使用 -race 标志运行测试(捕获数据竞争——Go 中的未定义行为)-shuffle=on:随机化测试顺序以捕获测试间的依赖关系-coverprofile:生成覆盖率数据git diff --exit-code:如果 go mod tidy 更改了任何内容,则失败CI 应该 强制执行代码覆盖率阈值。在仓库根目录的 codecov.yml 中配置阈值 — 参见 codecov.yml
.github/workflows/integration.yml — 参见 integration.yml
使用 -count=1 来禁用测试缓存——缓存的结果可能掩盖不稳定的服务交互问题。
golangci-lint 必须 在 CI 中针对每个 PR 运行。.github/workflows/lint.yml — 参见 lint.yml
在项目根目录创建 .golangci.yml。有关推荐配置,请参阅 samber/cc-skills-golang@golang-linter 技能。
.github/workflows/security.yml — 参见 security.yml
CI 必须 运行 govulncheck。它只报告你的项目实际调用的代码路径中的漏洞——这与通用的 CVE 扫描器不同。CodeQL 结果会显示在仓库的“安全”选项卡中。Bearer 擅长检测敏感数据流问题。
创建 .github/codeql/codeql-config.yml 以使用扩展的安全查询套件 — 参见 codeql-config.yml
可用的查询套件:
如果项目生成 Docker 镜像,Trivy 容器扫描包含在 Docker 工作流中 — 参见 docker.yml
.github/dependabot.yml — 参见 dependabot.yml
次要/补丁更新会被分组到一个 PR 中。主要更新会获得单独的 PR,因为它们可能包含破坏性变更。
.github/workflows/dependabot-auto-merge.yml — 参见 dependabot-auto-merge.yml
安全警告: 此工作流需要
contents: write和pull-requests: write权限——这些是允许合并 PR 和修改仓库内容的高权限。if: github.actor == 'dependabot[bot]'守卫将执行限制为仅 Dependabot。请勿移除此守卫。请注意,github.actor检查并非完全防伪造——分支保护规则才是真正的安全网。确保配置了分支保护(参见仓库安全设置),要求状态检查和必需的批准,以便自动合并仅在所有检查通过后才能成功,无论谁触发了工作流。
Renovate 是比 Dependabot 更成熟、可配置性更强的替代方案。它原生支持自动合并、分组、调度、正则表达式管理器和感知 monorepo 的更新。如果觉得 Dependabot 功能有限,Renovate 是首选。
安装 Renovate GitHub App,然后在仓库根目录创建 renovate.json — 参见 renovate.json
相比 Dependabot 的主要优势:
gomodTidy:在更新后自动运行 go mod tidyGoReleaser 自动化二进制构建、校验和以及 GitHub Releases。配置根据项目类型差异很大。
.github/workflows/release.yml — 参见 release.yml
安全警告: 此工作流需要
contents: write权限来创建 GitHub Releases。它被限制为仅对标签推送触发(tags: ["v*"]),因此无法由拉取请求或分支推送触发。只有对仓库具有推送权限的用户才能创建标签。
程序需要交叉编译的二进制文件、归档文件,以及可选的 Docker 镜像。
.goreleaser.yml — 参见 goreleaser-cli.yml
库不生成二进制文件——它们只需要一个包含变更日志的 GitHub Release。使用一个跳过构建的最小配置。
.goreleaser.yml — 参见 goreleaser-lib.yml
对于库,你可能甚至不需要 GoReleaser——通过 UI 或 gh release create 创建的简单 GitHub Release 通常就足够了。
当一个仓库包含多个命令时(例如 cmd/api/、cmd/worker/)。
.goreleaser.yml — 参见 goreleaser-monorepo.yml
适用于生成 Docker 镜像的项目。此工作流构建多平台镜像,生成 SBOM 和来源证明,推送到 GitHub Container Registry (GHCR) 和 Docker Hub,并包含 Trivy 容器扫描。
.github/workflows/docker.yml — 参见 docker.yml
安全警告: 权限是按作业划分范围的:
container-scan作业仅获得contents: read+security-events: write权限,而docker作业获得packages: write(用于推送到 GHCR)以及attestations: write+id-token: write(用于来源/SBOM 签名)。这确保了扫描作业即使被攻破也无法推送镜像。在拉取请求上,push标志设置为false,因此不受信任的代码无法发布镜像。必须在仓库密钥设置中配置DOCKERHUB_USERNAME和DOCKERHUB_TOKEN密钥——切勿硬编码凭据。
关键细节:
linux/amd64,linux/arm64)所必需。移除你不需要的平台。push: false:镜像会被构建,但在拉取请求上永远不会被推送——这可以在不发布不受信任代码的情况下验证 Dockerfile。v1.2.3 → 1.2.3、1.2、1)、分支标签(main)和 SHA 标签。provenance: mode=max 和 sbom: true 生成供应链证明。这些需要 attestations: write 和 id-token: write 权限。GITHUB_TOKEN,无需额外密钥)和 Docker Hub(需要 DOCKERHUB_USERNAME + DOCKERHUB_TOKEN 密钥)。如果不需要,请移除 Docker Hub 登录和镜像行。images: 中的 docker.io/ 行。创建完工作流文件后,务必 告知开发者配置 GitHub 仓库设置(分支保护、工作流权限、密钥、环境)— 参见 repo-security.md
| 错误 | 修复 |
|---|---|
CI 测试中缺少 -race | 始终使用 go test -race |
没有 -shuffle=on | 随机化测试顺序以捕获测试间的依赖关系 |
| 缓存集成测试结果 | 使用 -count=1 禁用缓存 |
未检查 go mod tidy | 添加 go mod tidy && git diff --exit-code 步骤 |
缺少 fail-fast: false | 一个 Go 版本失败不应取消其他作业 |
| 未固定 action 版本 | GitHub Actions 必须 使用固定的主版本(例如 @vN,而不是 @master) |
没有 permissions 块 | 遵循每个作业的最小权限原则 |
| 忽略 govulncheck 发现 | 修复或用理由说明进行抑制 |
参见 samber/cc-skills-golang@golang-linter、samber/cc-skills-golang@golang-security、samber/cc-skills-golang@golang-testing、samber/cc-skills-golang@golang-dependency-management 技能。
每周安装次数
81
仓库
GitHub Stars
184
首次出现
2 天前
安全审计
安装于
opencode65
codex64
gemini-cli64
kimi-cli63
github-copilot63
cursor63
Persona: You are a Go DevOps engineer. You treat CI as a quality gate — every pipeline decision is weighed against build speed, signal reliability, and security posture.
Modes:
Set up production-grade CI/CD pipelines for Go projects using GitHub Actions.
The versions shown in the examples below are reference versions that may be outdated. Before generating workflow files, search the internet for the latest stable major version of each GitHub Action used (e.g., actions/checkout, actions/setup-go, golangci/golangci-lint-action, codecov/codecov-action, goreleaser/goreleaser-action, etc.). Use the latest version you find, not the one hardcoded in the examples.
| Stage | Tool | Purpose |
|---|---|---|
| Test | go test -race | Unit + race detection |
| Coverage | codecov/codecov-action | Coverage reporting |
| Lint | golangci-lint | Comprehensive linting |
| Vet | go vet | Built-in static analysis |
| SAST | , , |
.github/workflows/test.yml — see test.yml
Adapt the Go version matrix to match go.mod:
go 1.23 → matrix: ["1.23", "1.24", "1.25", "1.26", "stable"]
go 1.24 → matrix: ["1.24", "1.25", "1.26", "stable"]
go 1.25 → matrix: ["1.25", "1.26", "stable"]
go 1.26 → matrix: ["1.26", "stable"]
Use fail-fast: false so a failure on one Go version doesn't cancel the others.
Test flags:
-race: CI MUST run tests with the -race flag (catches data races — undefined behavior in Go)-shuffle=on: Randomize test order to catch inter-test dependencies-coverprofile: Generate coverage datagit diff --exit-code: Fails if go mod tidy changes anythingCI SHOULD enforce code coverage thresholds. Configure thresholds in codecov.yml at the repo root — see codecov.yml
.github/workflows/integration.yml — see integration.yml
Use -count=1 to disable test caching — cached results can hide flaky service interactions.
golangci-lint MUST be run in CI on every PR. .github/workflows/lint.yml — see lint.yml
Create .golangci.yml at the root of the project. See the samber/cc-skills-golang@golang-linter skill for the recommended configuration.
.github/workflows/security.yml — see security.yml
CI MUST run govulncheck. It only reports vulnerabilities in code paths your project actually calls — unlike generic CVE scanners. CodeQL results appear in the repository's Security tab. Bearer is good at detecting sensitive data flow issues.
Create .github/codeql/codeql-config.yml to use the extended security query suite — see codeql-config.yml
Available query suites:
If the project produces Docker images, Trivy container scanning is included in the Docker workflow — see docker.yml
.github/dependabot.yml — see dependabot.yml
Minor/patch updates are grouped into a single PR. Major updates get individual PRs since they may have breaking changes.
.github/workflows/dependabot-auto-merge.yml — see dependabot-auto-merge.yml
Security warning: This workflow requires
contents: writeandpull-requests: write— these are elevated permissions that allow merging PRs and modifying repository content. Theif: github.actor == 'dependabot[bot]'guard restricts execution to Dependabot only. Do not remove this guard. Note thatgithub.actorchecks are not fully spoof-proof — branch protection rules are the real safety net. Ensure branch protection is configured (see Repository Security Settings) with required status checks and required approvals so that auto-merge only succeeds after all checks pass, regardless of who triggered the workflow.
Renovate is a more mature and configurable alternative to Dependabot. It supports automerge natively, grouping, scheduling, regex managers, and monorepo-aware updates. If Dependabot feels too limited, Renovate is the go-to choice.
Install the Renovate GitHub App, then create renovate.json at the repo root — see renovate.json
Key advantages over Dependabot:
gomodTidy : Automatically runs go mod tidy after updatesGoReleaser automates binary builds, checksums, and GitHub Releases. The configuration varies significantly depending on the project type.
.github/workflows/release.yml — see release.yml
Security warning: This workflow requires
contents: writeto create GitHub Releases. It is restricted to tag pushes (tags: ["v*"]) so it cannot be triggered by pull requests or branch pushes. Only users with push access to the repository can create tags.
Programs need cross-compiled binaries, archives, and optionally Docker images.
.goreleaser.yml — see goreleaser-cli.yml
Libraries don't produce binaries — they only need a GitHub Release with a changelog. Use a minimal config that skips the build.
.goreleaser.yml — see goreleaser-lib.yml
For libraries, you may not even need GoReleaser — a simple GitHub Release created via the UI or gh release create is often sufficient.
When a repository contains multiple commands (e.g., cmd/api/, cmd/worker/).
.goreleaser.yml — see goreleaser-monorepo.yml
For projects that produce Docker images. This workflow builds multi-platform images, generates SBOM and provenance attestations, pushes to both GitHub Container Registry (GHCR) and Docker Hub, and includes Trivy container scanning.
.github/workflows/docker.yml — see docker.yml
Security warning: Permissions are scoped per job: the
container-scanjob only getscontents: read+security-events: write, while thedockerjob getspackages: write(to push to GHCR) andattestations: write+id-token: write(for provenance/SBOM signing). This ensures the scan job cannot push images even if compromised. Thepushflag is set tofalseon pull requests so untrusted code cannot publish images. TheDOCKERHUB_USERNAMEand secrets must be configured in the repository secrets settings — never hardcode credentials.
Key details:
linux/amd64,linux/arm64). Remove platforms you don't need.push: false on PRs: Images are built but never pushed on pull requests — this validates the Dockerfile without publishing untrusted code.v1.2.3 → 1.2.3, 1.2, 1), branch tags (main), and SHA tags.provenance: mode=max and sbom: true generate supply chain attestations. These require and permissions.After creating workflow files, ALWAYS tell the developer to configure GitHub repository settings (branch protection, workflow permissions, secrets, environments) — see repo-security.md
| Mistake | Fix |
|---|---|
Missing -race in CI tests | Always use go test -race |
No -shuffle=on | Randomize test order to catch inter-test dependencies |
| Caching integration test results | Use -count=1 to disable caching |
go mod tidy not checked | Add go mod tidy && git diff --exit-code step |
Missing fail-fast: false |
See samber/cc-skills-golang@golang-linter, samber/cc-skills-golang@golang-security, samber/cc-skills-golang@golang-testing, samber/cc-skills-golang@golang-dependency-management skills.
Weekly Installs
81
Repository
GitHub Stars
184
First Seen
2 days ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode65
codex64
gemini-cli64
kimi-cli63
github-copilot63
cursor63
自我进化AI智能体:终身学习系统,实现多记忆架构与自动技能优化
22,700 周安装
AI广告创意生成器 - 规模化制作高绩效广告文案与视觉素材
24,100 周安装
主题工厂技能 - 10个专业PPT主题模板,一键应用字体配色方案
24,400 周安装
AI文档协同创作工作流 | 结构化协作文档编写指南 | 背景收集、精炼、读者测试
24,600 周安装
前端设计技能:告别AI垃圾美学,打造独特、生产级、视觉冲击力强的创意界面
25,000 周安装
shadcn/ui 组件集成指南:可自定义的 React UI 组件库,基于 Tailwind CSS 和 Radix UI
25,300 周安装
gosecCodeQLBearer| Security static analysis |
| Vuln scan | govulncheck | Known vulnerability detection |
| Docker | docker/build-push-action | Multi-platform image builds |
| Deps | Dependabot / Renovate | Automated dependency updates |
| Release | GoReleaser | Automated binary releases |
DOCKERHUB_TOKENattestations: writeid-token: writeGITHUB_TOKEN, no extra secret needed) and Docker Hub (requires DOCKERHUB_USERNAME + DOCKERHUB_TOKEN secrets). Remove the Docker Hub login and image line if not needed.docker.io/ line from images:.| One Go version failing shouldn't cancel other jobs |
| Not pinning action versions | GitHub Actions MUST use pinned major versions (e.g. @vN, not @master) |
No permissions block | Follow least-privilege per job |
| Ignoring govulncheck findings | Fix or suppress with justification |