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

使用GitHub Actions构建src目录下Unity项目的问题排查

问题描述

我正在搭建CD流水线,实现Unity项目从GitHub自动发布到itch.io,但项目数据存放在仓库的src目录中,流水线尝试从根目录访问文件导致异常。以下是我的main.yaml配置:

name: Build Project and Publish to itch.io
on: 
  push:
    branches:
      - 'main'
jobs:
  build:
    name: Build Project and Publish to itch.io ✨
    runs-on: ubuntu-latest
    # This stops builds that are in-progress once a new commit comes in
    concurrency: 
      group: unity-build
      cancel-in-progress: true
    steps:
      # Checkout
      - name: Checkout repository
        uses: actions/checkout@v2
        with:
          path: ./src
          lfs: true     
      # Cache
      - uses: actions/cache@v2
        with:
          path: Library
          key: Library      
      # Build
      - name: Build project
        uses: game-ci/unity-builder@v2
        env:
          UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
        with:
          projectPath: ./src
          targetPlatform: StandaloneWindows       
 
        # Upload to Itch
      - uses: josephbmanley/butler-publish-itchio-action@master
        env:
          BUTLER_CREDENTIALS: ${{ secrets.BUTLER_CREDENTIALS }}
          CHANNEL: windows
          ITCH_GAME: (myitchgamename)
          ITCH_USER: (myitchusername)
          PACKAGE: build/StandaloneWindows

我是GitHub Actions新手,不太理解工作目录,请问我哪里出错了?

问题分析与解决

你的配置有三个关键问题:

  1. YAML语法缩进错误
    # Upload to Itch对应的发布步骤被错误缩进在了Build project步骤的with块内,导致该步骤无法被正确识别执行,甚至会引发语法解析异常。需要将该步骤的缩进调整到和前面的步骤同级。

  2. 缓存路径不匹配
    Unity项目的Library目录会生成在项目根目录(即你指定的./src)下,但你配置的缓存路径是Library,这是相对于工作目录根的路径,实际找不到对应目录。需将缓存路径改为./src/Library,确保缓存能正确命中和复用。

  3. 发布路径指向错误
    game-ci/unity-builder会在你指定的projectPath(即./src)下生成build文件夹,构建产物的实际路径是./src/build/StandaloneWindows,但你配置的PACKAGE参数是build/StandaloneWindows,该路径在工作目录根下不存在,需修正为./src/build/StandaloneWindows。

修正后的完整配置如下:

name: Build Project and Publish to itch.io
on: 
  push:
    branches:
      - 'main'
jobs:
  build:
    name: Build Project and Publish to itch.io ✨
    runs-on: ubuntu-latest
    # This stops builds that are in-progress once a new commit comes in
    concurrency: 
      group: unity-build
      cancel-in-progress: true
    steps:
      # Checkout
      - name: Checkout repository
        uses: actions/checkout@v2
        with:
          path: ./src
          lfs: true     
      # Cache
      - uses: actions/cache@v2
        with:
          path: ./src/Library
          key: Library      
      # Build
      - name: Build project
        uses: game-ci/unity-builder@v2
        env:
          UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
        with:
          projectPath: ./src
          targetPlatform: StandaloneWindows       
 
      # Upload to Itch
      - uses: josephbmanley/butler-publish-itchio-action@master
        env:
          BUTLER_CREDENTIALS: ${{ secrets.BUTLER_CREDENTIALS }}
          CHANNEL: windows
          ITCH_GAME: (myitchgamename)
          ITCH_USER: (myitchusername)
          PACKAGE: ./src/build/StandaloneWindows

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 04:16:30