Files
xgj/npm-install/examples/custom-cache-hash.yml

108 lines
2.4 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 自定义缓存hash示例推荐用法
name: 自定义缓存hash示例
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 设置Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
# 推荐用法手动计算hash并传入
- name: 安装npm依赖使用package-lock.json hash
uses: actions/xgj/npm-install@v1
with:
package-manager: 'npm'
cache-hash: ${{ hashFiles('package-lock.json') }}
- name: 运行linting
run: npm run lint
- name: 运行测试
run: npm test
test-pnpm:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 设置Node.js和pnpm
uses: actions/setup-node@v4
with:
node-version: '18'
- name: 安装pnpm
run: npm install -g pnpm
# pnpm项目示例
- name: 安装pnpm依赖
uses: actions/xgj/npm-install@v1
with:
package-manager: 'pnpm'
cache-hash: ${{ hashFiles('pnpm-lock.yaml') }}
- name: 运行测试
run: pnpm test
test-yarn:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 设置Node.js和Yarn
uses: actions/setup-node@v4
with:
node-version: '18'
- name: 启用Yarn
run: corepack enable yarn
# Yarn项目示例
- name: 安装yarn依赖
uses: actions/xgj/npm-install@v1
with:
package-manager: 'yarn'
cache-hash: ${{ hashFiles('yarn.lock') }}
- name: 运行测试
run: yarn test
# 多个锁文件的复杂项目示例
test-multi-lockfiles:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 设置Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
# 组合多个文件的hash确保任何文件变化都会使缓存失效
- name: 安装依赖多文件hash
uses: actions/xgj/npm-install@v1
with:
package-manager: 'npm'
cache-hash: ${{ hashFiles('package.json', 'package-lock.json', '.nvmrc') }}
- name: 运行测试
run: npm test