|
| 1 | +$ErrorActionPreference = "Stop" |
| 2 | +Set-StrictMode -Version Latest |
| 3 | + |
| 4 | +$RunnerTemp = if ([string]::IsNullOrWhiteSpace($env:RUNNER_TEMP)) { |
| 5 | + [System.IO.Path]::GetTempPath() |
| 6 | +} else { |
| 7 | + $env:RUNNER_TEMP |
| 8 | +} |
| 9 | + |
| 10 | +function Add-ActionPath { |
| 11 | + param([Parameter(Mandatory = $true)][string] $Path) |
| 12 | + |
| 13 | + $env:Path = "$Path;$env:Path" |
| 14 | + if (-not [string]::IsNullOrWhiteSpace($env:GITHUB_PATH)) { |
| 15 | + Add-Content -LiteralPath $env:GITHUB_PATH -Value $Path |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +if (-not (Get-Command aws -ErrorAction SilentlyContinue)) { |
| 20 | + $installer = Join-Path $RunnerTemp "AWSCLIV2.msi" |
| 21 | + Invoke-WebRequest -Uri "https://awscli.amazonaws.com/AWSCLIV2.msi" -OutFile $installer |
| 22 | + $install = Start-Process msiexec.exe -Wait -PassThru -ArgumentList "/i `"$installer`" /qn" |
| 23 | + if ($install.ExitCode -ne 0) { |
| 24 | + throw "AWS CLI installer failed with exit code $($install.ExitCode)." |
| 25 | + } |
| 26 | + |
| 27 | + $awsCliDir = Join-Path $env:ProgramFiles "Amazon/AWSCLIV2" |
| 28 | + $machinePath = [System.Environment]::GetEnvironmentVariable("Path", "Machine") |
| 29 | + $userPath = [System.Environment]::GetEnvironmentVariable("Path", "User") |
| 30 | + $env:Path = "$awsCliDir;$machinePath;$userPath;$env:Path" |
| 31 | + if (-not [string]::IsNullOrWhiteSpace($env:GITHUB_PATH)) { |
| 32 | + Add-Content -LiteralPath $env:GITHUB_PATH -Value $awsCliDir |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +if (-not (Get-Command coscli -ErrorAction SilentlyContinue)) { |
| 37 | + $coscliDir = Join-Path $RunnerTemp "coscli" |
| 38 | + New-Item -ItemType Directory -Force -Path $coscliDir | Out-Null |
| 39 | + Invoke-WebRequest -Uri "https://github.com/tencentyun/coscli/releases/download/v1.0.8/coscli-v1.0.8-windows-amd64.exe" -OutFile (Join-Path $coscliDir "coscli.exe") |
| 40 | + Add-ActionPath $coscliDir |
| 41 | +} |
| 42 | + |
| 43 | +if (-not (Get-Command tccli -ErrorAction SilentlyContinue)) { |
| 44 | + python -m pip install --user tccli |
| 45 | + if ($LASTEXITCODE -ne 0) { |
| 46 | + throw "tccli install failed with exit code $LASTEXITCODE." |
| 47 | + } |
| 48 | + |
| 49 | + $pythonUserScripts = Join-Path (python -m site --user-base) "Scripts" |
| 50 | + Add-ActionPath $pythonUserScripts |
| 51 | +} |
0 commit comments