Skip to content

Commit

Permalink
Try to unify .NET SDK installation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hach-que committed Oct 31, 2024
1 parent a2500c5 commit 1c0f86b
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 406 deletions.
85 changes: 85 additions & 0 deletions .github/actions/dotnet-sdk/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Install .NET SDK
description: Install the .NET SDK
inputs:
UET_FRAMEWORK_TARGET:
description: "The target framework."
required: true
runs:
using: 'composite'
steps:
- name: Cache .NET SDK (Windows)
if: ${{ runner.os == 'Windows' }}
id: cache-sdk-win
uses: actions/cache@v4
with:
key: dotnet-sdk-windows-${{ inputs.UET_FRAMEWORK_TARGET }}
restore-keys: dotnet-sdk-windows-${{ inputs.UET_FRAMEWORK_TARGET }}
path: .dotnet-${{ inputs.UET_FRAMEWORK_TARGET }}
- name: Cache .NET SDK (macOS)
if: ${{ runner.os == 'macOS' }}
id: cache-sdk-mac
uses: actions/cache@v4
with:
key: dotnet-sdk-mac-${{ inputs.UET_FRAMEWORK_TARGET }}
restore-keys: dotnet-sdk-mac-${{ inputs.UET_FRAMEWORK_TARGET }}
path: .dotnet-${{ inputs.UET_FRAMEWORK_TARGET }}
- name: Download .NET SDK (Windows)
if: ${{ runner.os == 'Windows' && steps.cache-sdk-win.outputs.cache-hit != 'true' }}
shell: pwsh
env:
UET_FRAMEWORK_TARGET: ${{ inputs.UET_FRAMEWORK_TARGET }}
UET_DOTNET_WIN_DL: https://download.visualstudio.microsoft.com/download/pr/6902745c-34bd-4d66-8e84-d5b61a17dfb7/e61732b00f7e144e162d7e6914291f16/dotnet-sdk-8.0.101-win-x64.zip
run: |
if (!(Test-Path .dotnet-${env:UET_FRAMEWORK_TARGET}\dotnet\dotnet-extracted)) {
if (Test-Path ".dotnet-${env:UET_FRAMEWORK_TARGET}") {
Remove-Item -Recurse -Force ".dotnet-${env:UET_FRAMEWORK_TARGET}"
}
Write-Host "Setting up .NET SDK..."
New-Item -ItemType Directory ".dotnet-${env:UET_FRAMEWORK_TARGET}" | Out-Null
curl.exe -L -o ".dotnet-${env:UET_FRAMEWORK_TARGET}\dotnet.zip" "${env:UET_DOTNET_WIN_DL}"
if ($LastExitCode -ne 0) {
exit $LastExitCode
}
Expand-Archive -Path ".dotnet-${env:UET_FRAMEWORK_TARGET}\dotnet.zip" -DestinationPath ".dotnet-${env:UET_FRAMEWORK_TARGET}\dotnet" -Force | Out-Null
Set-Content -Path .dotnet-${env:UET_FRAMEWORK_TARGET}\dotnet\dotnet-extracted -Value "done"
}
- name: Download .NET SDK (macOS)
if: ${{ runner.os == 'macOS' && steps.cache-sdk-mac.outputs.cache-hit != 'true' }}
shell: pwsh
env:
UET_FRAMEWORK_TARGET: ${{ inputs.UET_FRAMEWORK_TARGET }}
UET_DOTNET_MAC_DL: https://download.visualstudio.microsoft.com/download/pr/ef083c06-7aee-4a4f-b18b-50c9a8990753/e206864e7910e81bbd9cb7e674ff1b4c/dotnet-sdk-8.0.101-osx-arm64.tar.gz
run: |
if (!(Test-Path .dotnet-${env:UET_FRAMEWORK_TARGET}/dotnet/dotnet-extracted)) {
if (Test-Path ".dotnet-${env:UET_FRAMEWORK_TARGET}") {
Remove-Item -Recurse -Force ".dotnet-${env:UET_FRAMEWORK_TARGET}"
}
Write-Host "Setting up .NET SDK..."
New-Item -ItemType Directory ".dotnet-${env:UET_FRAMEWORK_TARGET}" | Out-Null
curl -L -o ".dotnet-${env:UET_FRAMEWORK_TARGET}/dotnet.tar.gz" "${env:UET_DOTNET_MAC_DL}"
if ($LastExitCode -ne 0) {
exit $LastExitCode
}
New-Item -ItemType Directory ".dotnet-${env:UET_FRAMEWORK_TARGET}/dotnet" | Out-Null
Push-Location ".dotnet-${env:UET_FRAMEWORK_TARGET}/dotnet"
try {
tar -xvf "../dotnet.tar.gz"
} finally {
Pop-Location
}
Set-Content -Path .dotnet-${env:UET_FRAMEWORK_TARGET}/dotnet/dotnet-extracted -Value "done"
}
- name: Add .NET SDK to PATH (Windows)
if: ${{ runner.os == 'Windows' }}
shell: pwsh
env:
UET_FRAMEWORK_TARGET: ${{ inputs.UET_FRAMEWORK_TARGET }}
run: |
Add-Content -Path "${env:GITHUB_PATH}" -Value ".dotnet-${env:UET_FRAMEWORK_TARGET}\dotnet"
- name: Add .NET SDK to PATH (macOS)
if: ${{ runner.os == 'macOS' }}
shell: pwsh
env:
UET_FRAMEWORK_TARGET: ${{ inputs.UET_FRAMEWORK_TARGET }}
run: |
Add-Content -Path "${env:GITHUB_PATH}" -Value ".dotnet-${env:UET_FRAMEWORK_TARGET}/dotnet"
Loading

0 comments on commit 1c0f86b

Please sign in to comment.