github-workflow

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub Workflows

GitHub工作流

Rules for writing GitHub Actions workflows for this user.
为该用户编写GitHub Actions工作流的规则。

Action versions

Action版本

  • Pin every action to its latest major version tag (e.g.
    actions/checkout@v7
    ).
  • Find the latest tag at authoring time instead of reusing stale tags from memory:
    bash
    gh api repos/OWNER/REPO/releases/latest --jq .tag_name
  • On a major-version bump, check the release notes for breaking changes to inputs.
Current latest, verified 2026-08 (re-check before use):
ActionLatest
actions/checkoutv7
actions/setup-nodev7
actions/setup-pythonv7
actions/cachev6
actions/upload-artifactv7
actions/download-artifactv8
pnpm/action-setupv6
  • 将每个action固定到其最新的主版本标签(例如
    actions/checkout@v7
    )。
  • 在编写时查找最新标签,而非使用记忆中过时的标签:
    bash
    gh api repos/OWNER/REPO/releases/latest --jq .tag_name
  • 当主版本升级时,查看发布说明以了解输入参数的破坏性变更。
当前最新版本,验证于2026年8月(使用前请重新确认):
ActionLatest
actions/checkoutv7
actions/setup-nodev7
actions/setup-pythonv7
actions/cachev6
actions/upload-artifactv7
actions/download-artifactv8
pnpm/action-setupv6

Node version

Node版本

  • If the repo has
    .node-version
    (or
    .nvmrc
    ), use it via
    node-version-file
    .
  • Otherwise use the latest LTS with
    node-version: 'lts/*'
    . Never hardcode a specific Node version.
  • 如果仓库存在
    .node-version
    (或
    .nvmrc
    )文件,通过
    node-version-file
    参数使用该版本。
  • 否则使用
    node-version: 'lts/*'
    来指定最新的LTS版本。切勿硬编码特定的Node版本。

pnpm

pnpm

  • Use the setup-pnpm action (
    pnpm/action-setup
    ) — never
    corepack
    .
  • Do not hardcode a version:
    pnpm/action-setup
    reads
    packageManager
    from
    package.json
    automatically.
  • If
    package.json
    has no pnpm version, set
    version: latest
    .
  • 使用setup-pnpm action(
    pnpm/action-setup
    )——绝不使用
    corepack
  • 不要硬编码版本:
    pnpm/action-setup
    会自动从
    package.json
    packageManager
    字段读取版本。
  • 如果
    package.json
    中未指定pnpm版本,设置
    version: latest

Existing workflows

现有工作流

  • When asked to update an existing workflow, first list every action with its current and latest version, and get the user's confirmation before changing anything.
  • 当需要更新现有工作流时,先列出每个action的当前版本和最新版本,在进行任何更改前获得用户确认。

Example

示例

yaml
name: CI

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7

      - uses: pnpm/action-setup@v6
        # version is read from package.json "packageManager"; no hardcoding

      - uses: actions/setup-node@v7
        with:
          node-version-file: '.node-version' # or: node-version: 'lts/*'
          cache: 'pnpm'

      - run: pnpm install --frozen-lockfile
      - run: pnpm test
yaml
name: CI

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7

      - uses: pnpm/action-setup@v6
        # version is read from package.json "packageManager"; no hardcoding

      - uses: actions/setup-node@v7
        with:
          node-version-file: '.node-version' # or: node-version: 'lts/*'
          cache: 'pnpm'

      - run: pnpm install --frozen-lockfile
      - run: pnpm test