mirror of
https://github.com/yanhao98/composite-actions.git
synced 2025-07-13 06:40:49 +08:00
feat: 更新 setup-node-environment.yml 和 action.yml,添加版本检查和输出信息;新增 .npmrc 文件以指定 Node.js 版本
This commit is contained in:
9
.github/workflows/setup-node-environment.yml
vendored
9
.github/workflows/setup-node-environment.yml
vendored
@ -12,8 +12,17 @@ jobs:
|
|||||||
job:
|
job:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
- name: before
|
||||||
|
run: |
|
||||||
|
set -x
|
||||||
|
which pnpm
|
||||||
|
node -v
|
||||||
|
|
||||||
- uses: yanhao98/composite-actions/setup-node-environment@main
|
- uses: yanhao98/composite-actions/setup-node-environment@main
|
||||||
|
|
||||||
- name: Check Node and PNPM versions
|
- name: Check Node and PNPM versions
|
||||||
run: |
|
run: |
|
||||||
set -x
|
set -x
|
||||||
which pnpm
|
which pnpm
|
||||||
|
node -v
|
||||||
|
pnpm node -v
|
||||||
|
1
.npmrc
Normal file
1
.npmrc
Normal file
@ -0,0 +1 @@
|
|||||||
|
use-node-version=22.9.0 # https://pnpm.io/zh/npmrc#use-node-version
|
@ -39,28 +39,41 @@ runs:
|
|||||||
id: prepare
|
id: prepare
|
||||||
run: |
|
run: |
|
||||||
# Check package manager
|
# Check package manager
|
||||||
# packageManager=$(jq -r '.packageManager' package.json)
|
|
||||||
packageManager=$(node -p "require('./package.json').packageManager")
|
packageManager=$(node -p "require('./package.json').packageManager")
|
||||||
echo "packageManager: $packageManager"
|
echo "#############################"
|
||||||
|
echo "packageManager: $packageManager found in package.json"
|
||||||
|
echo "#############################"
|
||||||
|
|
||||||
if [[ "$packageManager" == "pnpm"* ]]; then
|
if [[ "$packageManager" == "pnpm"* ]]; then
|
||||||
|
echo "#############################"
|
||||||
echo "setup-pnpm=true"
|
echo "setup-pnpm=true"
|
||||||
|
echo "#############################"
|
||||||
|
|
||||||
echo "setup-pnpm=true" >> $GITHUB_OUTPUT
|
echo "setup-pnpm=true" >> $GITHUB_OUTPUT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if pnpm-lock.yaml exists
|
# Check if pnpm-lock.yaml exists
|
||||||
if [[ -f "pnpm-lock.yaml" ]]; then
|
if [[ -f "pnpm-lock.yaml" ]]; then
|
||||||
echo "pnpm-lock.yaml exists"
|
echo "#############################"
|
||||||
|
echo "pnpm-lock.yaml exists. So pnpm install --frozen-lockfile will run"
|
||||||
|
echo "#############################"
|
||||||
|
|
||||||
echo "pnpm-lock-exists=true" >> $GITHUB_OUTPUT
|
echo "pnpm-lock-exists=true" >> $GITHUB_OUTPUT
|
||||||
echo "cache=pnpm" >> $GITHUB_OUTPUT
|
echo "cache=pnpm" >> $GITHUB_OUTPUT
|
||||||
else
|
else
|
||||||
echo "pnpm-lock.yaml does not exist"
|
echo "pnpm-lock.yaml does not exist"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Extract the node version from the .npmrc file
|
||||||
|
nodeVersion=$(grep 'use-node-version=' .npmrc | sed -E 's/^use-node-version=([0-9.]+).*/\1/')
|
||||||
|
echo "node-version=$nodeVersion" >> $GITHUB_OUTPUT
|
||||||
|
sed -i '/use-node-version/d' .npmrc
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v4 # https://github.com/pnpm/action-setup?tab=readme-ov-file#inputs
|
- uses: pnpm/action-setup@v4 # https://github.com/pnpm/action-setup?tab=readme-ov-file#inputs
|
||||||
if: steps.prepare.outputs.setup-pnpm == 'true'
|
if: steps.prepare.outputs.setup-pnpm == 'true'
|
||||||
- uses: actions/setup-node@v4 # https://github.com/actions/setup-node?tab=readme-ov-file#usage
|
- uses: actions/setup-node@v4 # https://github.com/actions/setup-node?tab=readme-ov-file#usage
|
||||||
with:
|
with:
|
||||||
node-version: lts/*
|
node-version: ${{ steps.prepare.outputs.node-version || 'lts/*' }}
|
||||||
cache: ${{ steps.prepare.outputs.cache }}
|
cache: ${{ steps.prepare.outputs.cache }}
|
||||||
- name: 📦 Install Project Dependencies
|
- name: 📦 Install Project Dependencies
|
||||||
if: steps.prepare.outputs.pnpm-lock-exists == 'true'
|
if: steps.prepare.outputs.pnpm-lock-exists == 'true'
|
||||||
|
Reference in New Issue
Block a user