Files
2026-01-29 01:34:54 +08:00

167 lines
3.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Gitea Runner Node.js
Gitea Action Runner Node.js 构建环境,基于 `gitea_runner_base` 添加多版本 Node.js 和包管理器。
## 基础镜像
- `timi/gitea_runner_base:latest`
## 包含环境
| 组件 | 版本 |
|------|------|
| Node.js | 18, 20, 22 (LTS) |
| npm | 最新 (随 Node.js) |
| yarn | 最新 |
| pnpm | 最新 |
## Node.js 版本说明
| 版本 | 状态 | 说明 |
|------|------|------|
| Node.js 18 | LTS | Hydrogen (维护至 2025-04) |
| Node.js 20 | LTS | Iron (推荐使用,维护至 2026-04) |
| Node.js 22 | Current | 当前活跃版本 |
默认使用 Node.js 20。
## 构建
```bash
# 先构建基础镜像
./rebuild.sh gitea_runner_base
# 再构建 Node.js 镜像
./rebuild.sh gitea_runner_node
```
## 切换 Node.js 版本
### 方式一:使用切换脚本
```bash
source use-node 18 # 切换到 Node.js 18
source use-node 20 # 切换到 Node.js 20
source use-node 22 # 切换到 Node.js 22
```
### 方式二:使用 n 命令
```bash
n use 18 # 切换到 Node.js 18
n use 20 # 切换到 Node.js 20
n use 22 # 切换到 Node.js 22
```
## 包管理器选择
镜像内置三种包管理器,可按需选择:
```bash
npm install # 使用 npm
yarn install # 使用 yarn
pnpm install # 使用 pnpm
```
## Gitea Action 示例
### 基础构建
```yaml
name: Node.js Build
on: [push]
jobs:
build:
runs-on: ubuntu-latest
container:
image: timi/gitea_runner_node:latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Test
run: npm test
```
### 多版本测试
```yaml
name: Multi-version Test
on: [push]
jobs:
test:
runs-on: ubuntu-latest
container:
image: timi/gitea_runner_node:latest
strategy:
matrix:
node-version: [18, 20, 22]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
run: |
source use-node ${{ matrix.node-version }}
node -v
- name: Install and test
run: |
npm install
npm test
```
### 使用不同包管理器
```yaml
name: Build with pnpm
on: [push]
jobs:
build:
runs-on: ubuntu-latest
container:
image: timi/gitea_runner_node:latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies with pnpm
run: pnpm install
- name: Build
run: pnpm build
```
## 环境变量
| 变量 | 默认值 |
|------|--------|
| `NODE_BASE` | `/usr/local/node` |
| `PATH` | 包含当前 Node.js 版本的 bin 目录 |
## 常见问题
### 如何查看已安装的 Node.js 版本?
```bash
n ls
```
### 如何全局安装 npm 包?
```bash
npm install -g <package-name>
```
### pnpm 和 yarn 的区别?
- **pnpm**: 使用硬链接节省磁盘空间,速度快,严格依赖管理
- **yarn**: 速度快离线缓存workspaces 支持好
- **npm**: Node.js 官方包管理器,兼容性最好