|
| 1 | +param( |
| 2 | + [string]$AdvinstVersion = "", |
| 3 | + [string]$AdvinstLicense = "", |
| 4 | + [ValidateSet("true", "false")] |
| 5 | + [string]$AdvinstEnableAutomation = "false", |
| 6 | + [string]$AipPath = "", |
| 7 | + [string]$AipBuildName = "", |
| 8 | + [string]$AipPackageName = "", |
| 9 | + [string]$AipOutputDir = "", |
| 10 | + [string]$AipCommands = "", |
| 11 | + [switch]$SkipPre, |
| 12 | + [switch]$SkipMain, |
| 13 | + [switch]$SkipPost |
| 14 | +) |
| 15 | + |
| 16 | +Set-StrictMode -Version Latest |
| 17 | +$ErrorActionPreference = "Stop" |
| 18 | + |
| 19 | +function Set-ActionInput { |
| 20 | + param( |
| 21 | + [Parameter(Mandatory = $true)] |
| 22 | + [string]$Name, |
| 23 | + [Parameter(Mandatory = $true)] |
| 24 | + [AllowEmptyString()] |
| 25 | + [string]$Value |
| 26 | + ) |
| 27 | + |
| 28 | + $envName = "INPUT_" + ($Name.ToUpperInvariant() -replace " ", "_") |
| 29 | + [System.Environment]::SetEnvironmentVariable($envName, $Value) |
| 30 | +} |
| 31 | + |
| 32 | +function Invoke-NodeScript { |
| 33 | + param( |
| 34 | + [Parameter(Mandatory = $true)] |
| 35 | + [string]$Path, |
| 36 | + [Parameter(Mandatory = $true)] |
| 37 | + [string]$Label |
| 38 | + ) |
| 39 | + |
| 40 | + Write-Host ("==> Running {0}: {1}" -f $Label, $Path) |
| 41 | + & node $Path |
| 42 | + if ($LASTEXITCODE -ne 0) { |
| 43 | + throw "{0} failed with exit code {1}" -f $Label, $LASTEXITCODE |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +$repoRoot = Split-Path -Parent $PSScriptRoot |
| 48 | +Set-Location $repoRoot |
| 49 | + |
| 50 | +$preScript = Join-Path $repoRoot "dist\pre\index.js" |
| 51 | +$mainScript = Join-Path $repoRoot "dist\main\index.js" |
| 52 | +$postScript = Join-Path $repoRoot "dist\post\index.js" |
| 53 | + |
| 54 | +if (-not (Get-Command node -ErrorAction SilentlyContinue)) { |
| 55 | + throw "Node.js was not found in PATH." |
| 56 | +} |
| 57 | + |
| 58 | +foreach ($scriptPath in @($preScript, $mainScript, $postScript)) { |
| 59 | + if (-not (Test-Path $scriptPath)) { |
| 60 | + throw "Missing built action file: $scriptPath. Run 'npm run dist' first." |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +$runnerDir = Join-Path $repoRoot ".tmp\local-action-runner" |
| 65 | +$toolCacheDir = Join-Path $repoRoot ".tmp\tool-cache" |
| 66 | +New-Item -ItemType Directory -Force -Path $runnerDir | Out-Null |
| 67 | +New-Item -ItemType Directory -Force -Path $toolCacheDir | Out-Null |
| 68 | + |
| 69 | +$githubEnvFile = Join-Path $runnerDir "env.txt" |
| 70 | +$githubPathFile = Join-Path $runnerDir "path.txt" |
| 71 | +$githubOutputFile = Join-Path $runnerDir "output.txt" |
| 72 | +$githubStateFile = Join-Path $runnerDir "state.txt" |
| 73 | + |
| 74 | +foreach ($f in @($githubEnvFile, $githubPathFile, $githubOutputFile, $githubStateFile)) { |
| 75 | + if (-not (Test-Path $f)) { |
| 76 | + New-Item -ItemType File -Path $f | Out-Null |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +[System.Environment]::SetEnvironmentVariable("GITHUB_ACTIONS", "true") |
| 81 | +[System.Environment]::SetEnvironmentVariable("RUNNER_TEMP", $runnerDir) |
| 82 | +[System.Environment]::SetEnvironmentVariable("RUNNER_TOOL_CACHE", $toolCacheDir) |
| 83 | +[System.Environment]::SetEnvironmentVariable("GITHUB_WORKSPACE", $repoRoot) |
| 84 | +[System.Environment]::SetEnvironmentVariable("GITHUB_ENV", $githubEnvFile) |
| 85 | +[System.Environment]::SetEnvironmentVariable("GITHUB_PATH", $githubPathFile) |
| 86 | +[System.Environment]::SetEnvironmentVariable("GITHUB_OUTPUT", $githubOutputFile) |
| 87 | +[System.Environment]::SetEnvironmentVariable("GITHUB_STATE", $githubStateFile) |
| 88 | +[System.Environment]::SetEnvironmentVariable("RUNNER_DEBUG", "1") |
| 89 | +[System.Environment]::SetEnvironmentVariable("ADVANCEDINSTALLER_INI_URL", "https://dev.advancedinstaller.com/downloads/updates.ini") |
| 90 | + |
| 91 | +Set-ActionInput -Name "advinst-version" -Value $AdvinstVersion |
| 92 | +Set-ActionInput -Name "advinst-license" -Value $AdvinstLicense |
| 93 | +Set-ActionInput -Name "advinst-enable-automation" -Value $AdvinstEnableAutomation |
| 94 | +Set-ActionInput -Name "aip-path" -Value $AipPath |
| 95 | +Set-ActionInput -Name "aip-build-name" -Value $AipBuildName |
| 96 | +Set-ActionInput -Name "aip-package-name" -Value $AipPackageName |
| 97 | +Set-ActionInput -Name "aip-output-dir" -Value $AipOutputDir |
| 98 | +Set-ActionInput -Name "aip-commands" -Value $AipCommands |
| 99 | + |
| 100 | +$mainFailed = $false |
| 101 | + |
| 102 | +try { |
| 103 | + if (-not $SkipPre) { |
| 104 | + Invoke-NodeScript -Path $preScript -Label "pre" |
| 105 | + } else { |
| 106 | + Write-Host "==> Skipping pre" |
| 107 | + } |
| 108 | + |
| 109 | + if (-not $SkipMain) { |
| 110 | + Invoke-NodeScript -Path $mainScript -Label "main" |
| 111 | + } else { |
| 112 | + Write-Host "==> Skipping main" |
| 113 | + } |
| 114 | +} catch { |
| 115 | + $mainFailed = $true |
| 116 | + Write-Error $_ |
| 117 | +} finally { |
| 118 | + if (-not $SkipPost) { |
| 119 | + try { |
| 120 | + Invoke-NodeScript -Path $postScript -Label "post" |
| 121 | + } catch { |
| 122 | + Write-Error $_ |
| 123 | + if (-not $mainFailed) { |
| 124 | + throw |
| 125 | + } |
| 126 | + } |
| 127 | + } else { |
| 128 | + Write-Host "==> Skipping post" |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +Write-Host "" |
| 133 | +Write-Host "Runner files:" |
| 134 | +Write-Host (" RUNNER_TOOL_CACHE: {0}" -f $toolCacheDir) |
| 135 | +Write-Host (" GITHUB_ENV: {0}" -f $githubEnvFile) |
| 136 | +Write-Host (" GITHUB_PATH: {0}" -f $githubPathFile) |
| 137 | +Write-Host (" GITHUB_OUTPUT: {0}" -f $githubOutputFile) |
| 138 | +Write-Host (" GITHUB_STATE: {0}" -f $githubStateFile) |
| 139 | + |
| 140 | +if ($mainFailed) { |
| 141 | + exit 1 |
| 142 | +} |
| 143 | + |
| 144 | +Write-Host "Local action run completed successfully." |
0 commit comments