Create USD Release v2505 #32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Workflow to build USD versions required to run the usd plugins | |
| # This assumes there is a Release created called USD Artifacts | |
| name: Create USD Release | |
| run-name: Create USD Release v${{ github.event.inputs.usd_version }} | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| usd_version: | |
| description: "USD Version to build" | |
| required: true | |
| default: "2411" | |
| jobs: | |
| prepare-matrix: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - id: set-matrix | |
| run: | | |
| OS_LIST="[\"windows-2022\",\"macOS-13\"" | |
| if [[ "${{ github.event.inputs.usd_version }}" -gt 2400 ]]; then | |
| OS_LIST="$OS_LIST,\"macOS-14\"" | |
| fi | |
| OS_LIST="$OS_LIST,\"ubuntu-22.04\"]" | |
| echo "matrix=$OS_LIST" >> $GITHUB_OUTPUT | |
| build: | |
| needs: [prepare-matrix] | |
| name: Create USD Release ${{ matrix.os }} ${{ github.event.inputs.usd_version }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: ${{ fromJson(needs.prepare-matrix.outputs.matrix) }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Check if artifact exists in 'USD-${{ github.event.inputs.usd_version }}-Artifacts' Release | |
| id: check_artifact | |
| shell: pwsh | |
| run: | | |
| $usd_version = "${{ github.event.inputs.usd_version }}" | |
| $usdFormattedVersion = "$($usd_version.Substring(0,2)).$($usd_version.Substring(2))" | |
| "USD_FORMATTED_VERSION=$usdFormattedVersion" | Out-File -FilePath $env:GITHUB_ENV -Append | |
| $releaseName = "USD-${usd_version}-Artifacts" | |
| $ASSET_NAME = "usd-${usd_version}-${{ matrix.os }}.zip" | |
| $releaseExists = $false | |
| $stderr = $null | |
| $releaseView = gh release view $releaseName 2>&1 | Tee-Object -Variable stderr | |
| if ($stderr -match "release not found") { | |
| $releaseExists = $false | |
| "exists=false" | Out-File -FilePath $env:GITHUB_ENV -Append | |
| Write-Output "Release not found: $releaseName -- Creating new one" | |
| gh release create "$releaseName" --title "$releaseName" --notes "USD built with the following parameters: --build-shared --openimageio --tools --python --debug-python --usd-imaging --build-variant release --use-cxx11-abi=0 (linux)" | |
| } else { | |
| $releaseExists = $true | |
| } | |
| Write-Output "Release View result: $releaseName, Exists: $releaseExists" | |
| if ($releaseExists) { | |
| $assets = gh release view $releaseName --repo ${{ github.repository }} --json assets -q '.assets[].name' | |
| if ($assets -like "*$ASSET_NAME*") { | |
| Write-Output "Asset $ASSET_NAME exists in the $releaseName Release." | |
| "exists=true" | Out-File -FilePath $env:GITHUB_ENV -Append | |
| } else { | |
| Write-Output "Asset $ASSET_NAME does not exist in the $releaseName Release." | |
| "exists=false" | Out-File -FilePath $env:GITHUB_ENV -Append | |
| } | |
| } | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Python | |
| if: env.exists == 'false' | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.10.11" | |
| id: setup-python | |
| - name: Install Ninja (Unix) | |
| if: env.exists == 'false' && matrix.os != 'windows-2022' | |
| run: | | |
| python -m pip install ninja | |
| - name: Install Additional Dependencies (macOS-13) | |
| if: env.exists == 'false' && matrix.os == 'macOS-13' | |
| run: | | |
| sudo xcode-select -s /Applications/Xcode_14.1.app | |
| brew uninstall --ignore-dependencies openexr imath | |
| brew cleanup | |
| brew install glew | |
| - name: Install Additional Dependencies (macOS-14) | |
| if: env.exists == 'false' && matrix.os == 'macOS-14' | |
| run: | | |
| brew uninstall --ignore-dependencies giflib | |
| brew cleanup | |
| - name: Install Additional Dependencies (Ubuntu) | |
| if: env.exists == 'false' && matrix.os == 'ubuntu-22.04' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y build-essential libgl1-mesa-dev libglew-dev libxi-dev libxrandr-dev | |
| - name: Install Additional Dependencies (Windows) | |
| if: env.exists == 'false' && matrix.os == 'windows-2022' | |
| run: | | |
| choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' | |
| - name: Clone USD | |
| if: env.exists == 'false' | |
| run: git clone --branch v${{ env.USD_FORMATTED_VERSION }} --depth 1 https://github.com/PixarAnimationStudios/OpenUSD.git | |
| - name: Install Python Dependencies | |
| if: env.exists == 'false' | |
| shell: pwsh | |
| run: | | |
| python -m pip install PySide6 | |
| python -m pip install pyopengl | |
| if ("${{runner.os}}" -eq "Windows") { | |
| python -m pip install jinja2 | |
| } | |
| # New Step: Patch build_usd.py to override IsVisualStudioVersionOrGreater | |
| - name: Patch build_usd.py to Always Return True on Windows | |
| if: env.exists == 'false' && matrix.os == 'windows-2022' | |
| shell: pwsh | |
| run: | | |
| # Define the path to build_usd.py | |
| $buildUsdPath = "OpenUSD/build_scripts/build_usd.py" | |
| # Verify that build_usd.py exists | |
| if (-Not (Test-Path $buildUsdPath)) { | |
| Write-Error "build_usd.py not found at path: $buildUsdPath" | |
| exit 1 | |
| } | |
| # Read the entire content of build_usd.py | |
| $content = Get-Content -Path $buildUsdPath -Raw | |
| # Define the new function as a here-string | |
| $newFunction = @" | |
| def IsVisualStudioVersionOrGreater(desiredVersion): | |
| if not Windows(): | |
| return False | |
| return True | |
| "@ | |
| # Define a regex pattern to match the existing function | |
| $pattern = '(?s)def\s+IsVisualStudioVersionOrGreater\(desiredVersion\):.*?return False' | |
| # Perform the replacement and write the updated content back to build_usd.py | |
| $updatedContent = $content -replace $pattern, $newFunction | |
| Set-Content -Path $buildUsdPath -Value $updatedContent | |
| Write-Output "Successfully patched IsVisualStudioVersionOrGreater in build_usd.py" | |
| - name: Build USD | |
| if: env.exists == 'false' | |
| shell: pwsh | |
| run: | | |
| $file = "OpenUSD/build_scripts/build_usd.py" | |
| $env:CMAKE_PREFIX_PATH = "/usr/local;$env:CMAKE_PREFIX_PATH" | |
| $env:DYLD_LIBRARY_PATH = "/usr/local/lib;$env:DYLD_LIBRARY_PATH" | |
| $env:LD_LIBRARY_PATH = "/usr/local/lib;$env:LD_LIBRARY_PATH" | |
| $abi_arg = "" | |
| $generator = "--generator Ninja" | |
| if ("${{runner.os}}" -eq "Windows") { | |
| $generator = '--generator "Visual Studio 17 2022"' | |
| $fileContent = Get-Content $file -Raw | |
| $fileContent = $fileContent -replace ' -- \{multiproc\}', '' | |
| Set-Content $file -Value $fileContent | |
| } | |
| if ("${{runner.os}}" -eq "Linux") { | |
| $abi_arg = "--use-cxx11-abi 0" | |
| } | |
| $python_cmd = "python $file `${{ github.workspace }}/usd_build` --build-shared --openimageio --tools --python --debug-python --usd-imaging --build-variant release $abi_arg $generator" | |
| Invoke-Expression $python_cmd | |
| - name: Remove Specific Folders Unix | |
| if: env.exists == 'false' && matrix.os != 'windows-2022' | |
| run: | | |
| rm -rf ${{ github.workspace }}/usd_build/build | |
| rm -rf ${{ github.workspace }}/usd_build/share | |
| rm -rf ${{ github.workspace }}/usd_build/src | |
| - name: Remove Specific Folders Windows | |
| if: env.exists == 'false' && matrix.os == 'windows-2022' | |
| run: | | |
| powershell -Command "& { | |
| Remove-Item -Path ${{ github.workspace }}\usd_build\build -Recurse -Force | |
| Remove-Item -Path ${{ github.workspace }}\usd_build\share -Recurse -Force | |
| Remove-Item -Path ${{ github.workspace }}\usd_build\src -Recurse -Force | |
| }" | |
| - name: Set USD Paths to Environment variable to USD_BUILD_PATH | |
| if: env.exists == 'false' | |
| shell: pwsh | |
| run: | | |
| if ($env:RUNNER_OS -eq 'macOS') { | |
| $localPath = "/Users/runner/work/USD-Fileformat-plugins/USD-Fileformat-plugins/usd_build" | |
| } elseif ($env:RUNNER_OS -eq 'Linux') { | |
| $localPath = "/home/runner/work/USD-Fileformat-plugins/USD-Fileformat-plugins/usd_build" | |
| } elseif ($env:RUNNER_OS -eq 'Windows') { | |
| $localPath = "D:/a/USD-Fileformat-plugins/USD-Fileformat-plugins/usd_build" | |
| } | |
| $files = @( | |
| "${{ github.workspace }}/usd_build/cmake/pxrTargets.cmake", | |
| "${{ github.workspace }}/usd_build/lib/cmake/OpenImageIO/OpenImageIOConfig.cmake", | |
| "${{ github.workspace }}/usd_build/lib/cmake/OpenImageIO/OpenImageIOTargets.cmake" | |
| ) | |
| $replacementPath = '${USD_BUILD_PATH}' | |
| foreach ($file in $files) { | |
| (Get-Content $file) -replace [regex]::Escape($localPath), $replacementPath | Set-Content $file | |
| $content = 'set(USD_BUILD_PATH "$ENV{USD_BUILD_PATH}")' + "`r`n" + (Get-Content $file -Raw) | |
| $content | Set-Content $file | |
| } | |
| - name: Package Build Artifacts Unix | |
| if: env.exists == 'false' && matrix.os != 'windows-2022' | |
| run: | | |
| cd ${{ github.workspace }}/usd_build | |
| zip -r ../usd-${{ github.event.inputs.usd_version }}-${{ matrix.os }}.zip * | |
| - name: Package Build Artifacts Windows | |
| if: env.exists == 'false' && matrix.os == 'windows-2022' | |
| run: | | |
| powershell -Command "& { | |
| Set-Location ${{ github.workspace }}\usd_build | |
| Compress-Archive -Path * -DestinationPath ..\usd-${{ github.event.inputs.usd_version }}-${{ matrix.os }}.zip | |
| }" | |
| - name: Upload Artifact to USD-${{ github.event.inputs.usd_version }}-Artifacts Release | |
| if: env.exists == 'false' | |
| shell: pwsh | |
| run: | | |
| $ARTIFACT_PATH = "${{ github.workspace }}/usd-${{ github.event.inputs.usd_version }}-${{ matrix.os }}.zip" | |
| if (-Not (Test-Path $ARTIFACT_PATH)) { | |
| Write-Output "$ARTIFACT_PATH does not exist." | |
| } | |
| else { | |
| Write-Output "File $ARTIFACT_PATH exists." | |
| Write-Output "Size of the artifact file:" | |
| Get-Item $ARTIFACT_PATH | Select-Object Name, Length | |
| } | |
| Write-Output "Uploading $ARTIFACT_PATH to USD-${{github.event.inputs.usd_version}}-Artifacts release..." | |
| gh release upload USD-${{ github.event.inputs.usd_version }}-Artifacts $ARTIFACT_PATH --repo ${{ github.repository }} --clobber | |
| Write-Output "Upload successful." | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |