name: Actions
on:
  pull_request: {}
  push: { branches: [master] }
env:
  CODECOV_TOKEN: '2f2eb890-30e2-4724-83eb-7633832cf0de'
  GKE_ZONE: 'us-central1-c'
  GKE_REGION: 'us-central1'
  GKE_PROJECT: 'unitykubernetesbuilder'
  GKE_CLUSTER: 'unity-builder-cluster'
jobs:
  tests:
    name: Tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12.x
      - run: yarn
      - run: yarn lint
      - run: yarn test --coverage
      - run: bash <(curl -s https://codecov.io/bash)
      - run: yarn build || { echo "build command should always succeed" ; exit 61; }
      # - run: yarn build --quiet && git diff --quiet action || { echo "action should be auto generated" ; git diff action ; exit 62; }
  buildForAllPlatforms:
    name: Build for ${{ matrix.targetPlatform }} on version ${{ matrix.unityVersion }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        projectPath:
          - test-project
        unityVersion:
          - 2019.2.11f1
          - 2019.3.15f1
        include:
          # Please be polite; don't copy my personal licenses.
          # These are here because they are needed to allowing pull requests from forks to unity-builder.
          # You should be using ${{ secrets.UNITY_LICENSE_2019_3_15 }} here.
          - unityVersion: 2019.2.11f1
            license: "\n    \n        \n            \n            \n        \n        \n        \n        \n            \n            \n            \n            \n            \n            \n            \n            \n            \n            \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n            \n        \n    \nJHdOBFmBNq2H8BrGFzir/StLoYo=aENLHd37a51RtP2/g7YU0Pexf5mx0/ENXYGtrPzqwZ8NQt2AsSdxGnl0CUB45/GuNXfJVDt2HWot\ncNYZB2OylVBn1WHQbKZlPmm8gEAMz0MYbr4Isb5i5buryBrZlmbEOjnRI+pEg1CBwlgMo6xdtjjE\n/d7cC293QIUO91kdzRXftYou1dNaUyuPL9ZH65vdB2pDXGRNxgUVD+GnnqZA7b5L2HXqNQclcWAK\n5Yd1BeF3VzR1iLw9G/SmH5oOhnpXSmqbL4qk7LVP2/mgXpFk5kP4X8VC3z47obNhBIGq40dwWyEe\nUYk5/nRAOkZawDT+tcu96e06gPC9Cxk5PdbRbA=="
          - unityVersion: 2019.3.15f1
            license: "\n    \n        \n            \n            \n        \n        \n        \n        \n            \n            \n            \n            \n            \n            \n            \n            \n            \n            \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n            \n        \n    \nbpzWx3PZ0lqWDo1m9aLQuZ4cweo=QcDm4/qAXZuUMQbUVk63vO6u66Bp8PnqqWQcZZOcym/rGUZLj1sr66EquF3X3w1L7aqiwMGtbY2b\nkPttcalFeaBkc5NsJMrexWjuBCxQvhbmVFQnTjvC6vNS+k1wrkz7If1oPkz/XaDtCfUs8oxc9iPe\nPzzUJIVYLZoDtpPq2XbgVn9/TiVb3Zu6ldKgvtNRYUjrB3KywtvL9OcIFll3htRcBZPG43kxryJc\nDD2TL5Nw1JuX6MejBBuYTZsZNpGX9Pjop9+uFUZ4GI9h8a5g6wJUfXzsGw7j4gkvDkC9MvyWiksi\n2hNXw1QNeB6JfQsd4sAuhYh/CqTm2gCz9i9ZpA=="
        targetPlatform:
          - StandaloneOSX # Build a macOS standalone (Intel 64-bit).
          - StandaloneWindows64 # Build a Windows 64-bit standalone.
          - StandaloneLinux64 # Build a Linux 64-bit standalone.
          - iOS # Build an iOS player.
          # - Android # Build an Android .apk.
          #          - StandaloneWindows # Build a Windows standalone.
          #          - WebGL # WebGL.
          #          - WSAPlayer # Build an Windows Store Apps player.
          #          - PS4 # Build a PS4 Standalone.
          #          - XboxOne # Build a Xbox One Standalone.
          #          - tvOS # Build to Apple's tvOS platform.
          #          - Switch # Build a Nintendo Switch player
    steps:
      - uses: actions/checkout@v2
        with:
          lfs: true
      - uses: actions/cache@v1.1.0
        with:
          path: ${{ matrix.projectPath }}/Library
          key: Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}
          restore-keys: |
            Library-${{ matrix.projectPath }}-
            Library-
      - uses: ./
        env:
          UNITY_LICENSE: ${{ matrix.license }}
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: -profile SomeProfile -someBoolean -someValue exampleValue
      - uses: actions/upload-artifact@v1
        with:
          name: Build (${{ matrix.unityVersion }})
          path: build
  k8sBuilds:
    name: K8s build for ${{ matrix.targetPlatform }} on version ${{ matrix.unityVersion }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        targetPlatform:
          - StandaloneLinux64
          - StandaloneWindows64
    steps:
      - uses: actions/checkout@v2
        with:
          lfs: true
      - uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
        with:
          version: '288.0.0'
          service_account_email: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_EMAIL }}
          service_account_key: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_KEY }}
      - name: Get Gist
        id: get-apply
        uses: andymckay/get-gist-action@master
        with:
          gistURL: 'https://gist.github.com/frostebite/58fdeb02d45f6e7a24bcbe36f6bdc051'
      - run: chmod +x ${{ steps.get-apply.outputs.file }}
      - run: ${{ steps.get-apply.outputs.file }} ${{ env.GKE_PROJECT }} ${{ env.GKE_CLUSTER }} ${{ env.GKE_ZONE }}
      - uses: frostebite/File-To-Base64@master
        id: read-base64
        with:
          filePath: ~/.kube/config
      - uses: ./
        id: k8s-unity-build
        env:
          UNITY_LICENSE: "\n    \n        \n            \n            \n        \n        \n        \n        \n            \n            \n            \n            \n            \n            \n            \n            \n            \n            \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n            \n        \n    \nbpzWx3PZ0lqWDo1m9aLQuZ4cweo=QcDm4/qAXZuUMQbUVk63vO6u66Bp8PnqqWQcZZOcym/rGUZLj1sr66EquF3X3w1L7aqiwMGtbY2b\nkPttcalFeaBkc5NsJMrexWjuBCxQvhbmVFQnTjvC6vNS+k1wrkz7If1oPkz/XaDtCfUs8oxc9iPe\nPzzUJIVYLZoDtpPq2XbgVn9/TiVb3Zu6ldKgvtNRYUjrB3KywtvL9OcIFll3htRcBZPG43kxryJc\nDD2TL5Nw1JuX6MejBBuYTZsZNpGX9Pjop9+uFUZ4GI9h8a5g6wJUfXzsGw7j4gkvDkC9MvyWiksi\n2hNXw1QNeB6JfQsd4sAuhYh/CqTm2gCz9i9ZpA=="
        with:
          targetPlatform: ${{ matrix.targetPlatform }}
          kubeConfig: ${{ steps.read-base64.outputs.base64 }}
          githubToken: ${{ secrets.GITHUB_TOKEN }}
          projectPath: test-project
          unityVersion: 2019.3.15f1
      - uses: frostebite/K8s-Download-Volume@master
        with:
          kubeConfig: ${{ steps.read-base64.outputs.base64 }}
          volume: ${{ steps.k8s-unity-build.outputs.volume }}
          sourcePath: repo/build/
      - uses: actions/upload-artifact@v1
        with:
          name: Kubernetes Build (${{ matrix.targetPlatform }})
          path: k8s-volume-download
      - name: Get Gist
        id: get-shutdown
        uses: andymckay/get-gist-action@master
        with:
          gistURL: 'https://gist.github.com/frostebite/5964fdd4d1c84507673ddef035d344ca'
        if: ${{ always() }}
      - run: |
          chmod +x ${{ steps.get-shutdown.outputs.file }}
          ${{ steps.get-shutdown.outputs.file }} ${{ env.GKE_PROJECT }} ${{ env.GKE_CLUSTER }} ${{ env.GKE_ZONE }}
        if: ${{ always() }}