setup-node-environment-test.yaml

This commit is contained in:
mini2024
2025-04-04 21:25:36 +08:00
parent 4a3df28bbf
commit 2a7a660cc4
2 changed files with 18 additions and 21 deletions

View File

@ -56,15 +56,12 @@ jobs:
strategy:
fail-fast: false
matrix:
checkout:
- true
- false
container:
- 'yanhao98/runner-images:pnpm'
- '' # gitea/runner-images:ubuntu-latest
npmrc_content:
- ''
-
- |
use-node-version=22.14.0 # https://pnpm.io/zh/npmrc#use-node-version
lock_file:
- 'true'
@ -74,13 +71,11 @@ jobs:
- 'test'
container: ${{ matrix.container }}
steps:
- uses: actions/checkout@main
if: matrix.checkout == 'true'
# - uses: actions/checkout@main
- name: 打印 matrix
run: |
echo "🤖---- 打印 matrix ----🤖"
echo "container: ${{ matrix.container }}"
echo "checkout: ${{ matrix.checkout }}"
echo "npmrc_content: ${{ matrix.npmrc_content }}"
echo "lock_file: ${{ matrix.lock_file }}"
echo "cwd: ${{ matrix.cwd }}"
@ -90,18 +85,21 @@ jobs:
if: matrix.cwd != ''
run: |
mkdir -p ${{ matrix.cwd }}
set -x;
ls -l -R .
pwd
- name: Create .npmrc
working-directory: ${{ matrix.cwd }}
if: matrix.npmrc_content != ''
run: |
set -x;
ls -l -R .
cat <<EOF > .npmrc
${{ matrix.npmrc_content }}
EOF
set -x;
ls -l -R .
pwd
cat .npmrc
- name: Create package.json
working-directory: ${{ matrix.cwd }}
@ -112,22 +110,21 @@ jobs:
EOF
set -x;
ls -l -R .
cat package.json
pwd
cat package.json
- name: Create pnpm-lock.yaml
working-directory: ${{ matrix.cwd }}
if: matrix.lock_file == 'true'
run: |
mkdir -p ${{ github.workspace }}/.git
cat <<EOF > pnpm-lock.yaml
${{ needs.generate_lock.outputs.lock_file_content }}
EOF
set -x;
ls -l -R .
pwd
cat pnpm-lock.yaml
- uses: yanhao98/composite-actions/setup-node-environment@main
with:
package_json_cwd: ${{ matrix.cwd }}
# pnpm_standalone: true
working-directory: ${{ matrix.cwd }}

View File

@ -18,8 +18,9 @@ inputs:
description: '是否将 pnpm 用作独立包'
required: false
default: 'false'
package_json_cwd: # https://github.com/pnpm/action-setup/blob/d648c2dd069001a242c621c8306af467f150e99d/action.yml#L18C3-L18C20
description: 'package.json 的所在目录'
# https://github.com/pnpm/action-setup/blob/d648c2dd069001a242c621c8306af467f150e99d/action.yml#L18C3-L18C20
working-directory:
description: '工作目录'
required: false
default: '.'
runs:
@ -40,7 +41,7 @@ runs:
- id: prepare
shell: bash
working-directory: ${{ inputs.package_json_cwd }}
working-directory: ${{ inputs.working-directory }}
run: |
# 🤖---- 准备环境变量 ----🤖 #
@ -185,7 +186,7 @@ runs:
shell: bash
- if: steps.cache-pnpm-restore.outputs.cache-hit == 'true'
working-directory: ${{ inputs.package_json_cwd }}
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
echo "🤖---- 缓存命中,安装依赖 ----🤖"
@ -194,7 +195,7 @@ runs:
# ERR_PNPM_NO_LOCKFILE Cannot install with "frozen-lockfile" because pnpm-lock.yaml is absent
- if: steps.cache-pnpm-restore.outputs.cache-hit != 'true'
working-directory: ${{ inputs.package_json_cwd }}
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
echo "🤖---- 缓存未命中,安装依赖 ----🤖"
@ -211,7 +212,6 @@ runs:
with:
path: ${{ steps.pnpm-store-dir.outputs.pnpmStoreDir }}
key: ${{ steps.cache-pnpm-restore.outputs.cache-primary-key }}
# # https://github.com/pnpm/pnpm/issues/7192#issuecomment-2353298966
# package-import-method=hardlink