Communitygithub.com

lguidolin/init-repo-CI

在新仓库中初始化 conventional commits、release-please 和 CI 自动化,或为缺乏自动版本管理和 PR 验证工作流的现有仓库进行改造。

init-repo-CI 是什么?

此技能可为任何 Git 仓库自动搭建完整的 conventional commits + release-please + CI 自动化基础设施,适用于全新仓库和已有代码的仓库。其核心理念是“左移”:在 PR 阶段捕获格式错误的提交信息、配置错误和代码问题,避免它们污染主分支和生产环境。它生成一系列经过精心设计的 GitHub Actions 工作流,包括 PR 标题验证、自动标签、禁止 AI 署名、YAML 语法检查,以及基于 release-please 的自动化发布流程,并支持从单包到多包(monorepo)的多种项目结构。所有工作流均遵循渐进式启用策略:先以非阻塞模式运行,经过验证后再改为必需检查,从而在保证代码质量的同时降低部署风险。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/lguidolin/agent-skills/tree/main/skills/init-repo-CI

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

仓库自动化设置

在任何仓库中搭建完整的 conventional-commits + release-please + CI 自动化栈。适用于空仓库和已有内容的仓库。

概述

左移: 尽早捕获问题。一个在 PR 时发现的错误提交信息只耗费几秒钟;同样的信息污染了发布说明则会损害可信度。将验证前置——在 PR 标题中强制提交格式,在 CI 中验证配置,在问题到达主分支前捕获它们。

更快即更安全: 更小的批次和更频繁的发布降低了风险。包含 3 个变更的发布比包含 30 个的更容易调试。自动化发布构建了对发布流程本身的信心。

此技能设置强制执行机制:PR 标题验证确保每次合并到主分支都会生成一个有意义的、可解析的提交。Release-please 将这些提交转化为带有变更日志的自动化发布。CI 在合并前捕获配置和代码问题。

何时使用

  • 开始一个新仓库,需要从一开始就具备发布自动化
  • 已有仓库没有自动版本管理或变更日志生成
  • 从手动发布流程或其他发布工具迁移
  • 仓库需要 PR 标题验证和自动标签

何时不使用

  • 仓库已配置了 release-please 或等效工具(请先检查)
  • 多包仓库使用了不兼容的发布工具(例如 Lerna 的独立版本管理已在工作中)
  • 仓库是一个 fork,其上游控制发布流程

流程

步骤 1:收集配置

在生成任何文件之前,向用户询问以下值:

参数默认值描述
PROJECT_NAME(必填)用于文档的人类可读项目名称
INITIAL_VERSION0.1.0起始语义版本
RELEASE_TYPEsimplesimple(单包)或 node / python 等
REPO_LAYOUTsinglesingle(根目录一个包)或 monorepo(多个包)
PACKAGE_PATHS.对于 monorepo:逗号分隔的路径,如 packages/api,packages/ui
DEPENDABOT_ECOSYSTEMSgithub-actions逗号分隔:github-actions、npm、pip、cargo 等
DEFAULT_BRANCHmain触发发布的分支

自动检测正确的 RELEASE_TYPE:

  • 存在 package.json → 建议 node
  • 存在 setup.py 或 pyproject.toml → 建议 python
  • 存在 Cargo.toml → 建议 rust
  • 以上皆无 → 建议 simple

步骤 2:检测现有文件

在创建任何内容之前,检查是否存在冲突:

for f in .github/workflows/pull-request.yml .github/workflows/main-branch.yml \
         .github/release-please-config.json .release-please-manifest.json \
         .github/dependabot.yml .github/pull_request_template.md docs/DEVELOPMENT.md; do
  [[ -f "$f" ]] && echo "EXISTS: $f"
done

如果文件存在,显示将要更改的差异,并在覆盖之前征求用户许可。不要静默覆盖——现有文件可能包含项目特定的自定义内容。

步骤 3:创建配置文件

按以下顺序创建文件(依赖关系自上而下):

3a. .github/release-please-config.json

单包:

{
  "release-type": "{{RELEASE_TYPE}}",
  "bump-minor-pre-major": true,
  "bump-patch-for-minor-pre-major": false,
  "initial-version": "{{INITIAL_VERSION}}",
  "packages": {
    ".": {}
  }
}

多包: 将 packages 替换为每个路径的一个条目:

{
  "packages": {
    "packages/api": { "release-type": "node" },
    "packages/ui": { "release-type": "node" }
  }
}

每个 monorepo 包都有自己的 release-type——如果它们不同,请逐个询问用户。

3b. .release-please-manifest.json

单包:

{
  ".": "{{INITIAL_VERSION}}"
}

多包: 每个包路径一个条目,每个都有自己的版本。

3c. .github/workflows/pull-request.yml

name: Pull Request Validation

on:
  pull_request:
    types: [opened, edited, synchronize, reopened]

permissions:
  pull-requests: write
  contents: read
  statuses: write

jobs:
  validate-pr-title:
    name: Validate PR Title
    runs-on: ubuntu-latest
    steps:
      - uses: amannn/action-semantic-pull-request@v6
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          types: |
            feat
            fix
            docs
            chore
            refactor
            test
            ci
          requireScope: false
          subjectPattern: ^[a-z].+$
          subjectPatternError: |
            The subject "{subject}" found in the pull request title "{title}"
            didn't match the configured pattern. Please ensure that the subject
            starts with a lowercase character (per conventional commits).

  auto-label:
    name: Auto Label PR
    runs-on: ubuntu-latest
    steps:
      - name: Label based on PR title
        uses: actions/github-script@v8
        with:
          script: |
            const title = context.payload.pull_request.title;
            const labelMap = {
              'feat': 'enhancement',
              'fix': 'bug',
              'docs': 'documentation',
              'chore': 'chore',
              'refactor': 'refactor',
              'test': 'test',
              'ci': 'ci'
            };
            for (const [type, label] of Object.entries(labelMap)) {
              if (title.startsWith(`${type}:`) || title.startsWith(`${type}(`)) {
                await github.rest.issues.addLabels({
                  owner: context.repo.owner,
                  repo: context.repo.repo,
                  issue_number: context.payload.pull_request.number,
                  labels: [label]
                });
                break;
              }
            }

  no-ai-attribution:
    name: No AI Attribution
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 0
      - name: Scan commit messages and PR body
        env:
          PR_BODY: ${{ github.event.pull_request.body }}
          BASE_SHA: ${{ github.event.pull_request.base.sha }}
          HEAD_SHA: ${{ github.event.pull_request.head.sha }}
        run: |
          # Trailer/footer forms only: a commit that merely mentions Claude or
          # Anthropic in prose is fine. Human Co-authored-by trailers are fine.
          PAT='^[[:space:]]*Co-authored-by:.*(Claude|Anthropic|noreply@anthropic)|Generated with \[?(Claude|Anthropic)'
          fail=0
          if git log --format='%B' "$BASE_SHA..$HEAD_SHA" | grep -Eiq "$PAT"; then
            echo "::error::AI attribution found in a commit message on this branch"
            fail=1
          fi
          if printf '%s' "$PR_BODY" | grep -Eiq "$PAT"; then
            echo "::error::AI attribution found in the PR description"
            fail=1
          fi
          [ "$fail" -eq 0 ] && echo "No AI attribution found."
          exit $fail

  ci-checks:
    name: CI Checks
    runs-on: ubuntu-latest
    continue-on-error: true
    steps:
      - uses: actions/checkout@v6
      - name: Validate YAML syntax
        run: |
          sudo apt-get update && sudo apt-get install -y yamllint
          find . -name "*.yml" -o -name "*.yaml" | while read file; do
            echo "Checking $file"
            yamllint -d "{extends: default, rules: {line-length: disable}}" "$file" || true
          done

No AI Attribution 从第一天起就启用阻止功能——它没有误报空间(仅匹配尾部/页脚形式,而非散文),因此不需要下面的逐步启用路径。

CI 检查逐步启用路径:

  1. 使用 continue-on-error: true 部署(仅信息性,非阻塞)
  2. 在 3-5 个真实 PR 上验证检查通过
  3. 移除 continue-on-error 并将其添加到分支保护必需检查中
  4. 随着代码库增长添加特定于项目的检查(lint、测试、构建)

没有门可以跳过。 如果 lint 失败,修复 lint——不要禁用规则。如果测试失败,修复代码——不要跳过测试。当 CI 失败时,将失败输出提供给您的代理并在再次推送之前修复它。

3d. .github/workflows/main-branch.yml

name: Release Automation

on:
  push:
    branches:
      - {{DEFAULT_BRANCH}}

permissions:
  contents: write
  pull-requests: write

jobs:
  release-please:
    name: Release Please
    runs-on: ubuntu-latest
    outputs:
      release_created: ${{ steps.release.outputs.release_created }}
      tag_name: ${{ steps.release.outputs.tag_name }}
    steps:
      - uses: googleapis/release-please-action@v4
        id: release
        with:
          config-file: .github/release-please-config.json
          manifest-file: .release-please-manifest.json

  update-major-tag:
    name: Update Major Version Tag
    needs: release-please
    if: ${{ needs.release-please.outputs.release_created == 'true' }}
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v6
        with:
          ref: ${{ needs.release-please.outputs.tag_name }}
      - name: Update major version tag
        env:
          TAG_NAME: ${{ needs.release-please.outputs.tag_name }}
        run: |
          MAJOR_TAG=$(echo "$TAG_NAME" | sed 's/^\(v[0-9]*\).*/\1/')
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git tag -fa "$MAJOR_TAG" -m "Update $MAJOR_TAG tag to $TAG_NAME"
          git push origin "$MAJOR_TAG" --force

3e. .github/dependabot.yml

为每个生态系统生成一个 updates 条目:

version: 2
updates:
  - package-ecosystem: "github-actions"
    directory: "/"
    schedule:
      interval: "weekly"
    open-pull-requests-limit: 5
    labels:
      - "dependencies"
    commit-message:
      prefix: "chore"
      include: "scope"

commit-message 配置确保 Dependabot PR 自动符合 conventional commits(例如 chore(deps): bump actions/checkout from v5 to v6)。

3f. .github/pull_request_template.md

## 变更内容

[详细描述变更——这将进入变更日志]

## 原因

[变更的背景和动机]

## 检查清单

- [ ] PR 标题遵循 conventional commits 格式(`type: description`)
- [ ] 描述解释了变更内容和原因(不仅仅是内容)
- [ ] 代码、日志或版本控制中没有机密信息
- [ ] 测试在本地通过

“原因”部分至关重要——仅说明内容的 PR 描述与差异冗余。原因提供了上下文,使未来的 git-blame 更有用。

3g. .gitignore(如果缺失)

检查是否存在 .gitignore。如果不存在,创建一个适合项目的文件:

# 依赖项
node_modules/

# 构建输出
dist/
build/
.next/

# 环境
.env
.env.local
*.pem

# IDE
.idea/

# 操作系统
.DS_Store
Thumbs.db

适应检测到的技术栈。永远不要提交 node_modules/、.env 或构建产物。

3h. docs/DEVELOPMENT.md

生成一份开发指南,涵盖:

  • 分支工作流——基于主干开发:短期特性分支(1-3 天),快速合并回去。分支命名:feature/<desc>、fix/<desc>、chore/<desc>。
  • 提交纪律——在分支内自由提交(任何格式)。只有 PR 标题很重要——它成为主分支上的 squash 合并提交信息,并出现在变更日志中。
  • PR 标题格式——类型表格:feat、fix、docs、chore、refactor、test、ci。破坏性变更:feat!: 或正文中的 BREAKING CHANGE:。
  • 变更规模——目标每个 PR 约 100 行。单个逻辑变更约 300 行可以接受。1000 行以上必须拆分。将重构与特性工作分开——它们是不同的变更。
  • PR 描述——第一行:简短、祈使、独立。正文:正在变更什么以及为什么。反模式:“修复错误”、“更新文件”、“阶段 1”。
  • 自动检查——PR 标题验证(必需,阻止合并)、自动标签(信息性)、CI 检查(最初非阻塞,逐步提升为必需)。
  • 发布流程——release-please 创建发布 PR → 合并 → GitHub 发布 + 标签 + 变更日志。版本演进:pre-1.0(feat → minor,fix → patch)与 post-1.0(feat → minor,fix → patch,BREAKING CHANGE → major)对比。
  • 故障排除——常见问题:PR 标题验证失败(编辑标题)、CI 检查失败、合并被阻止(检查必需的状态)。

在标题中使用 {{PROJECT_NAME}}。

步骤 4:分支保护建议

创建文件后,将这些作为手动步骤呈现(不自动应用):

推荐为 {{DEFAULT_BRANCH}} 设置的 GitHub 分支保护:
  ✓ 合并前要求拉取请求
  ✓ 要求状态检查:“Validate PR Title”
  ✓ 要求分支保持最新
  ✓ 仅允许 squash 合并
  ✓ 要求线性历史

为什么使用 squash 合并: 分支历史(WIP 提交、修复、实验)保留在 PR 中。主分支获得一个干净、有意义、线性的日志,其中每次提交都是 conventional commit。这使得 release-please 和 git log --oneline 变得有用。

步骤 5:启用工作流权限

Release-please 需要权限才能通过 GitHub Actions 创建拉取请求。这在新仓库上默认是禁用的,会导致“发布自动化”工作流失败并显示:

GitHub Actions is not permitted to create or approve pull requests.

指示用户启用此设置:

GitHub 仓库 → Settings → Actions → General → Workflow permissions:
  ✓ 读写权限(release-please 推送更新日志提交所必需)
  ✓ 允许 GitHub Actions 创建和批准拉取请求(发布 PR 所必需)

此步骤必须在第一次推送到 {{DEFAULT_BRANCH}} 之前完成,否则 release-please 将在每次推送时失败,直到启用。

步骤 6:验证

# 验证 YAML 语法
yamllint .github/workflows/*.yml .github/dependabot.yml

# 验证 JSON
python3 -c "import json; ...

[已截断以供翻译]

Individual skills in this repo

This repo contains 18 individual skills — each has its own dedicated page.

lguidolin/change-hygiene-and-code-craft

Use when writing or refactoring code, structuring a commit or PR, or deciding whether to abstract duplication. Symptoms — mixing reorg with logic changes, a PR doing several things at once, a file growing large, the second copy of similar code, or unsure whether to DRY something up.

lguidolin/cloud-delivery-aks

Use when deploying to Kubernetes or Azure Kubernetes Service (AKS), configuring cloud secrets, setting up progressive rollout/canary, per-PR ephemeral environments, or k8s health probes. Keywords — Kubernetes, AKS, Key Vault, Argo Rollouts, Flagger, canary, blue-green, liveness, readiness, PodDisruptionBudget, HPA, rollback, GHCR.

lguidolin/commit-history-rewrite

Use when an existing repository has messy commit history that needs to conform to conventional commits before adopting release-please, or when intermediate WIP/fixup/merge commits need to be cleaned up.

lguidolin/conventional-commits-and-releases

Use when committing, writing a commit message, opening a PR that will be squash-merged, or configuring automated versioning/changelogs. Keywords — conventional commits, release-please, semver, feat/fix/chore, breaking change, changelog.

lguidolin/defense-in-depth-security

Use when handling untrusted input, secrets, authentication/authorization, or dependencies — or threat-modeling a new surface. Keywords — STRIDE, threat model, least privilege, secrets management, supply chain, dependency scanning, input validation, audit log, defense in depth.

lguidolin/designing-before-building

Use when starting a feature, fixing a non-trivial bug, or about to write implementation code — before any code exists. Symptoms you need this: "this is simple, I'll just code it", reaching for the editor before a design is approved, or an idea that hasn't been turned into a spec and plan.

lguidolin/engineering-constitution

Use when starting work in a project that follows the engineering constitution, orienting to its rules, or deciding which engineering practice applies to a task — spec writing, commits, testing, security, deploys, database, or UI work.

lguidolin/graphql-contract-testing

Use when writing a GraphQL query/mutation that the UI and a test will share, or building route/schema contract or smoke tests. Symptoms — copying a query into a test, a test asserting on query text, schema change that didn't break the UI build, or RLS/permission drift. Keywords — graphql-codegen, typed document, contract test, route smoke test.

lguidolin/interface-craft-and-accessibility

Use when building or styling UI — components, layouts, forms, design tokens — or making accessibility decisions. Keywords — a11y, WCAG, keyboard navigation, focus state, contrast, design system, minimalist UI, component reuse, ARIA, semantic HTML.

lguidolin/merge-gates-and-automation

Use when setting up or changing CI, pre-push hooks, or a task runner, or deciding what must pass before merge. Symptoms — tempted to put authoritative checks only in a local hook, skip CI, bypass with --no-verify, or unsure what gates a merge vs. runs locally.

lguidolin/observability-and-slos

Use when adding logging, metrics, tracing, health checks, SLOs, or alerting — or when building a service surface that needs to be operable and debuggable. Keywords — structured logs, OpenTelemetry, correlation id, RED metrics, liveness, readiness, SLI, SLO, error budget, alerting.

lguidolin/performance-and-scale

Use when working on hot paths, list endpoints, pagination, data-access in loops, or public interfaces/schemas. Symptoms — unbounded queries, N+1 access, no latency budget, optimizing without measuring, or changing an interface many consumers depend on. Keywords — pagination, N+1, Hyrum's Law, performance budget, bundle size.

lguidolin/postgres-postgraphile-rls-and-sql

Use when writing PostgreSQL, PostGraphile config, Row-Level Security policies, SQL schema files, or working on the Browser→App→PostGraphile→Postgres data path. Keywords — RLS, SECURITY DEFINER, search_path, pgSettings, grants, roles, GraphQL depth limit, query cost, statement_timeout, SQL file organization.

lguidolin/recording-decisions

Use when a design or architecture decision has been made and needs to be captured — writing a decision record or ADR, updating a decision index, noting a deferred idea, or superseding a past decision. Keywords — ADR, decision record, rationale, rejected alternatives, dependency index.

lguidolin/resilience-and-deploy-safety

Use when planning a deploy, designing a rollback, or responding to an incident or writing a postmortem. Keywords — deploy safety, rollback, immutable artifact, progressive delivery, canary, blast radius, incident response, blameless postmortem, error budget.

lguidolin/ship-it

Use when the user wants to ship work — push, PR, archive decision records, merge, and clean up. Handles the full lifecycle from committing final changes through post-merge cleanup including converting specs/plans to compact decision records.

lguidolin/tests-as-a-control

Use when writing or modifying tests, when a test breaks during a refactor, or when testing permission/role rules. Symptoms — tempted to edit a test to make it pass, testing only the happy path, a deny-test that started passing, flaky tests, or unsure what to assert.

lguidolin/zero-downtime-migrations

Use when changing a database schema where data must survive the change — adding/removing/renaming columns, constraints, indexes, or backfilling. Symptoms — a destructive migration bundled with a code deploy, a NOT NULL column with a backfill, a table-locking UPDATE, or a rename. Keywords — expand/contract, parallel change, backfill, NOT VALID, CREATE INDEX CONCURRENTLY, graphile-migrate.

相关技能