Skip to content

Commit

Permalink
Convert-BuildStep: Better support for Actions. Adding .ID to outputte…
Browse files Browse the repository at this point in the history
…d steps.
  • Loading branch information
StartAutomating committed Mar 19, 2021
1 parent fc97097 commit 4c236e4
Showing 1 changed file with 16 additions and 42 deletions.
58 changes: 16 additions & 42 deletions Convert-BuildStep.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
$DefaultParameter = @{},

# The build system. Currently supported options, ADO and GitHub. Defaulting to ADO.
[ValidateSet('ADOPipeline', 'GitHubWorkflow')]
[ValidateSet('ADOPipeline', 'ADOExtension','GitHubWorkflow','GitHubAction')]
[string]
$BuildSystem = 'ADOPipeline',

Expand All @@ -104,12 +104,9 @@
}
return $false
}

$rootDir = if ($RootDirectory) { $RootDirectory } else { $buildOption.RootDirectory }
}

process {

# If we have been given a path and an extension,
if ($PSCmdlet.ParameterSetName -eq 'PathAndExtension') {
if ($Extension -eq '.ps1') # and that extension is .ps1
Expand All @@ -129,7 +126,7 @@
bash= $shellScript
displayName=$Name
} # echo out a bash: step.
} elseif ($BuildSystem -eq 'GitHubWorkflow') {
} elseif ($BuildSystem -in 'GitHubWorkflow', 'GitHubAction') {
[Ordered]@{
name=$Name
run=$shellScript
Expand All @@ -149,7 +146,7 @@
}
}
}
elseif ($BuildSystem -eq 'GitHubWorkflow') {
elseif ($BuildSystem -in 'GitHubWorkflow','GitHubAction') {
[Ordered]@{
name = $Name
run = $pythonScript
Expand Down Expand Up @@ -322,7 +319,7 @@
}
}

if ($BuildSystem -eq 'GitHubWorkflow') {
if ($BuildSystem -in 'GitHubWorkflow','GitHubAction') {
# In GitHub Workflows, variables can come from an event.
$eventName =
& $MatchesAnyWildcard $disambiguatedParameter, $parameterName $InputParameter.Keys
Expand All @@ -338,7 +335,12 @@
$evt = ($evt -replace '\.(?:\*)?$') + '.' + $stepParamName
}
if ($evt -notlike '${{*' -and $evt -notlike '*.*') {
$evt = 'github.events.inputs' + '.' + $stepParamName
$evt =
$(if ($BuildSystem -eq 'GitHubWorkflow') {
'${{github.events.inputs.'
} else {
'${{inputs.'
}) + $stepParamName + '}}'
}
if ($evt -notlike '${{*' -and $evt -notlike 'github.*') {
$evt = "github." + '.' + $stepParamName
Expand Down Expand Up @@ -406,7 +408,7 @@ foreach ($k in @($parameters.Keys)) {
@(
if ($BuildSystem -eq 'ADOPipeline') {
'Write-Host "##[command]'
} elseif ($BuildSystem -eq 'GitHubWorkflow') {
} elseif ($BuildSystem -in'GitHubWorkflow','GitHubAction') {
'Write-Host "::debug::'
}
if ($name) { $name}
Expand All @@ -423,43 +425,16 @@ $Name `@Parameters
"@)
$innerScript = $sb
} else {

if ($ScriptBlock.File -and $rootDir -and
$ScriptBlock.File -ilike "$rootDir*")
{
$relativePath = '.' +
[IO.Path]::DirectorySeparatorChar +
$ScriptBlock.File.Substring("$rootDir".Length).TrimStart([IO.Path]::DirectorySeparatorChar)
$sb = [scriptBlock]::Create(@"
$CollectParameters
$logParameters
& '$relativePath' `@Parameters
"@)
$innerScript = $sb
} else {
$sb = [scriptBlock]::Create(@"
$sb = [scriptBlock]::Create(@"
$CollectParameters
$logParameters
& {$ScriptBlock} `@Parameters
"@)
$innerScript = $sb
}

}
Remove-Item -Force function:_TempFunction
}
else {
if ($ScriptBlock.File -and $rootDir -and
$ScriptBlock.File -ilike "$rootDir*") {
$relativePath = '.' +
[IO.Path]::DirectorySeparatorChar +
$ScriptBlock.File.Substring("$rootDir".Length).TrimStart([IO.Path]::DirectorySeparatorChar)
$innerScript = "& $relativePath"
}
}
$out = [Ordered]@{}


if ($BuildSystem -eq 'ADOPipeline') {
if ($DebugPreference -ne 'silentlycontinue') {
$innerScript = @"
Expand All @@ -481,7 +456,7 @@ try {
} else {
$out.powershell = "$innerScript" -replace '`\$\{','${'
}
$out.name = $Name -replace '\.', '_' -replace '\W'
$out.name = $Name
$out.displayName = $Name
if ($definedParameters) {
$out.parameters = $definedParameters
Expand All @@ -490,8 +465,7 @@ try {
if (-not $out.env) { $out.env = @{}}
$out.env."SYSTEM_ACCESSTOKEN"='$(System.AccessToken)'
}
}
elseif ($BuildSystem -eq 'GitHubWorkflow') {
} elseif ($BuildSystem -in 'GitHubWorkflow','GitHubAction') {
if ($DebugPreference -ne 'silentlycontinue') {
$innerScript = @"
try {
Expand All @@ -503,8 +477,8 @@ try {
}
"@
}
$out.name = $Name -replace '\.', '_' -replace '\W'
$out.id = $Name -replace '\.', '_' -replace '\W'
$out.name = $Name
$out.id = $Name -replace '\W'
$out.shell = 'pwsh'
if ($eventParameters.Count) {
if (-not $out.env) { $out.env = @{}}
Expand Down

0 comments on commit 4c236e4

Please sign in to comment.