cmd-setup-workflows

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

/setup-workflows

/setup-workflows

Agent skill wrapper for the Claude command
/setup-workflows
.
When the original command text references
{{INPUT}}
,
$1
, or named arguments, map them from the user's current request.
Claude命令
/setup-workflows
的Agent技能封装。
当原始命令文本引用
{{INPUT}}
$1
或命名参数时,从用户当前请求中映射这些参数。

Command Instructions

命令说明

Task

任务

Create or update GitHub Actions workflows in
.github/workflows/
.
.github/workflows/
目录下创建或更新GitHub Actions工作流。

Detection Phase

检测阶段

First, detect the project ecosystem by inspecting the repo root:
  1. Language & package manager: Check for
    mix.exs
    ,
    package.json
    ,
    Cargo.toml
    ,
    go.mod
    ,
    pubspec.yaml
    ,
    pyproject.toml
    ,
    Makefile
    ,
    flake.nix
    , etc.
  2. Project type: Determine if this is a library/package or an application — this affects whether
    release.yml
    publishes to a registry.
  3. Existing workflows: Read any existing
    .github/workflows/*.yml
    to preserve custom jobs or secrets already configured.
  4. Test framework: Detect test runner from config (ExUnit, Jest/Vitest, cargo test, go test, flutter_test, pytest, etc.)
  5. Build tool: Detect build commands (mix compile, npm run build, cargo build, go build, flutter build, etc.)
  6. Linter/formatter: Detect available checks (mix format --check-formatted, mix credo, eslint, clippy, go vet, dart analyze, ruff, etc.)
首先,通过检查仓库根目录来检测项目生态系统:
  1. 语言与包管理器:检查是否存在
    mix.exs
    package.json
    Cargo.toml
    go.mod
    pubspec.yaml
    pyproject.toml
    Makefile
    flake.nix
    等文件。
  2. 项目类型:确定这是一个库/包还是应用程序——这会影响
    release.yml
    是否向注册表发布内容。
  3. 现有工作流:读取所有已存在的
    .github/workflows/*.yml
    文件,以保留已配置的自定义任务或密钥。
  4. 测试框架:从配置中检测测试运行器(ExUnit、Jest/Vitest、cargo test、go test、flutter_test、pytest等)。
  5. 构建工具:检测构建命令(mix compile、npm run build、cargo build、go build、flutter build等)。
  6. 代码检查器/格式化工具:检测可用的检查项(mix format --check-formatted、mix credo、eslint、clippy、go vet、dart analyze、ruff等)。

Workflow Definitions

工作流定义

Generate only the workflows that apply. Use the detected ecosystem to fill in concrete commands — never use placeholder commands.
仅生成适用的工作流。使用检测到的生态系统填充具体命令——切勿使用占位符命令。

1.
ci.yml
— Static checks & build

1.
ci.yml
—— 静态检查与构建

  • Trigger:
    push
    to any branch,
    pull_request
    to any branch
  • Jobs: format check, lint, build (compile/typecheck) — can be parallel jobs or sequential steps, whichever fits the ecosystem
  • No tests in this workflow
  • Cache: dependencies (hex/deps, node_modules, target/, pkg cache, pub cache, etc.)
  • 触发条件:推送至任意分支、针对任意分支的拉取请求
  • 任务:格式检查、代码检查、构建(编译/类型检查)——可采用并行任务或顺序步骤,以适配生态系统为准
  • 此工作流不包含测试
  • 缓存:依赖项(hex/deps、node_modules、target/、pkg缓存、pub缓存等)

2.
test.yml
— Unit tests

2.
test.yml
—— 单元测试

  • Trigger:
    push
    to
    main
    only,
    pull_request
    targeting
    main
  • Jobs: run unit test suite
  • Services: if tests need a database (Postgres, Redis, etc.), add service containers detected from config (e.g.
    config/test.exs
    ,
    docker-compose.yml
    ,
    .env.test
    )
  • Cache: dependencies
  • 触发条件:仅推送至
    main
    分支、针对
    main
    分支的拉取请求
  • 任务:运行单元测试套件
  • 服务:如果测试需要数据库(Postgres、Redis等),从配置中添加服务容器(例如
    config/test.exs
    docker-compose.yml
    .env.test
  • 缓存:依赖项

3.
release.yml
— Manual release

3.
release.yml
—— 手动发布

  • Trigger:
    workflow_dispatch
    with inputs:
    • version
      (string, required, description: "Release version (e.g. 1.2.3)")
    • git_ref
      (string, required, default: "main", description: "Git ref to release from")
  • Steps in order:
    1. Checkout at
      git_ref
    2. Setup language toolchain
    3. Update version in the canonical version file (
      mix.exs
      ,
      package.json
      ,
      Cargo.toml
      ,
      pubspec.yaml
      ,
      pyproject.toml
      , etc.) to the input
      version
    4. Build the package/artifact
    5. If library/package: publish to registry (hex.pm, npm, crates.io, pub.dev, pypi, etc.) — use appropriate secrets (
      HEX_API_KEY
      ,
      NPM_TOKEN
      ,
      CARGO_REGISTRY_TOKEN
      ,
      PUB_CREDENTIALS
      ,
      PYPI_TOKEN
      , etc.)
    6. If application: skip publish, but upload build artifacts
    7. Commit the version bump:
      git commit -am "chore(release): v${version}"
    8. Create git tag:
      v${version}
    9. Push commit and tag
    10. Create GitHub Release via
      gh release create
      or
      softprops/action-gh-release
      — include release notes (auto-generate from commits since last tag), upload build artifacts
  • Permissions:
    contents: write
  • 触发条件:带输入参数的
    workflow_dispatch
    • version
      (字符串,必填,描述:"发布版本(例如1.2.3)")
    • git_ref
      (字符串,必填,默认值:"main",描述:"用于发布的Git引用")
  • 步骤顺序
    1. 基于
      git_ref
      检出代码
    2. 设置语言工具链
    3. 将规范版本文件(
      mix.exs
      package.json
      Cargo.toml
      pubspec.yaml
      pyproject.toml
      等)中的版本更新为输入的
      version
    4. 构建包/制品
    5. 如果是库/包:发布至注册表(hex.pm、npm、crates.io、pub.dev、pypi等)——使用相应的密钥(
      HEX_API_KEY
      NPM_TOKEN
      CARGO_REGISTRY_TOKEN
      PUB_CREDENTIALS
      PYPI_TOKEN
      等)
    6. 如果是应用程序:跳过发布,但上传构建制品
    7. 提交版本更新:
      git commit -am "chore(release): v${version}"
    8. 创建Git标签:
      v${version}
    9. 推送提交和标签
    10. 通过
      gh release create
      softprops/action-gh-release
      创建GitHub Release——包含发布说明(从上次标签以来的提交自动生成),并上传构建制品
  • 权限
    contents: write

4.
e2e.yml
— End-to-end tests (only if
$ARGUMENTS
contains "e2e")

4.
e2e.yml
—— 端到端测试(仅当
$ARGUMENTS
包含"e2e"时生成)

  • Trigger:
    workflow_dispatch
    with input:
    • version
      (string, required, description: "Release version to test")
  • Steps:
    1. Fetch the release artifacts from GitHub Releases for the given version
    2. Setup test environment (install deps, start services)
    3. Run e2e test suite
  • Only generate this file when the user explicitly passes "e2e" as argument
  • 触发条件:带输入参数的
    workflow_dispatch
    • version
      (字符串,必填,描述:"要测试的发布版本")
  • 步骤
    1. 从GitHub Releases获取指定版本的发布制品
    2. 设置测试环境(安装依赖、启动服务)
    3. 运行端到端测试套件
  • 仅当用户明确传入"e2e"作为参数时才生成此文件

Output Rules

输出规则

  • Use the latest stable action versions (e.g.
    actions/checkout@v4
    ,
    actions/setup-node@v4
    ,
    erlef/setup-beam@v1
    )
  • Set
    permissions
    explicitly on each workflow — principle of least privilege
  • Every workflow must set
    concurrency
    to cancel redundant runs:
    yaml
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
      cancel-in-progress: true
  • Use
    fail-fast: false
    in matrix strategies if applicable
  • Prefer pinned action versions over
    @latest
  • Name each workflow clearly with a
    name:
    field
  • If existing workflow files are found, update them in place preserving any custom secrets, env vars, or extra jobs the user added — do not blindly overwrite
  • 使用最新稳定版本的Action(例如
    actions/checkout@v4
    actions/setup-node@v4
    erlef/setup-beam@v1
  • 在每个工作流中显式设置
    permissions
    ——遵循最小权限原则
  • 每个工作流必须设置
    concurrency
    以取消冗余运行:
    yaml
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
      cancel-in-progress: true
  • 如果适用,在矩阵策略中使用
    fail-fast: false
  • 优先使用固定版本的Action而非
    @latest
  • 为每个工作流设置清晰的
    name:
    字段
  • 如果发现现有工作流文件,就地更新,保留用户添加的任何自定义密钥、环境变量或额外任务——切勿盲目覆盖

Commit

提交

After writing all workflow files, create a single commit:
ci(github): update github actions workflows
Do NOT push. Report what was created/updated.
编写完所有工作流文件后,创建一个单独的提交:
ci(github): update github actions workflows
请勿推送。报告已创建/更新的内容。