Dinomite-Studios / unity-azure-pipelines-tasks

Azure DevOps extension adding tools to build and deploy Unity 3D projects using Azure Pipelines
https://unitydevops.com/
MIT License
121 stars 49 forks source link

Feature Request: Download Unity version if not installed/found #178

Open SimonDarksideJ opened 3 years ago

SimonDarksideJ commented 3 years ago

Given the frequency of Unity builds appearing sometimes, it takes a lot of time to keep the build server up to date ahead of development.

It would be great to have an additional build task to automatically download and install the required Unity version as noted in the ProjectSettings.txt

eirikwah commented 2 years ago

I know this is not directly what you ask for, but this is a way we use to automatically install Unity, as an Azure DevOps template. With good help from https://github.com/sttz/install-unity :

parameters:
- name: unityComponents
- name: unityProjectRoot
  default: './'

steps:
- task: DinomiteStudios.64e90d50-a9c0-11e8-a356-d3eab7857116.custom-unity-get-project-version-task.UnityGetProjectVersionTask@1
  displayName: 'Unity Get Project Version'
  name: UnityGetProjectVersionTask
  inputs:
    unityProjectPath: '${{parameters.unityProjectRoot}}'

- task: PowerShell@2
  displayName: 'Download and install unity'
  inputs:
    targetType: inline
    script: |
      $unityFolder = ""
      $unityPath = ""
      if ($IsMacOS) {
        $Uri = "https://github.com/sttz/install-unity/releases/download/2.3.0/install-unity-2.3.0.zip"
        $unityExecutable = "/Unity.app/Contents/MacOS/Unity"
        Invoke-WebRequest -Uri $Uri -OutFile "install-unity.zip"
        Expand-Archive "install-unity.zip" -DestinationPath .
        chmod +x install-unity
        sudo ./install-unity install $(UnityGetProjectVersionTask.projectVersion) --packages '${{parameters.unityComponents}}' --opt progressBar=false
        if ($LASTEXITCODE -ne 0) { throw "Could not install unity" }

        # We used a common approach to get Unity installed on Windows and MacOS, but something broke with time in DevOps PowerShell, so we need a workaround
        $unityPath = Get-ChildItem -Path "/Applications/" -Filter Unity* | Select -Expand FullName

        $unityFolder = "$unityPath/Unity.app"
      } else {
        $Uri = "https://github.com/minorai/install-unity/releases/download/2.7.2-win2/install-unity.zip"
        $unityExecutable = "\Editor\Unity.exe"
        Invoke-WebRequest -Uri $Uri -OutFile "install-unity.zip"
        Expand-Archive "install-unity.zip" -DestinationPath .
        ./install-unity install $(UnityGetProjectVersionTask.projectVersion) --packages '${{parameters.unityComponents}}' --opt progressBar=false
        if ($LASTEXITCODE -ne 0) { throw "Could not install unity" }

        # install-unity list -i - returns installed Unities in the following format:
        # Unity version <---TAB---> Unity path
        $unityInstall = & .\install-unity list -i | Out-String
        $unityPath = $unityInstall.SubString($unityInstall.IndexOf("`t")).Trim()

        $unityFolder = "$unityPath"
      }
      $unityPath += $unityExecutable
      echo "Unity installation folder: $unityFolder"
      echo "Unity executable: $unityPath"
      echo "##vso[task.setvariable variable=UnityFolder]$unityFolder"
      echo "##vso[task.setvariable variable=UnityPath]$unityPath"
    errorActionPreference: stop