mirror of
https://git.bjxgj.com/xgj/xgj-actions.git
synced 2025-10-14 11:23:37 +08:00
feat: 更新 npm-install GitHub Action,移除 lockfile-name 输入参数,添加 cache-hash 参数以支持自定义缓存 hash,优化锁文件处理逻辑,确保在未提供 hash 时使用 package.json 作为 fallback,提升缓存管理的灵活性和可靠性,同时更新文档以反映新功能和使用示例。
This commit is contained in:
107
npm-install/examples/custom-cache-hash.yml
Normal file
107
npm-install/examples/custom-cache-hash.yml
Normal file
@@ -0,0 +1,107 @@
|
||||
# 自定义缓存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
|
Reference in New Issue
Block a user