Compare commits

..

2 Commits

Author SHA1 Message Date
09eb3e089b cicd 2025-08-24 19:20:31 +08:00
a02da12c32 修改打包 2025-08-24 18:59:51 +08:00
19 changed files with 142 additions and 5 deletions

133
.gitea/workflows/master.yml Normal file
View File

@@ -0,0 +1,133 @@
name: Uniapp 自动化打包 CI/CD
# 触发条件:可根据需求调整(如 push 到 main 分支、打 tag 时触发)
on:
push:
branches: [ main ] # 分支触发
# tag:
# - 'v*' # 版本 tag 触发(可选)
# 运行环境
jobs:
build:
name: 打包 Uniapp 项目
runs-on: ubuntu-latest # 云 Runner 环境(自建 Runner 可替换为自定义名称)
steps:
########################################################################
# 步骤 1检出 Gitea 代码
########################################################################
- name: 1. 检出项目代码
uses: actions/checkout@v4 # Gitea 兼容的代码检出插件
with:
fetch-depth: 1 # 仅拉取最新代码,加速流程
########################################################################
# 步骤 2安装 Node.js 环境Uniapp 依赖 Node 处理项目依赖)
########################################################################
- name: 2. 安装 Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x' # 推荐 16.x+,适配 Uniapp 依赖
cache: 'npm' # 缓存 npm 依赖,加速后续构建
########################################################################
# 步骤 3安装 Uniapp 项目依赖
########################################################################
- name: 3. 安装项目依赖
run: |
echo "开始安装项目依赖..."
npm install --registry=https://registry.npmmirror.com # 国内源加速(可选)
echo "项目依赖安装完成"
########################################################################
# 步骤 4下载并部署 HBuilderX CLI若 Runner 未预装)
########################################################################
- name: 4. 部署 HBuilderX CLI 到 /hbuilderxcli/HBuilderX
run: |
# 创建 CLI 目标目录
sudo mkdir -p /hbuilderxcli/HBuilderX
# 下载 HBuilderX Linux 完整版(版本 ≥3.1.5,可替换为最新版)
wget -O hbuilderx.zip https://download1.dcloud.net.cn/download/HBuilderX.4.0.14.20240528.full.zip
# 解压到目标目录
unzip -q hbuilderx.zip -d /hbuilderxcli/HBuilderX
# 赋予 CLI 执行权限
sudo chmod +x /hbuilderxcli/HBuilderX/cli
# 验证 CLI 版本(确保部署成功)
/hbuilderxcli/HBuilderX/cli -v
echo "HBuilderX CLI 部署完成,路径:/hbuilderxcli/HBuilderX/cli"
########################################################################
# 步骤 5HBuilderX 密钥登录(安全读取账户信息)
########################################################################
- name: 5. HBuilderX 账户登录
id: hbx_login
run: |
echo "开始登录 HBuilderX 账户..."
# 执行登录命令(读取 Gitea Secrets 中的账户密码)
LOGIN_OUTPUT=$(/hbuilderxcli/HBuilderX/cli user login --username ${{ secrets.HBUILDERX_USERNAME }} --password ${{ secrets.HBUILDERX_PASSWORD }})
# 打印登录输出(便于调试,无敏感信息)
echo "登录结果:$LOGIN_OUTPUT"
# 验证登录是否成功(根据文档,成功返回 "0:user login:OK"
if [[ $? -ne 0 || $(echo "$LOGIN_OUTPUT" | grep -c "0:user login:OK") -eq 0 ]]; then
echo "HBuilderX 登录失败!"
exit 1 # 登录失败则终止 CI/CD 流程
fi
echo "HBuilderX 登录成功!"
########################################################################
# 步骤 6实时显示打包进度 + 执行 Uniapp 打包
########################################################################
- name: 6. 打包 Uniapp实时显示排队/进度)
id: uniapp_build
run: |
echo "开始打包 Uniapp 项目,当前时间:$(date +%Y-%m-%d_%H:%M:%S)"
echo "========================================"
echo "正在查询打包队列状态..."
# (可选)提前查询队列(部分场景下 HBuilderX 会返回排队信息)
/hbuilderxcli/HBuilderX/cli publish --platform android --query-queue
echo "========================================"
echo "开始执行打包(实时输出进度)..."
# 执行打包命令(根据目标平台调整 --platform 参数,支持 android/ios/h5 等)
# --project指定项目根目录当前检出目录
# --output指定产物输出目录便于后续归档
BUILD_OUTPUT=$(/hbuilderxcli/HBuilderX/cli publish \
--platform android \
--project ./ \
--output ./unpackage/dist/build/android \
--progress # 强制输出打包进度(部分版本需显式指定)
)
# 实时打印打包日志(包含排队进度、编译进度等信息)
echo "$BUILD_OUTPUT"
# 验证打包是否成功(根据实际输出调整判断条件,示例:找 "打包成功" 关键字)
if [[ $? -ne 0 || $(echo "$BUILD_OUTPUT" | grep -c "打包成功") -eq 0 ]]; then
echo "Uniapp 打包失败!"
exit 1
fi
echo "========================================"
echo "Uniapp 打包完成!产物路径:./unpackage/dist/build/android"
########################################################################
# 步骤 7归档打包产物便于下载和后续部署
########################################################################
- name: 7. 归档打包产物
uses: gitea/actions/upload-artifact@v1 # Gitea 产物归档插件
with:
name: uniapp-android-build # 产物压缩包名称
path: ./unpackage/dist/build/android # 产物目录(与步骤 6 的 --output 对应)
retention-days: 7 # 产物保留时间7 天,可调整)
########################################################################
# 后置步骤:无论打包成功/失败,均执行 HBuilderX 登出(安全规范)
########################################################################
post:
- name: 8. HBuilderX 账户登出
run: |
echo "开始登出 HBuilderX 账户..."
LOGOUT_OUTPUT=$(/hbuilderxcli/HBuilderX/cli user logout)
echo "登出结果:$LOGOUT_OUTPUT"
# 验证登出是否成功(根据文档,成功返回 "0:user logout:OK"
if [[ $(echo "$LOGOUT_OUTPUT" | grep -c "0:user logout:OK") -eq 0 ]]; then
echo "HBuilderX 登出异常(非致命错误,不终止流程)"
else
echo "HBuilderX 登出成功!"
fi

View File

@@ -1,7 +1,7 @@
{ {
"name" : "数字南川", "name" : "数字南川",
"appid" : "__UNI__3570A56", "appid" : "__UNI__7AF1078",
"description" : "aidex敏捷开发平台", "description" : "",
"versionName" : "1.8.4", "versionName" : "1.8.4",
"versionCode" : "100", "versionCode" : "100",
"transformPx" : false, "transformPx" : false,
@@ -26,7 +26,9 @@
"nvueCompiler" : "uni-app", "nvueCompiler" : "uni-app",
"compilerVersion" : 3, "compilerVersion" : 3,
"modules" : { "modules" : {
"Payment" : {} "Payment" : {},
"Camera" : {},
"Barcode" : {}
}, },
"distribute" : { "distribute" : {
"android" : { "android" : {
@@ -55,7 +57,9 @@
], ],
"abiFilters" : [ "armeabi-v7a", "arm64-v8a" ] "abiFilters" : [ "armeabi-v7a", "arm64-v8a" ]
}, },
"ios" : {}, "ios" : {
"dSYMs" : false
},
"sdkConfigs" : { "sdkConfigs" : {
"ad" : {}, "ad" : {},
"payment" : { "payment" : {
@@ -103,7 +107,7 @@
} }
}, },
"splashscreen" : { "splashscreen" : {
"androidStyle" : "default", "androidStyle" : "common",
"android" : { "android" : {
"hdpi" : "E:/vueworkspace/aidex-m2m/src/assets/logo.png", "hdpi" : "E:/vueworkspace/aidex-m2m/src/assets/logo.png",
"xhdpi" : "E:/vueworkspace/aidex-m2m/src/assets/logo.png", "xhdpi" : "E:/vueworkspace/aidex-m2m/src/assets/logo.png",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 705 B

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB