GitHub Actions CI/CD 缓存与矩阵构建实战工作流示例name: ci

on:

push:

branches: [ main ]

jobs:

build:

runs-on: ubuntu-latest

strategy:

matrix:

node-version: [18, 20]

steps:

- uses: actions/checkout@v4

- uses: actions/setup-node@v4

with:

node-version: ${{ matrix.node-version }}

cache: 'npm'

- run: npm ci

- run: npm test --if-present

- run: npm run build --if-present

- uses: actions/upload-artifact@v4

with:

name: build-${{ matrix.node-version }}

path: dist/

要点使用 `cache: 'npm'` 复用依赖下载通过矩阵同时验证多版本运行环境使用制品上传保存构建结果便于后续发布或分析安全与密钥使用 `secrets.*` 注入敏感变量,不在日志中输出总结矩阵与缓存结合显著提升流水线效率与覆盖度,制品管理保障结果可复用。

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部