Unity CI/CD Sample

Yumin·2024년 12월 22일
0

Unity

목록 보기
1/18

Github Action

아래의 코드로 CI / CD를 시도 했으나 Disk 부족의 문제가 발생
따라서 Free Up Disk Space의 부분을 더 강화를 해보았다.

현재도 해당 문제는 해결중에 있음.

2024 - 12 - 23 해결은 완료 했으나
아직 Action 공부가 부족해서 좀 더 최적화 요소 고민중

name: UnityBuild

on:
  workflow_dispatch:

permissions: write-all
  
jobs:
  buildForAndroid: 
    name: Build Android
    runs-on: ubuntu-latest
    steps:

      # Step1 - Check Out
      - name: Check Out
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
          lfs: true

      # Step2 - Cache Library
      - name: Cache Library
        uses: actions/cache@v4.0.2
        with: 
          path: Library
          key: Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
          restore-keys: |
            Library-
      # Step3 - Free up disk space
      - name: Free Disk Space for Android
        run: |
          sudo swapoff -a
          sudo rm -f /swapfile
          sudo apt clean
          docker images -q | xargs --no-run-if-empty docker rmi
          df -h
            
      # Step4 - Unity Build
      - name: Unity Build
        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
      
      # Step5 - Upload Build File
      - name: Upload Build File
        uses: actions/upload-artifact@v3
        with:
          name: Build-Android
          path: build

24년 12월 23일 수정된 코드

name: UnityBuild

on:
  push: # Master 브랜치에 Push가 되면 빌드가 되도록 동작시킵니다.
    branches: [ main ]

permissions: write-all

jobs:
  buildForAndroid:
    name: Build Android
    runs-on: ubuntu-latest
    steps:
      # Step1 - Check Out
      - name: Check Out
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
          lfs: true

      # Step2 - Cache Library
      - name: Cache Library
        uses: actions/cache@v4.0.2
        with: 
          path: Library
          key: Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
          restore-keys: |
            Library-
      # Step3 - Cache Temp Directory
      - name: Cache Temp Directory
        uses: actions/cache@v4.0.2
        with: 
          path: Temp
          key: Temp-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
          restore-keys: |
            Temp-
      # Step4 - Free up Disk Space
      - name: Free Disk Space for Android
        run: |
          sudo apt-get clean
          sudo apt-get autoremove -y
          sudo rm -rf /usr/share/dotnet
          sudo rm -rf /usr/local/lib/android
          sudo rm -rf /opt/ghc
          sudo rm -rf /tmp/*
          sudo rm -rf /var/tmp/*
          sudo rm -rf /usr/share/man/*
          sudo rm -rf /usr/share/doc/*
          sudo rm -rf /usr/share/locale/*
          docker images -q | xargs --no-run-if-empty docker rmi
          df -h
      # Step5 - Unity Build
      - name: Unity Build
        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

      # Step6 - Upload Build File
      - name: Upload Build File
        uses: actions/upload-artifact@v3
        with:
          name: Build-Android
          path: build

Discord 알림 WebHook 추가

name: Test Discord Notification

on:
  workflow_dispatch: # 수동 실행을 위한 트리거

jobs:
  test-discord-notify:
    runs-on: ubuntu-latest
    steps:
      # 기본적으로 리포지토리 체크아웃
      - name: Checkout repository
        uses: actions/checkout@v3

      # Discord 알림 테스트 스텝 추가
      - name: Notify discord
        uses: th0th/notify-discord@v0.4.1
        if: ${{ always() }} # 항상 실행
        env:
          DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_GITHUBACTION_WEBHOOKURL }}
          GITHUB_ACTOR: ${{ github.actor }}
          GITHUB_JOB_NAME: "Build and deploy"
          GITHUB_JOB_STATUS: ${{ job.status }}
profile
クリエイティブを楽しむ開発者

0개의 댓글