Unity

Unity Git hub Acitons - 3 (Unity 연동)

dev_hyunn 2025. 3. 1. 16:11

[Git hub Action Workflow 작성]

 

이전 글들에서 Git hub Actions의 구성요소 및 키워드들에 대해서 알아보았고, 간단한 예제의 Workflow를 작성해 보았습니다. 이번 글에서는 Workflow를 통해 Unity 빌드를 자동화하는 작업을 진행해 보겠습니다.

 

Unity를 기존에 빌드하기 위해서는 Unity Editor에 Login 및 라이선스를 할당해주어야 합니다. Github Action으로 빌드를 진행할 때도 마찬가지로, 로그인 및 라이선스 정보가 필요합니다. 하지만 이런 개인정보 및 공개되지 않아야 되는 정보는 Github의 Secrets에 기입하여 숨겨둔 상태로 사용합니다. 그리하여, Github Secrets을 등록을 진행해 줍니다.

 

등록 Secrets 

Settings > Secrets and Variables  > Actions

  • Unity Email : 유니티 로그인 시 ID (email)
  • Unity Password : 유니티 로그인시 Password 
  • Unity License : 유니티 License(Pro, Industry, personal)

Create Secret

먼저 순서대로 아래와 같은 순서대로 테스트를 진행하며, Workflow를 확장해보려고 합니다.

 

  1. 단순 Unity Build, 결과가 정상적으로 출력되는지 확인.
  2. Unity Build가 완료된 상태에서 해당 결과물(여기서는. apk) 파일을 Artifact에 업로드를 진행합니다. 
  3. 해당 Build 파일을 다른 Discord나, Slack 채널에 업로드를 진행하여 다른 팀원들에게 공유가 가능하게 진행해보려고 합니다.

 

먼저 첫 번째 Step입니다.

 

Unity Build

name: Unity Android Build Sample 😎

on: 
  issues:
    types: 
    - opened

jobs:
  build:
    name: Build my project ✨
    runs-on: ubuntu-latest
    steps:
      # Checkout
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          lfs: true
      # Cache
      - uses: actions/cache@v3
        with:
          path: Library
          key: Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
          restore-keys: |
            Library-
      # Build
      - name: Build project
        uses: game-ci/unity-builder@v4
        env:
          UNITY_LICENSE: ${{ secrets.UNITY_LICENSE}}
          UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
          UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
        with:
          targetPlatform: Android

각 Key별로 나타내는 동작 및 의미가 다릅니다.

  • name : 해당 Workflow, Jobs, Step의 이름을 지정합니다. 이는 Actions의 Summary의 각 Step별 명칭을 나타냅니다.
  • uses : 어떤 Actions을 사용할지에대한 명령어 지시문입니다. ex) Marketplace에 업로드되어있는 actions들을 사용할 수 있습니다. 여기서 사용한 Actions은 'game-ci/unity-builder', 'actions/checkout', actions/cache 등을 사용하였습니다.
  • env : 해당 Actions의 환경값을 지정해줍니다. 이는 각 Actions 별로 상이하며, 여기서는 유니티 라이선스, 이메일, 비밀번호등을 추가하여, 빌드에 적용합니다.
  • with : 해당 Actions에 어떤 작업을 포함할지에대한 추가 데이터입니다. 여기서는 Build Platform을 지정하였습니다.

위의 Unity Build에 대한 Workflow를 해석하면 아래와 같습니다.

Workflow의 Name은 Unity Android Build Sample입니다.
해당 Workflow의 Event 발생 시점(on)은 issues가 opened Type 일 때 트리거되게 됩니다.
해당 Workflow는 하위 Jobs로 구성되어 있습니다. build를 진행하며 해당 각 Jobs은 Dependency가 있으므로 순차적으로 진행됩니다.

1. name : Build My project
2. runs-on : 해당 Actions을 동작할 runner를 지정 여기서는 ubuntu-latest
3. 하위 Steps들로 이루어져 있습니다.

Steps
1. checkout Repository
2. 현재 build Cache Check
3. Unity GameCi를 활용하여 Unity Build 빌듯이 env(유니티 계정 아이디, 비밀번호, 유니티 라이선스 등)을 추가하여 빌드

 

문제점 발생

위 방식으로 빌드하였을 때 아래와 같은 문제가 발생하게 됩니다.

 

1.  무료 Github 사용자의 경우 runner 우분투의 memory 크기가 작아 두 번째 빌드부터 우분투의 남아있는 메모리가 적어 아래와 같은 에러를 발생시킵니다.

 

docker의 no space left on device

 

이를 해결하기 위해서는 아래와같은 공식문서 가이드를 확인할 수 있습니다.

No space left on Device

 

Error: "Out of disk" or Error: "Out of memory" - GitHub Docs

If you see one of these errors with GitHub Actions, you can try alternative runners.

docs.github.com

Fixing the problem
If the runners you're using don't meet the recommended hardware requirements, consider using either larger runners or self-hosted runners.

Larger runners are GitHub-hosted runners with more RAM, CPU, and disk space than standard runners. These runners have the runner application and other tools preinstalled. For more information about larger runners and code scanning, see Using larger runners and Configuring larger runners for default setup.

Self-hosted runners offer more control of hardware, operating system, and software tools than GitHub-hosted runners can provide. For more information, see About self-hosted runners.

 

3가지의 방법으로 해결해 볼 수 있을 것 같습니다.

1. 무료로 제공하는 Github-hosted runners의 경우에는 성능이 많이 낮습니다.

2. 더 성능이 좋은 Github-hosted runners를 사용하여 메모리 부족을 해결합니다.

3. Self-hosted runner를 사용하여 메모리 부족을 해결합니다.

 

여기서 self-hosted runner란?

  • Github의 hosted runner가 아닌 실제 Local Device의 성능을 사용하여 빌드를 하는 방식입니다. 예를 들어 실제 작업하고 있는 노트북 말고 사용이 가능한 노트북 혹은 macOs를 활용하는 방식입니다.

But , Github-hosted runners의 무료 성능만으로 빌드를 자동화하고 싶어, 이를 좀 더 확인해 보니, 최초 빌드하였을 때 정상적으로 성공하는 것을 확인하였으니, 빌드하기 전에 ubuntu의 Disk Space Clear 하는 방식도 종종 확인할 수 있었습니다. 아래 그 예시로 yml 파일을 변경해 보았습니다.

name: Unity Android Build Sample 😎

on: 
  issues:
    types: 
    - opened

jobs:
  build:
    name: Build my project ✨
    runs-on: ubuntu-latest
    steps:
      # Clear Disk Space
      - name: Free Disk Space (Ubuntu)
        uses: jlumbroso/free-disk-space@main
        with:
          # this might remove tools that are actually needed,
          # if set to "true" but frees about 6 GB
          tool-cache: false
        
          # all of these default to true, but feel free to set to
          # "false" if necessary for your workflow
          android: true
          dotnet: true
          haskell: true
          large-packages: true
          docker-images: true
          swap-storage: true
      # Checkout
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          lfs: true
      # Cache
      - uses: actions/cache@v3
        with:
          path: Library
          key: Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
          restore-keys: |
            Library-
      # Build
      - name: Build project
        uses: game-ci/unity-builder@v4
        env:
          UNITY_LICENSE: ${{ secrets.UNITY_LICENSE}}
          UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
          UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
        with:
          targetPlatform: Android

 

다음 시간에는 빌드된 apk파일을 discord 서버 혹은 github에 배포하는 방식까지 알아보려고합니다.