feat(ci): add custom Node.js and pnpm setup action

- Introduced a new GitHub Action for setting up Node.js and pnpm with caching capabilities.
- Updated workflows to utilize the new action, changing the Node.js version to 22.x across CI, API client, and release workflows.
- Streamlined dependency installation and caching processes for improved build performance.

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2025-05-06 00:41:49 +08:00
parent 423cc7de14
commit 5077535eda
4 changed files with 59 additions and 62 deletions

40
.github/actions/setup-node/action.yml vendored Normal file
View File

@@ -0,0 +1,40 @@
name: 'Setup Node.js and pnpm'
description: 'Sets up Node.js and pnpm with caching'
inputs:
node-version:
description: 'Node.js version to use'
required: false
default: '22.x'
runs:
using: 'composite'
steps:
- name: Use Node.js ${{ inputs.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
- name: Setup pnpm
uses: pnpm/action-setup@v4.1.0
with:
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Cache pnpm modules
uses: actions/cache@v4
env:
cache-name: cache-pnpm-modules
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ inputs.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ inputs.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }}
- name: Install Dependencies
shell: bash
run: pnpm i

View File

@@ -23,7 +23,7 @@ jobs:
strategy:
matrix:
node-version: [20.x]
node-version: [22.x]
steps:
- uses: actions/checkout@v4

View File

@@ -4,7 +4,8 @@ on:
- 'v*'
paths-ignore:
- CHANGELOG.MD
branches: master
branches:
- master
pull_request:
workflow_dispatch:
name: CI
@@ -54,44 +55,15 @@ jobs:
core:
name: Build (Core)
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js and pnpm
uses: ./.github/actions/setup-node
with:
node-version: ${{ matrix.node-version }}
- name: Setup pnpm
uses: pnpm/action-setup@v4.1.0
with:
version:
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Cache pnpm modules
uses: actions/cache@v4
env:
cache-name: cache-pnpm-modules
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }}
- name: Install Dependencies
run: |
pnpm i
node-version: '22.x'
- name: Build project
run: |
npm run bundle
run: npm run bundle
- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.12.0
with:
@@ -101,36 +73,22 @@ jobs:
with:
redis-version: 6
- name: Test Bundle Server
run: |
bash scripts/workflow/test-server.sh
run: bash scripts/workflow/test-server.sh
test:
name: Test
timeout-minutes: 10
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js and pnpm
uses: ./.github/actions/setup-node
with:
node-version: ${{ matrix.node-version }}
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
run_install: |
- recursive: false
node-version: '22.x'
- name: Run Lint
run: |
npm run lint
run: npm run lint
- name: Run Tests
run: |
npm run test
run: npm run test
env:
CI: true

View File

@@ -19,7 +19,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20.x
node-version: 22.x
- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.12.0
@@ -32,7 +32,6 @@ jobs:
- name: Setup pnpm
uses: pnpm/action-setup@v4.1.0
with:
version:
run_install: false
- name: Get pnpm store directory