This commit is contained in:
@@ -7,54 +7,97 @@ jobs:
|
||||
Explore-Gitea-Actions:
|
||||
runs-on: ubuntu64
|
||||
steps:
|
||||
- name: 拉取代码仓库
|
||||
- name: 拉取代码
|
||||
uses: http://git.missmoc.top/mocheng/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # 只拉取最新的1个提交(浅克隆)
|
||||
fetch-depth: 0
|
||||
|
||||
# - name: Set up Node.js
|
||||
# uses: http://git.missmoc.top/mocheng/setup-node@v3
|
||||
# with:
|
||||
# node-version: 20.x
|
||||
|
||||
- name: 5. HBuilderX 账户登录
|
||||
id: hbx_login
|
||||
run: |
|
||||
echo "开始登录 HBuilderX 账户..."
|
||||
LOGIN_OUTPUT=$(/hbuildcli/HBuilderX/cli user login --username ${{ secrets.HBUILDERX_USERNAME }} --password ${{ secrets.HBUILDERX_PASSWORD }})
|
||||
- name: 6. 打包 Uniapp(实时显示排队/进度)
|
||||
id: uniapp_build
|
||||
run: |
|
||||
echo "开始打包 Uniapp 项目,当前时间:$(date +%Y-%m-%d_%H:%M:%S)"
|
||||
echo "========================================"
|
||||
echo "正在查询打包队列状态..."
|
||||
# (可选)提前查询队列(部分场景下 HBuilderX 会返回排队信息)
|
||||
/hbuildcli/HBuilderX/cli publish --platform android --query-queue
|
||||
echo "========================================"
|
||||
echo "开始执行打包(实时输出进度)..."
|
||||
# 执行打包命令(根据目标平台调整 --platform 参数,支持 android/ios/h5 等)
|
||||
# --project:指定项目根目录(当前检出目录)
|
||||
# --output:指定产物输出目录(便于后续归档)
|
||||
/hbuildcli/HBuilderX/cli publish --platform android --project ./ --output ./unpackage/dist/build/android
|
||||
echo "========================================"
|
||||
echo "Uniapp 打包完成!产物路径:./unpackage/dist/build/android"
|
||||
|
||||
- name: 7. 归档打包产物
|
||||
uses: https://gitea.com/actions/upload-artifact@v1 # Gitea 产物归档插件
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
name: uniapp-android-build # 产物压缩包名称
|
||||
path: ./unpackage/dist/build/android # 产物目录(与步骤 6 的 --output 对应)
|
||||
retention-days: 7 # 产物保留时间(7 天,可调整)
|
||||
node-version: 16
|
||||
cache: 'npm'
|
||||
|
||||
post:
|
||||
- name: 8. HBuilderX 账户登出
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
echo "开始登出 HBuilderX 账户..."
|
||||
LOGOUT_OUTPUT=$(/hbuildcli/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 登出成功!"
|
||||
npm install
|
||||
# 安装HBuilderX命令行工具
|
||||
npm install -g hbuilderx-cli
|
||||
|
||||
- name: Build H5 project
|
||||
run: |
|
||||
# 执行HBuild项目构建
|
||||
npm run build
|
||||
|
||||
- name: Cloud package (Android)
|
||||
run: |
|
||||
# 使用HBuilderX CLI进行云打包
|
||||
hbuilderx package \
|
||||
--project . \
|
||||
--platform android \
|
||||
--appid ${{ secrets.HBUILDER_APPID }} \
|
||||
--username ${{ secrets.HBUILDER_USERNAME }} \
|
||||
--password ${{ secrets.HBUILDER_PASSWORD }} \
|
||||
--output ./dist
|
||||
env:
|
||||
HBUILDER_CLOUD_PACKAGE: true
|
||||
|
||||
- name: Cloud package (iOS)
|
||||
run: |
|
||||
hbuilderx package \
|
||||
--project . \
|
||||
--platform ios \
|
||||
--appid ${{ secrets.HBUILDER_APPID }} \
|
||||
--username ${{ secrets.HBUILDER_USERNAME }} \
|
||||
--password ${{ secrets.HBUILDER_PASSWORD }} \
|
||||
--output ./dist
|
||||
env:
|
||||
HBUILDER_CLOUD_PACKAGE: true
|
||||
# 可选:仅在有标签推送时才构建iOS版本
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
|
||||
- name: Prepare release assets
|
||||
run: |
|
||||
# 重命名APK文件以便于识别版本
|
||||
mv ./dist/*.apk ./dist/app-release-${{ github.sha }}.apk
|
||||
# 对于iOS,根据实际打包输出调整
|
||||
if [ -f ./dist/*.ipa ]; then
|
||||
mv ./dist/*.ipa ./dist/app-release-${{ github.sha }}.ipa
|
||||
fi
|
||||
|
||||
- name: Create Gitea Release
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
uses: actions/create-release@v1
|
||||
with:
|
||||
tag_name: ${{ github.ref_name }}
|
||||
release_name: Release ${{ github.ref_name }}
|
||||
body: |
|
||||
自动构建版本 ${{ github.ref_name }}
|
||||
提交哈希: ${{ github.sha }}
|
||||
draft: false
|
||||
prerelease: false
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
|
||||
- name: Upload Android Asset
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
uses: actions/upload-release-asset@v1
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./dist/app-release-${{ github.sha }}.apk
|
||||
asset_name: app-android-${{ github.ref_name }}.apk
|
||||
asset_content_type: application/vnd.android.package-archive
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
|
||||
- name: Upload iOS Asset
|
||||
if: startsWith(github.ref, 'refs/tags/') && -f ./dist/app-release-${{ github.sha }}.ipa
|
||||
uses: actions/upload-release-asset@v1
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./dist/app-release-${{ github.sha }}.ipa
|
||||
asset_name: app-ios-${{ github.ref_name }}.ipa
|
||||
asset_content_type: application/octet-stream
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
|
||||
|
Reference in New Issue
Block a user