首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行在Windows上的Github动作统一玩具示例

运行在Windows上的Github动作统一玩具示例
EN

Stack Overflow用户
提问于 2022-11-14 15:54:41
回答 1查看 38关注 0票数 1

我已经找到了一个网站(game.ci),它展示了一个运行Github动作工作流的示例,用于构建和测试Unity。

但是,我只能在Ubuntu (“ubuntu-最新”)上找到一个玩具示例。

对于Windows,我需要一个类似的文件。有人能帮我吗?

上下文:

这就是我当前Ubuntu的..github/工作流脚本的样子:

代码语言:javascript
复制
name: Test

on:
  workflow_dispatch: {}

jobs:
  build:
    name: Build my project ✨
    runs-on: ubuntu-latest
    steps:
      # Checkout
      - name: Checkout repository
        uses: actions/checkout@v2
        with:
          lfs: true

      # Cache
      - uses: actions/cache@v2
        with:
          path: MyGame/Library
          key: MyGame/Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
          restore-keys: |
            Library-

      # Test
      - name: Run tests
        uses: game-ci/unity-test-runner@v2
        env:
          UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
        with:
          projectPath: MyGame/
          githubToken: ${{ secrets.GITHUB_TOKEN }}

      # Build
      - name: Build project
        uses: game-ci/unity-builder@v2
        env:
          UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
          UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
          UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
        with:
          projectPath: MyGame/
          targetPlatform: Android

      # Output
      - uses: actions/upload-artifact@v2
        with:
          projectPath: MyGame/
          name: Build
          path: build
  • 在game.ci的网站上,只有一个Gitlab的Windows示例,而不是针对Github的。
  • 我还在国外项目中找到了一个基于windows的github统一工作流。然而,我无法使它适应我的情况。除了通过"疯疯癫癫“使用一个码头容器之外,Github操作文件使用一个名为"secrets.UNITY_TOTP_KEY”的秘密,我不知道在那里填充什么.
EN

回答 1

Stack Overflow用户

发布于 2022-11-24 12:35:48

这是一个玩具解决方案的第一个草稿,我可以在一个虚拟的团结项目上成功地运行。

前提条件:

  • 创建一个BuildScript.cs来指定构建场景和目标平台
  • 在您的统一帐户中启用2元素身份验证
    • 手动读取启动代码->作为机密输入到您各自的github存储库("UNITY_TOTP_KEY")

  • 使用联合的"Automated“创建PlayMode测试(否则注释该部分或更改为"EditorMode")
代码语言:javascript
复制
name: Run Tests on Windows
on:
  workflow_call:
    secrets:
      UNITY_EMAIL:
        required: true
      UNITY_PASSWORD:
        required: true
      UNITY_TOTP_KEY:
        required: true
jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        # Specify path of Unity project relative to repository root
        projectPath:
          - ./  
        os:
          - windows-2019
        unity:
          - { version: "2020.3.36f1", changeset: "71f96b79b9f0" }
    steps:
      
      # Install UnityHub
      - name: Install UnityHub
        uses: crazy-max/ghaction-chocolatey@v2
        with:
          args: install unity-hub -y
      
      # Install UnityEditor
      - name: Install UnityEditor
        run: |
          Start-Process -NoNewWindow -Wait -PassThru "C:\Program Files\Unity Hub\Unity Hub.exe" -ArgumentList "-- --headless install --version ${{ matrix.unity.version }} --changeset ${{ matrix.unity.changeset }}"
          exit 0

      # Generate license activation file
      - name: Generate a license activation file
        run: |
          Start-Process -NoNewWindow -Wait -PassThru "C:\Program Files\Unity\Hub\Editor\${{ matrix.unity.version }}\Editor\Unity.exe" -ArgumentList "-quit -batchmode -createManualActivationFile -logfile"
          exit 0

      # Request Unity license 
      - name: Request a Unity license file
        env:
          UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
          UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
          UNITY_TOTP_KEY: ${{ secrets.UNITY_TOTP_KEY }}
        continue-on-error: true        # Add this line to get pass the error flag
        run: |
          npm install -g unity-verify-code
          git clone -b ci https://github.com/homuler/unity-license-activate.git
          cd unity-license-activate
          npm install
          cd ..
          npm install -g ./unity-license-activate
          unity-license-activate "$env:UNITY_EMAIL" "$env:UNITY_PASSWORD" Unity_v${{ matrix.unity.version }}.alf --authenticator-key "$env:UNITY_TOTP_KEY"
      
      # # Upload a screenshot (uncomment in case of error in previous step)
      # - name:  Upload error screenshot
      #   uses: actions/upload-artifact@v1
      #   with:
      #     name: screenshot_error
      #     path: error.png

      # Use license to activate Unity editor     
      - name: Activate License
        run: |
          $ulf_file = Get-Item Unity_*.ulf
          $process = Start-Process -NoNewWindow -Wait -PassThru "C:\Program Files\Unity\Hub\Editor\${{ matrix.unity.version }}\Editor\Unity.exe" -ArgumentList "-batchmode -nographics -logFile -quit -manualLicenseFile $ulf_file"

          if ($process.ExitCode -ne 1)
          {
            exit $process.ExitCode
          }

      # Checkout source code
      - name: Checkout repository
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
          lfs: true

      # Cache Library folder
      - name: Cache Library folder
        uses: actions/cache@v2
        with:
          path: ${{ matrix.projectPath }}/Library
          key:
            Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}-${{
            hashFiles(matrix.projectPath) }}
          restore-keys: |
            Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}-
            Library-${{ matrix.projectPath }}-
            Library-

      # Run Play Mode Tests
      - name: Run play mode tests
        env:
          ARTIFACTS_PATH: testResults
        run: |
          $process = Start-Process -NoNewWindow -Wait -PassThru "C:\Program Files\Unity\Hub\Editor\${{ matrix.unity.version }}\Editor\Unity.exe" `
            -ArgumentList `
            "-batchmode -nographics `
            -logFile `
            -projectPath ${{ matrix.projectPath }} `
            -testResults $env:ARTIFACTS_PATH/results.xml `
            -runTests `
            -testPlatform PlayMode `
            -testCategory !GpuOnly;!SignalAbort"
          cat ${{ matrix.projectPath }}/$env:ARTIFACTS_PATH/results.xml
          exit $process.ExitCode
        # Arguments explained:
        # - If using '!MyCategory' then no tests with the 'MyCategory' category will be included in the run

      # Upload Test results
      - name: Upload test results
        uses: actions/upload-artifact@v2
        if: always()
        with:
          name: Test results for ${{ matrix.unity.version }} on ${{ matrix.os }}
          path: ${{ matrix.projectPath }}\testResults

      # Build
      # target platform is specified in "Assets/Editor/Scenes/BuildScript.cs"
      - name: Build apk
        env:
          ARTIFACTS_PATH: APKs
        run: |
          mkdir $env:ARTIFACTS_PATH
          $process = Start-Process -NoNewWindow -Wait -PassThru "C:\Program Files\Unity\Hub\Editor\${{ matrix.unity.version }}\Editor\Unity.exe" `
            -ArgumentList `
            "-batchmode -nographics `
            -logFile $env:ARTIFACTS_PATH/build.log `
            -projectPath ${{ matrix.projectPath }} `
            -executeMethod BuildScript.PerformBuild" 
          cat ${{ matrix.projectPath }}\$env:ARTIFACTS_PATH\build.log
          exit $process.ExitCode

      # Upload apk to Github actions
      - name: Upload apk to Github actions
        uses: actions/upload-artifact@v2
        with:
          name: APKs
          path: APKs

这个脚本的要点来自这里 (我不得不使用黑客,因为我不是来自美国)

问题:

  • 缓存目录似乎无法工作(可能是由于错误的命名)
  • 播放模式测试都失败了。这似乎是由于运行测试时的选项"-batchmode -nographics“。但是,省略这些选项会导致测试在本地Windows机器上成功运行,但在github上无限期地运行(不得不手动取消它们)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74434423

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档