GitHub Action上传Unity构建产物为Release资产失败求助
问题分析与解决方案
核心问题
你遇到的报错源于三个关键问题:
game-ci/unity-builder不会自动将构建产物打包为Galactic.zip,你指定的/build/Galactic.zip路径根本不存在- GitHub Actions中使用绝对路径
/build会指向Runner系统的根目录,而非仓库工作目录下的build文件夹 - Release步骤中配置的所有文件路径均错误,导致无法定位到实际构建产物
修正后的YAML配置
以下是调整后的完整配置,解决了路径错误并优化了流程顺序:
name: Building and Testing 😎 on: push: branches: - cd-testing - main - build-fix - unity-cd jobs: build: name: Build my project ✨ runs-on: ubuntu-latest steps: # 拉取代码 - name: Checkout repository uses: actions/checkout@v2 with: lfs: true # 缓存Unity Library目录,加速构建 - name: Cache uses: actions/cache@v2 with: path: PlatformerStealthGame/Library key: Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }} restore-keys: | Library-PlatformerStealthGame- Library- # 先执行测试,确保代码合格再构建 - name: Run tests uses: game-ci/unity-test-runner@v2 env: UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }} with: projectPath: PlatformerStealthGame githubToken: ${{ secrets.GITHUB_TOKEN }} # targetPlatform: WebGL - name: Unity - Return License uses: game-ci/unity-return-license@v2.0.0 # Unity项目构建 - name: Build project uses: game-ci/unity-builder@v2 env: UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }} with: projectPath: PlatformerStealthGame targetPlatform: StandaloneWindows # 将构建产物打包为Zip(关键步骤) - name: Package Build into Zip run: zip -r Galactic.zip build/StandaloneWindows # 上传打包后的产物作为Artifact - uses: actions/upload-artifact@v2 with: name: Galactic path: Galactic.zip - name: Unity - Return License uses: game-ci/unity-return-license@v2.0.0 # 发布Release资产 - name: Automatic Releases uses: marvinpinto/action-automatic-releases@v1.2.1 with: repo_token: "${{ secrets.GITHUB_TOKEN }}" automatic_release_tag: "latest" prerelease: false title: "Development Build" files: Galactic.zip - name: Unity - Return License uses: game-ci/unity-return-license@v2.0.0
关键修改说明
- 调整流程顺序:将测试步骤移至构建之前,先验证代码可测试性,避免无效构建浪费资源
- 新增打包步骤:通过
zip -r Galactic.zip build/StandaloneWindows将Unity构建的产物目录(StandaloneWindows为你指定的目标平台)打包为Galactic.zip - 修正路径配置:
- 上传Artifact时指向打包后的
Galactic.zip(而非整个build目录) - Release步骤中仅指定相对路径
Galactic.zip,确保能正确定位到文件
- 上传Artifact时指向打包后的
- 冗余License操作:保留了原有的License归还步骤,若觉得重复可合并(game-ci部分Action会自动处理License归还)
可选方案(无需手动打包)
如果你不想打包成Zip,也可以直接将构建目录下的所有文件作为Release资产上传,只需修改Release步骤的files配置:
files: build/StandaloneWindows/**/*
内容的提问来源于stack exchange,提问作者user
相关产品推荐
相关产品推荐

