rust-node-ci

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Rust+Node.js CI/CD

Rust+Node.js CI/CD

GitHub Actions workflows and composite actions for Rust+Node.js hybrid projects.
适用于Rust+Node.js混合项目的GitHub Actions工作流与复合Action。

When to Use This Skill

适用场景

Activate when any of the following are true:
  • Working with
    .github/workflows/
    in a repo with both
    Cargo.toml
    and
    package.json
  • Setting up, fixing, or extending CI/CD pipelines
  • Installing composite actions into a project
  • User mentions "CI", "workflow", "GitHub Actions", "cross-build", or "artifact"
当满足以下任一条件时启用:
  • 在同时包含
    Cargo.toml
    package.json
    的仓库中操作
    .github/workflows/
    目录
  • 搭建、修复或扩展CI/CD流水线
  • 向项目中安装复合Action
  • 用户提及「CI」「workflow」「GitHub Actions」「cross-build」或「artifact」

Decision Tree

决策树

What does the user need?

Set up CI from scratch?
  → Copy templates/workflows/ into .github/workflows/
  → Install composite actions from templates/actions/ into .github/actions/
  → Customize platform matrix for your targets

Fix a failing CI job?
  → Node job → CI Jobs section
  → Rust build/cross-compile → Composite Actions section + references/troubleshooting.md
  → Publish workflow → see rust-npm-publish skill

Add a new platform to the build matrix?
  → Publish Workflow Matrix section
  → Full platform reference → see rust-npm-publish skill

Understand dev vs release versioning in CI?
  → Dev Versioning section
用户需求是什么?

从零搭建CI?
  → 将templates/workflows/中的内容复制到.github/workflows/
  → 将templates/actions/中的复合Action安装到.github/actions/
  → 根据目标自定义平台构建矩阵

修复失败的CI任务?
  → Node任务 → 查看CI任务章节
  → Rust构建/交叉编译 → 查看复合Action章节 + references/troubleshooting.md
  → 发布工作流 → 查看rust-npm-publish技能文档

为构建矩阵添加新平台?
  → 查看发布工作流矩阵章节
  → 完整平台参考 → 查看rust-npm-publish技能文档

了解CI中的开发版与正式版版本管理?
  → 查看开发版本管理章节

Workflow Architecture

工作流架构

┌─────────────┐     ┌──────────────────┐
│  Node Build  │     │   Rust Build     │
│  (test/lint) │     │  (per platform)  │
└──────┬──────┘     └────────┬─────────┘
       │                     │
       │   ┌─────────────┐   │
       └──►│  Artifacts   │◄──┘
           └──────┬──────┘
           ┌──────▼──────┐
           │   Publish    │
           └─────────────┘
┌─────────────┐     ┌──────────────────┐
│  Node Build  │     │   Rust Build     │
│  (test/lint) │     │  (per platform)  │
└──────┬──────┘     └────────┬─────────┘
       │                     │
       │   ┌─────────────┐   │
       └──►│  Artifacts   │◄──┘
           └──────┬──────┘
           ┌──────▼──────┐
           │   Publish    │
           └─────────────┘

Workflows

工作流列表

WorkflowTriggerWhat It Does
ci.yml
PR, push to mainNode build+test+lint, Rust fmt+clippy+test
publish.yml
Release, dispatchCross-build → publish to npm
copilot-setup-steps.yml
repository_dispatchCopilot agent onboarding
Templates: templates/workflows/
工作流触发条件功能
ci.yml
PR、推送到main分支Node构建+测试+代码检查,Rust格式化+Clippy检查+测试
publish.yml
发布事件、手动触发交叉构建 → 发布到npm
copilot-setup-steps.yml
repository_dispatchCopilot Agent入门配置
模板地址:templates/workflows/

CI Jobs

CI任务

Node Job

Node任务

yaml
steps:
  - uses: ./.github/actions/setup-workspace
  - run: pnpm build
  - run: pnpm test
  - run: pnpm typecheck
yaml
steps:
  - uses: ./.github/actions/setup-workspace
  - run: pnpm build
  - run: pnpm test
  - run: pnpm typecheck

Rust Job

Rust任务

yaml
steps:
  - uses: actions/checkout@v4
  - uses: dtolnay/rust-toolchain@stable
    with:
      components: clippy, rustfmt
  - run: cargo fmt --all -- --check
  - run: cargo clippy --workspace -- -D warnings
  - run: cargo test --workspace
yaml
steps:
  - uses: actions/checkout@v4
  - uses: dtolnay/rust-toolchain@stable
    with:
      components: clippy, rustfmt
  - run: cargo fmt --all -- --check
  - run: cargo clippy --workspace -- -D warnings
  - run: cargo test --workspace

Composite Actions

复合Action

Install into
.github/actions/<name>/action.yml
in your project, then reference as
uses: ./.github/actions/<name>
.
Templates: templates/actions/
ActionInstall pathPurpose
setup-workspace
.github/actions/setup-workspace/
Checkout + pnpm + Node.js + cache + install
rust-cross-build
.github/actions/rust-cross-build/
Build Rust binaries for a target platform
compute-version
.github/actions/compute-version/
Compute dev/release version + npm tag
wait-npm-propagation
.github/actions/wait-npm-propagation/
Poll npm until platform packages are visible
安装到项目的
.github/actions/<name>/action.yml
路径下,然后通过
uses: ./.github/actions/<name>
引用。
模板地址:templates/actions/
Action安装路径用途
setup-workspace
.github/actions/setup-workspace/
代码检出 + pnpm + Node.js + 缓存 + 依赖安装
rust-cross-build
.github/actions/rust-cross-build/
为目标平台构建Rust二进制文件
compute-version
.github/actions/compute-version/
计算开发版/正式版版本号 + npm标签
wait-npm-propagation
.github/actions/wait-npm-propagation/
轮询npm直到平台包可见

Publish Workflow Matrix

发布工作流矩阵

yaml
strategy:
  matrix:
    include:
      - { os: macos-latest,   target: x86_64-apple-darwin,      platform: darwin-x64 }
      - { os: macos-latest,   target: aarch64-apple-darwin,     platform: darwin-arm64 }
      - { os: ubuntu-22.04,   target: x86_64-unknown-linux-gnu, platform: linux-x64 }
      - { os: windows-latest, target: x86_64-pc-windows-msvc,   platform: windows-x64 }
Each matrix entry runs
rust-cross-build
and uploads the binary as an artifact.
yaml
strategy:
  matrix:
    include:
      - { os: macos-latest,   target: x86_64-apple-darwin,      platform: darwin-x64 }
      - { os: macos-latest,   target: aarch64-apple-darwin,     platform: darwin-arm64 }
      - { os: ubuntu-22.04,   target: x86_64-unknown-linux-gnu, platform: linux-x64 }
      - { os: windows-latest, target: x86_64-pc-windows-msvc,   platform: windows-x64 }
每个矩阵条目都会执行
rust-cross-build
并将二进制文件作为工件上传。

Artifact Flow

工件流转

yaml
undefined
yaml
undefined

Upload from build job (one per platform)

从构建任务上传(每个平台一个)

  • uses: actions/upload-artifact@v4 with: name: binary-${{ matrix.platform }} path: target/${{ matrix.target }}/release/my-cli${{ matrix.platform == 'windows-x64' && '.exe' || '' }} retention-days: 1
  • uses: actions/upload-artifact@v4 with: name: binary-${{ matrix.platform }} path: target/${{ matrix.target }}/release/my-cli${{ matrix.platform == 'windows-x64' && '.exe' || '' }} retention-days: 1

Download in publish job (all platforms)

在发布任务中下载(所有平台)

  • uses: actions/download-artifact@v4 with: pattern: binary-* path: artifacts/ merge-multiple: false
undefined
  • uses: actions/download-artifact@v4 with: pattern: binary-* path: artifacts/ merge-multiple: false
undefined

Caching

缓存策略

ToolHow
pnpm
actions/setup-node@v4
with
cache: 'pnpm'
Rust
Swatinem/rust-cache@v2
with
shared-key: ${{ matrix.platform }}
Turbo
actions/cache@v4
on
.turbo
path
工具配置方式
pnpm使用
actions/setup-node@v4
并设置
cache: 'pnpm'
Rust使用
Swatinem/rust-cache@v2
并设置
shared-key: ${{ matrix.platform }}
Turbo使用
actions/cache@v4
缓存
.turbo
路径

Dev Versioning in CI

CI中的开发版本管理

Non-release builds compute a unique pre-release version:
base version: 0.2.15
compute-version (is-release: false) → 0.2.16-dev.{github_run_id}
npm-tag: dev
Use the
compute-version
action:
yaml
- uses: ./.github/actions/compute-version
  id: version
  with:
    base-version: ${{ steps.pkg.outputs.version }}
    is-release: ${{ github.event_name == 'release' }}
非发布构建会生成唯一的预发布版本号:
基础版本:0.2.15
compute-version (is-release: false) → 0.2.16-dev.{github_run_id}
npm标签: dev
使用
compute-version
Action:
yaml
- uses: ./.github/actions/compute-version
  id: version
  with:
    base-version: ${{ steps.pkg.outputs.version }}
    is-release: ${{ github.event_name == 'release' }}

outputs: version, npm-tag, is-dev

输出:version, npm-tag, is-dev

undefined
undefined

Troubleshooting

故障排查

ProblemFix
Rust build fails on macOS ARMUse
macos-latest
;
rustup target add aarch64-apple-darwin
pnpm lockfile mismatch
--frozen-lockfile
in CI; regenerate locally
Cargo cache too largeAdd
shared-key
to rust-cache; use
save-if
on main only
Artifact not found downstreamCheck
needs:
chain; verify artifact name matches
See references/troubleshooting.md for detailed diagnostics.
问题解决方案
macOS ARM上Rust构建失败使用
macos-latest
;执行
rustup target add aarch64-apple-darwin
pnpm锁文件不匹配CI中使用
--frozen-lockfile
;本地重新生成锁文件
Cargo缓存过大为rust-cache添加
shared-key
;仅在main分支启用
save-if
下游任务找不到工件检查
needs:
依赖链;确认工件名称匹配
详细诊断请查看references/troubleshooting.md

Templates

模板目录

DirectoryContents
templates/workflows/
ci.yml
,
publish.yml
,
copilot-setup-steps.yml
templates/actions/4 composite actions with
action.yml
+ README
目录内容
templates/workflows/
ci.yml
publish.yml
copilot-setup-steps.yml
templates/actions/4个带
action.yml
和README的复合Action

Setup & Activation

安装与激活

bash
npx skills add -g onsager-ai/dev-skills --skill rust-node-ci -a claude-code -y
Auto-activates when:
.github/workflows/
directory exists in a Rust+Node.js repo, or user mentions "CI", "workflow", "GitHub Actions", "cross-build".
bash
npx skills add -g onsager-ai/dev-skills --skill rust-node-ci -a claude-code -y
自动激活条件:Rust+Node.js仓库中存在
.github/workflows/
目录,或用户提及「CI」「workflow」「GitHub Actions」「cross-build」。