unity

github에서 빌려주는 cicd용 컴퓨터에서 unity builder를 통해서 빌드 후 빌드 된 파일을 다시 다른 repository에 올리게 된다. 그럼 그 repository의 파일을 github page나 vercel 같은 정적 페이지 배포 서비스에서 읽어서 배포를 해주게 된다.

  • UNITY_LICENSE: Mac 기준 /Library/Application Support/Unity/*.ulf에서 얻을 수 있다.
  • GITHUB_TOKEN: github에서 content에 read write에 대한 token으로 얻을 수 있다.
  • 버전에 민감하다. [2022.3.22f1에서 성공]

./.github/workflows/deploy.yml

name: Build and Deploy WebGL

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  buildWebGL:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Cache Library folder
        uses: actions/cache@v4
        with:
          path: Library
          key: Library-WebGL-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
          restore-keys: |
            Library-WebGL-
            Library-

      - name: Build WebGL
        uses: game-ci/unity-builder@v4
        env:
          UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
          UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
          UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
        with:
          unityVersion: 2022.3.22f1
          targetPlatform: WebGL
          customParameters: -logFile -
          
      - name: Upload WebGL build artifact
        uses: actions/upload-artifact@v4
        with:
          name: WebGL-Build
          path: build
          
      - name: Push to another repo
        run: |
          git config --global user.name "github-actions[bot]"
          git config --global user.email "github-actions[bot]@users.noreply.github.com"

          # clone target repo
          git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/Apptive-Game-Team/WordOnline_Play.git
          
          ls -R build
          
          cd WordOnline_Play

          # copy build result
          rm -rf ./Build
          rm -rf ./index.html
          cp -r ../build/WebGL/WebGL/* ./
          
          ls -R 

          git add .
          git commit -m "Update WebGL build from main repo"
          git push origin main