github-workflow
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitHub 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):
| Action | Latest |
|---|---|
| actions/checkout | v7 |
| actions/setup-node | v7 |
| actions/setup-python | v7 |
| actions/cache | v6 |
| actions/upload-artifact | v7 |
| actions/download-artifact | v8 |
| pnpm/action-setup | v6 |
-
将每个action固定到其最新的主版本标签(例如)。
actions/checkout@v7 -
在编写时查找最新标签,而非使用记忆中过时的标签:bash
gh api repos/OWNER/REPO/releases/latest --jq .tag_name -
当主版本升级时,查看发布说明以了解输入参数的破坏性变更。
当前最新版本,验证于2026年8月(使用前请重新确认):
| Action | Latest |
|---|---|
| actions/checkout | v7 |
| actions/setup-node | v7 |
| actions/setup-python | v7 |
| actions/cache | v6 |
| actions/upload-artifact | v7 |
| actions/download-artifact | v8 |
| pnpm/action-setup | v6 |
Node version
Node版本
- If the repo has (or
.node-version), use it via.nvmrc.node-version-file - Otherwise use the latest LTS with . Never hardcode a specific Node version.
node-version: 'lts/*'
- 如果仓库存在(或
.node-version)文件,通过.nvmrc参数使用该版本。node-version-file - 否则使用来指定最新的LTS版本。切勿硬编码特定的Node版本。
node-version: 'lts/*'
pnpm
pnpm
- Use the setup-pnpm action () — never
pnpm/action-setup.corepack - Do not hardcode a version: reads
pnpm/action-setupfrompackageManagerautomatically.package.json - If has no pnpm version, set
package.json.version: latest
- 使用setup-pnpm action()——绝不使用
pnpm/action-setup。corepack - 不要硬编码版本:会自动从
pnpm/action-setup的package.json字段读取版本。packageManager - 如果中未指定pnpm版本,设置
package.json。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 testyaml
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