Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SimonDarksideJ opened this issue May 17, 2021 · 1 comment
Open

Comments

@SimonDarksideJ
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants