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

View File

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