mirror of https://gitee.com/floraachy/llalaad.git
119 lines
4.7 KiB
Markdown
119 lines
4.7 KiB
Markdown
## 📦 创建发行版 Action 节点
|
||
|
||
### 📝 介绍
|
||
|
||
本 Action 支持用户通过节点登录指定仓库并创建发行版。它提供了灵活的参数配置,确保用户可以轻松地自动化发行版的创建过程。
|
||
|
||
### ⚡ 功能特点
|
||
|
||
- **自动化创建发行版**:支持在指定仓库中创建发行版。
|
||
- **灵活的参数配置**:提供多种参数,满足不同需求。
|
||
- **随机标题生成**:防止发行版标题重复。
|
||
- **本地调试支持**:方便开发者在本地测试和调试。
|
||
|
||
### ⚙️ 各项参数
|
||
|
||
| 参数名 | 必填 | 描述 |
|
||
|------------------|------|--------------------------------------------------------------------|
|
||
| `domain` | ✅ 必填 | 域名,默认为http://172.20.32.201:4000 |
|
||
| `username` | ✅ 必填 | 对需要发行版本的仓库具备管理员权限的用户。 |
|
||
| `password` | ✅ 必填 | 用户名对应的密码。 |
|
||
| `repository` | ❌选填 | 仓库名,格式:`拥有者/仓库标识`,例如:`tester/test`。为空则默认为当前流水线保存的仓库。 |
|
||
| `release_title` | ✅ 必填 | 发行版标题。为防止重复,会在用户输入标题后拼接随机字符,例如 `test_SD123`。 |
|
||
| `release_desc` | ❌选填 | 发行版描述。 |
|
||
| `tag_name` | ❌选填 | 标记。为空则自动生成 5 位长度的随机字符(字母和数字组成)。 |
|
||
| `sha` | ❌选填 | 分支或 SHA。为空则为当前仓库的默认分支名称。 |
|
||
|
||
---
|
||
|
||
### 📂 框架结构
|
||
|
||
```
|
||
publish-release-action/
|
||
├── 📁 dist/ # ncc 打包后的输出目录
|
||
├── 📁 src/ # 源代码目录
|
||
│ └── 📄 index.js # 入口文件
|
||
├── 📄 package.json # 项目配置文件
|
||
└── 📁 node_modules/ # 依赖目录
|
||
```
|
||
|
||
### 🛠️ 使用说明
|
||
1. **安装 Node.js**:
|
||
- 推荐使用 [nvm](https://github.com/nvm-sh/nvm) 安装 Node.js,版本为 `20.18.3`。
|
||
- 安装完成后,配置环境变量,确保 `node -v` 和 `npm -v` 命令生效。
|
||
|
||
2. **安装 ncc**:
|
||
- 通过以下命令安装 [ncc](https://github.com/vercel/ncc):
|
||
```bash
|
||
npm i -g @vercel/ncc
|
||
```
|
||
- **说明**:`ncc` 是一个将 Node.js 项目打包成单个文件的工具,通常用于部署或分发。
|
||
|
||
3. **编译代码**:
|
||
- 使用 `ncc` 编译代码:
|
||
```bash
|
||
ncc build src/index.js -o dist
|
||
```
|
||
- **说明**:
|
||
- 📄 `src/index.js` 是你的入口文件。
|
||
- `-o dist` 指定输出目录为 `dist`。
|
||
- 编译完成后,你会看到一个包含代码和已编译模块的新 `dist/index.js` 文件,以及一个 `dist/licenses.txt`
|
||
文件,其中包含所有依赖的许可证信息。
|
||
|
||
4. **更新 `action.yml` 文件**:
|
||
- 将 `action.yml` 文件中的 `main` 关键字更新为使用新的 `dist/index.js` 文件:
|
||
```yaml
|
||
main: 'dist/index.js'
|
||
```
|
||
- **注意**:如果已签入 `node_modules` 目录,请将其删除:
|
||
```bash
|
||
rm -rf node_modules/*
|
||
```
|
||
|
||
5. **提交更新**:
|
||
- 从终端提交对 `action.yml`、`dist/index.js` 和 `node_modules` 文件的更新。
|
||
|
||
### 🐛在本地调试编译后的代码
|
||
如果你只是调试 Node.js 代码,可以直接运行编译后的文件:
|
||
|
||
#### Windows
|
||
|
||
```bash
|
||
node dist/index.js
|
||
```
|
||
|
||
由于这里涉及到参数传递,所以需要设置环境变量。具体如下:
|
||
|
||
```bash
|
||
set INPUT_USERNAME=用户名
|
||
set INPUT_PASSWORD=密码
|
||
set INPUT_REPOSITORY=仓库
|
||
set INPUT_RELEASE_TITLE=发行版标题
|
||
set INPUT_RELEASE_DESC=发行版描述
|
||
set INPUT_TAG_NAME=标记
|
||
set INPUT_SHA=分支或者sha
|
||
node dist/index.js
|
||
|
||
```
|
||
|
||
单行命令:
|
||
```bash
|
||
set INPUT_USERNAME=用户名 && set INPUT_PASSWORD=密码 && set INPUT_REPOSITORY=仓库 && set INPUT_RELEASE_TITLE=发行版标题 && set INPUT_RELEASE_DESC=发行版描述 && node dist/index.js
|
||
```
|
||
|
||
#### macOS/Linux
|
||
```bash
|
||
export INPUT_USERNAME=用户名
|
||
export INPUT_PASSWORD=密码
|
||
export INPUT_REPOSITORY=仓库
|
||
export INPUT_RELEASE_TITLE=发行版标题
|
||
export INPUT_RELEASE_DESC=发行版描述
|
||
export INPUT_TAG_NAME=标记
|
||
export INPUT_SHA=分支或者sha
|
||
node dist/index.js
|
||
```
|
||
单行命令:
|
||
```bash
|
||
export INPUT_USERNAME=用户名 && export INPUT_PASSWORD=密码 && export INPUT_REPOSITORY=仓库 && export INPUT_RELEASE_TITLE=发行版标题 && export INPUT_RELEASE_DESC=发行版描述 && node dist/index.js
|
||
```
|