name: build
on:
  - push
  - pull_request

jobs:
        
#  checklicense:
#    name: Check for UNITY_LICENSE in GitHub Secrets
#    runs-on: ubuntu-latest
#    outputs:
#      is_unity_license_set: ${{ steps.checklicense_job.outputs.is_unity_license_set }}
#    steps:
#      - name: Check whether unity activation requests should be done
#        id: checklicense_job
#        env:
#          UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
#          UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
#          UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
#        run: |
#          echo "Skip activation job: ${{ env.UNITY_LICENSE != '' }}"
#          export is_unity_license_set="${{ env.UNITY_LICENSE != '' }}"
#          echo "is_unity_license_set=$is_unity_license_set" >> $GITHUB_OUTPUT
          
  build:
    name: Build for ${{ matrix.targetPlatform }}
#    needs: checklicense
    runs-on: 
      - ubuntu-latest
    container:
      volumes:
        - /volume1/docker/gitea_actions/act:/volume1/docker/gitea_actions/act
        - /volume1/docker/gitea_actions/workspace:/volume1/docker/gitea_actions/workspace
    strategy:
      fail-fast: false
      matrix:
        targetPlatform:
#          - Android
          - WebGL
    steps:
      - name: Set Unity license
        run: |
          export is_unity_license_set=true
          echo "is_unity_license_set=$is_unity_license_set" >> $GITHUB_OUTPUT
      - name: Checkout repository
        uses: actions/checkout@v4.2.2
        with:
          lfs: true
      - name: Cache
        uses: actions/cache@v4.2.2
        with:
          path: Library
          key: Library-${{ matrix.targetPlatform }}
      - name: Build
        uses: https://git.chikalin.space/unity/unity-builder@f685e64b813aa72a6e0b45f4c0ac1a44e7cec87b
        env:
          UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
          UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
          UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
          ACTION_FOLDER: /volume1/docker/gitea_actions/act/2f7ed7e14b5204eb0b805d660c8b513dafe695ebe4f34553a617791ad465d82a/dist
        with:
          targetPlatform: ${{ matrix.targetPlatform }}
          dockerCpuLimit: 0
          RUNNER_TEMP: /volume1/docker/gitea_actions/act/temp
          dockerWorkspacePath: /volume1/docker/gitea_actions/workspace/unity/textdecalURP # this is from volume
          buildProfile: 'Assets/Settings/Build Profiles/${{ matrix.targetPlatform }}-profile.asset'
      - name: Upload artifact
        uses: actions/upload-artifact@v3
        with:
          name: Build-${{ matrix.targetPlatform }}
          path: build