-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-set-variables.ps1
More file actions
42 lines (37 loc) · 1.29 KB
/
github-set-variables.ps1
File metadata and controls
42 lines (37 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<#
===============================================================
AUTHOR: Tao Yang
DATE: 13/01/2026
NAME: github-set-variables.ps1
VERSION: 1.0.0
COMMENT: Set GitHub Action variables from configuration files.
===============================================================
#>
[CmdletBinding()]
param (
[parameter(Mandatory = $true)]
[ValidateScript({ Test-Path $_ -PathType 'leaf' })]
[string]$configFilePath
)
# Import required module for YAML parsing
if (-not (Get-Module -ListAvailable -Name powershell-yaml)) {
Write-Verbose "Installing powershell-yaml module..."
Install-Module -Name powershell-yaml -Force -Scope CurrentUser
}
Import-Module powershell-yaml
# Read and parse YAML file
Write-Output "Reading configuration from: $configFilePath"
$yamlContent = Get-Content -Path $configFilePath -Raw
$config = ConvertFrom-Yaml -Yaml $yamlContent
# Check if variables exist in the configuration
if (-not $config.variables) {
Write-Error "No 'variables' section found in the configuration file."
exit 1
}
foreach ($item in $config.variables) {
$name = $item.name
$value = $item.Value
# Set GitHub Action output variable
Write-Output "Setting variable: '$name' with value: '$value'"
Write-Output ('{0}={1}' -f $name, $value) | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
}