|
| 1 | +function Get-VsCacheInfo { |
| 2 | + <# |
| 3 | + .SYNOPSIS |
| 4 | + Check if VS components need to be installed and set GitHub Actions outputs for caching. |
| 5 | + .PARAMETER PhpVersion |
| 6 | + PHP Version |
| 7 | + #> |
| 8 | + [OutputType()] |
| 9 | + param ( |
| 10 | + [Parameter(Mandatory = $true, Position=0, HelpMessage='PHP Version')] |
| 11 | + [ValidateNotNull()] |
| 12 | + [ValidateLength(1, [int]::MaxValue)] |
| 13 | + [string] $PhpVersion |
| 14 | + ) |
| 15 | + begin { |
| 16 | + $jsonPath = [System.IO.Path]::Combine($PSScriptRoot, '..\config\vs.json') |
| 17 | + } |
| 18 | + process { |
| 19 | + $VsConfig = Get-Content -Path $jsonPath -Raw | ConvertFrom-Json |
| 20 | + $majorMinor = if ($PhpVersion -eq 'master') { 'master' } else { $PhpVersion.Substring(0, 3) } |
| 21 | + $VsVersion = $VsConfig.php.$majorMinor |
| 22 | + $cacheRoot = if ([string]::IsNullOrWhiteSpace($env:RUNNER_TEMP)) { [System.IO.Path]::GetTempPath() } else { $env:RUNNER_TEMP } |
| 23 | + $cachePath = [System.IO.Path]::Combine($cacheRoot, 'vs-components', $VsVersion) |
| 24 | + $vsInstallPath = '' |
| 25 | + $needsInstall = $true |
| 26 | + $vsInstallPath = Get-VsInstallPath |
| 27 | + if (-not [string]::IsNullOrWhiteSpace($vsInstallPath)) { |
| 28 | + try { |
| 29 | + Get-VsVersionHelper -VsVersion $VsVersion -VsConfig $VsConfig | Out-Null |
| 30 | + $needsInstall = $false |
| 31 | + } catch { |
| 32 | + } |
| 33 | + } |
| 34 | + $components = $VsConfig.vs.$VsVersion.components -join ',' |
| 35 | + $bytes = [System.Text.Encoding]::UTF8.GetBytes($components) |
| 36 | + $hash = [System.Security.Cryptography.SHA256]::Create().ComputeHash($bytes) |
| 37 | + $componentHash = ([System.BitConverter]::ToString($hash).Replace('-', '').Substring(0, 16)).ToLower() |
| 38 | + $cachePath = Join-Path $cachePath $componentHash |
| 39 | + "needs-vs-install=$($needsInstall.ToString().ToLower())" >> $env:GITHUB_OUTPUT |
| 40 | + "vs-version=$VsVersion" >> $env:GITHUB_OUTPUT |
| 41 | + "vs-install-path=$vsInstallPath" >> $env:GITHUB_OUTPUT |
| 42 | + "vs-cache-path=$cachePath" >> $env:GITHUB_OUTPUT |
| 43 | + "vs-cache-key-prefix=vs-components-$VsVersion-$env:RUNNER_OS-$componentHash" >> $env:GITHUB_OUTPUT |
| 44 | + } |
| 45 | + end { |
| 46 | + } |
| 47 | +} |
0 commit comments