feat(ci): add custom action for MongoDB and Redis setup
- Introduced a new GitHub Action to streamline the setup of MongoDB and Redis for testing environments. - Updated CI workflows to utilize the new action, replacing direct MongoDB and Redis setup steps for improved maintainability. - Added `mongodb-memory-server` and `redis-memory-server` as dependencies in the project. Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
25
.github/actions/setup-databases/action.yml
vendored
Normal file
25
.github/actions/setup-databases/action.yml
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
name: 'Setup MongoDB and Redis'
|
||||||
|
description: 'Sets up MongoDB and Redis for testing'
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
mongodb-version:
|
||||||
|
description: 'MongoDB version to use'
|
||||||
|
required: false
|
||||||
|
default: '4.4'
|
||||||
|
redis-version:
|
||||||
|
description: 'Redis version to use'
|
||||||
|
required: false
|
||||||
|
default: '6'
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: 'composite'
|
||||||
|
steps:
|
||||||
|
- name: Start MongoDB
|
||||||
|
uses: supercharge/mongodb-github-action@1.12.0
|
||||||
|
with:
|
||||||
|
mongodb-version: ${{ inputs.mongodb-version }}
|
||||||
|
|
||||||
|
- name: Start Redis
|
||||||
|
uses: supercharge/redis-github-action@1.8.0
|
||||||
|
with:
|
||||||
|
redis-version: ${{ inputs.redis-version }}
|
||||||
12
.github/workflows/ci.yml
vendored
12
.github/workflows/ci.yml
vendored
@@ -64,14 +64,8 @@ jobs:
|
|||||||
node-version: '22.x'
|
node-version: '22.x'
|
||||||
- name: Build project
|
- name: Build project
|
||||||
run: npm run bundle
|
run: npm run bundle
|
||||||
- name: Start MongoDB
|
- name: Setup MongoDB and Redis
|
||||||
uses: supercharge/mongodb-github-action@1.12.0
|
uses: ./.github/actions/setup-databases
|
||||||
with:
|
|
||||||
mongodb-version: 4.4
|
|
||||||
- name: Start Redis
|
|
||||||
uses: supercharge/redis-github-action@1.8.0
|
|
||||||
with:
|
|
||||||
redis-version: 6
|
|
||||||
- name: Test Bundle Server
|
- name: Test Bundle Server
|
||||||
run: bash scripts/workflow/test-server.sh
|
run: bash scripts/workflow/test-server.sh
|
||||||
|
|
||||||
@@ -86,6 +80,8 @@ jobs:
|
|||||||
uses: ./.github/actions/setup-node
|
uses: ./.github/actions/setup-node
|
||||||
with:
|
with:
|
||||||
node-version: '22.x'
|
node-version: '22.x'
|
||||||
|
- name: Setup MongoDB and Redis
|
||||||
|
uses: ./.github/actions/setup-databases
|
||||||
- name: Run Lint
|
- name: Run Lint
|
||||||
run: npm run lint
|
run: npm run lint
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
|
|||||||
@@ -47,10 +47,6 @@
|
|||||||
],
|
],
|
||||||
"changelog": true
|
"changelog": true
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
|
||||||
"mongodb-memory-server": "^10.1.4",
|
|
||||||
"redis-memory-server": "^0.12.1"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@algolia/client-search": "catalog:",
|
"@algolia/client-search": "catalog:",
|
||||||
"@antfu/install-pkg": "catalog:",
|
"@antfu/install-pkg": "catalog:",
|
||||||
@@ -161,12 +157,13 @@
|
|||||||
"@vercel/ncc": "catalog:",
|
"@vercel/ncc": "catalog:",
|
||||||
"cron": "catalog:",
|
"cron": "catalog:",
|
||||||
"ioredis": "catalog:",
|
"ioredis": "catalog:",
|
||||||
|
"mongodb-memory-server": "catalog:",
|
||||||
|
"redis-memory-server": "catalog:",
|
||||||
"sharp": "catalog:",
|
"sharp": "catalog:",
|
||||||
"socket.io": "catalog:",
|
"socket.io": "catalog:",
|
||||||
"unplugin-swc": "catalog:",
|
"unplugin-swc": "catalog:",
|
||||||
"vite": "catalog:",
|
"vite": "catalog:",
|
||||||
"vite-tsconfig-paths": "catalog:",
|
"vite-tsconfig-paths": "catalog:",
|
||||||
"vitest": "catalog:",
|
"vitest": "catalog:"
|
||||||
"zx": "catalog:"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import { mkdirSync } from 'node:fs'
|
import { mkdirSync } from 'node:fs'
|
||||||
import { MongoMemoryServer } from 'mongodb-memory-server'
|
import { MongoMemoryServer } from 'mongodb-memory-server'
|
||||||
import { chalk } from 'zx'
|
|
||||||
|
|
||||||
import { Logger } from '@nestjs/common'
|
import { Logger } from '@nestjs/common'
|
||||||
|
|
||||||
@@ -15,15 +14,10 @@ import {
|
|||||||
|
|
||||||
export async function setup() {
|
export async function setup() {
|
||||||
mkdirSync(DATA_DIR, { recursive: true })
|
mkdirSync(DATA_DIR, { recursive: true })
|
||||||
Logger.log(chalk.blue(`数据目录已经建好:${DATA_DIR}`))
|
|
||||||
mkdirSync(TEMP_DIR, { recursive: true })
|
mkdirSync(TEMP_DIR, { recursive: true })
|
||||||
Logger.log(chalk.blue(`临时目录已经建好:${TEMP_DIR}`))
|
|
||||||
mkdirSync(LOG_DIR, { recursive: true })
|
mkdirSync(LOG_DIR, { recursive: true })
|
||||||
Logger.log(chalk.blue(`日志目录已经建好:${LOG_DIR}`))
|
|
||||||
mkdirSync(USER_ASSET_DIR, { recursive: true })
|
mkdirSync(USER_ASSET_DIR, { recursive: true })
|
||||||
Logger.log(chalk.blue(`资源目录已经建好:${USER_ASSET_DIR}`))
|
|
||||||
mkdirSync(STATIC_FILE_DIR, { recursive: true })
|
mkdirSync(STATIC_FILE_DIR, { recursive: true })
|
||||||
Logger.log(chalk.blue(`文件存放目录已经建好:${STATIC_FILE_DIR}`))
|
|
||||||
mkdirSync(THEME_DIR, { recursive: true })
|
mkdirSync(THEME_DIR, { recursive: true })
|
||||||
const db = await MongoMemoryServer.create()
|
const db = await MongoMemoryServer.create()
|
||||||
await db.stop()
|
await db.stop()
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ catalog:
|
|||||||
marked: 15.0.11
|
marked: 15.0.11
|
||||||
mime-types: ^3.0.1
|
mime-types: ^3.0.1
|
||||||
mkdirp: ^3.0.1
|
mkdirp: ^3.0.1
|
||||||
|
mongodb-memory-server: ^10.1.4
|
||||||
mongoose: 8.14.1
|
mongoose: 8.14.1
|
||||||
mongoose-aggregate-paginate-v2: 1.1.4
|
mongoose-aggregate-paginate-v2: 1.1.4
|
||||||
mongoose-autopopulate: 1.1.0
|
mongoose-autopopulate: 1.1.0
|
||||||
@@ -110,6 +111,7 @@ catalog:
|
|||||||
pluralize: ^8.0.0
|
pluralize: ^8.0.0
|
||||||
prettier: 3.5.3
|
prettier: 3.5.3
|
||||||
qs: 6.14.0
|
qs: 6.14.0
|
||||||
|
redis-memory-server: ^0.12.1
|
||||||
reflect-metadata: 0.2.2
|
reflect-metadata: 0.2.2
|
||||||
remove-markdown: 0.6.2
|
remove-markdown: 0.6.2
|
||||||
remove-md-codeblock: 0.0.4
|
remove-md-codeblock: 0.0.4
|
||||||
|
|||||||
Reference in New Issue
Block a user