mirror of
https://git.bjxgj.com/xgj/xgj-actions.git
synced 2025-10-14 06:33:37 +08:00
108 lines
2.4 KiB
YAML
108 lines
2.4 KiB
YAML
# 自定义缓存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
|