You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Action上传Unity构建产物为Release资产失败求助

问题分析与解决方案

核心问题

你遇到的报错源于三个关键问题:

  1. game-ci/unity-builder不会自动将构建产物打包为Galactic.zip,你指定的/build/Galactic.zip路径根本不存在
  2. GitHub Actions中使用绝对路径/build会指向Runner系统的根目录,而非仓库工作目录下的build文件夹
  3. 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

关键修改说明

  1. 调整流程顺序:将测试步骤移至构建之前,先验证代码可测试性,避免无效构建浪费资源
  2. 新增打包步骤:通过zip -r Galactic.zip build/StandaloneWindows将Unity构建的产物目录(StandaloneWindows为你指定的目标平台)打包为Galactic.zip
  3. 修正路径配置:
    • 上传Artifact时指向打包后的Galactic.zip(而非整个build目录)
    • Release步骤中仅指定相对路径Galactic.zip,确保能正确定位到文件
  4. 冗余License操作:保留了原有的License归还步骤,若觉得重复可合并(game-ci部分Action会自动处理License归还)

可选方案(无需手动打包)

如果你不想打包成Zip,也可以直接将构建目录下的所有文件作为Release资产上传,只需修改Release步骤的files配置:

files: build/StandaloneWindows/**/*

内容的提问来源于stack exchange,提问作者user

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 20:23:16