Skip to content

Commit 65083c8

Browse files
Merge pull request #165 from StartAutomating/PipeScriptEnhancements
Pipe script enhancements
2 parents 97312e2 + 822a592 commit 65083c8

27 files changed

+1066
-28
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
## 0.0.14:
2+
* New Transpilers:
3+
* [RemoveParameter] (#159)
4+
* [RenameVariable] (#160)
5+
* Keyword Updates:
6+
* new now supports extended type creation (#164)
7+
* until now supports a TimeSpan, DateTime, or EventName string (#153)
8+
* AST Extended Type Enhancements:
9+
* [TypeConstraintAst] and [AttributeAst] now have .ResolvedCommand (#162)
10+
* Action Updates
11+
* Pulling just before push (#163)
12+
* Not running when there is not a current branch (#158)
13+
* Improving email determination (#156)
14+
* Invoke-PipeScript terminates transpiler errors when run interactively (#161)
15+
---
16+
117
## 0.0.13:
218
* New / Improved Keywords
319
* assert keyword (Support for pipelines) (#143)

Github/Actions/PipeScriptAction.ps1

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,30 @@ $processScriptOutput = { process {
100100

101101

102102
if (-not $UserName) { $UserName = $env:GITHUB_ACTOR }
103-
if (-not $UserEmail) { $UserEmail = "$UserName@github.com" }
103+
if (-not $UserEmail) {
104+
$GitHubUserEmail =
105+
if ($env:GITHUB_TOKEN) {
106+
Invoke-RestMethod -uri "https://api.github.com/user/emails" -Headers @{
107+
Authorization = "token $env:GITHUB_TOKEN"
108+
} |
109+
Select-Object -First 1 -ExpandProperty email
110+
} else {''}
111+
$UserEmail =
112+
if ($GitHubUserEmail) {
113+
$GitHubUserEmail
114+
} else {
115+
"$UserName@github.com"
116+
}
117+
}
104118
git config --global user.email $UserEmail
105119
git config --global user.name $UserName
106120

107121
if (-not $env:GITHUB_WORKSPACE) { throw "No GitHub workspace" }
108122

109-
git pull | Out-Host
123+
$branchName = git rev-parse --abrev-ref HEAD
124+
if (-not $branchName) {
125+
return
126+
}
110127

111128
$PipeScriptStart = [DateTime]::Now
112129
if ($PipeScript) {
@@ -143,11 +160,15 @@ if ($CommitMessage -or $anyFilesChanged) {
143160

144161
git commit -m $ExecutionContext.SessionState.InvokeCommand.ExpandString($CommitMessage)
145162
}
163+
164+
146165

147166
$checkDetached = git symbolic-ref -q HEAD
148167
if (-not $LASTEXITCODE) {
168+
"::notice::Pulling Changes" | Out-Host
169+
git pull | Out-Host
149170
"::notice::Pushing Changes" | Out-Host
150-
git push
171+
git push | Out-Host
151172
"Git Push Output: $($gitPushed | Out-String)"
152173
} else {
153174
"::notice::Not pushing changes (on detached head)" | Out-Host

Invoke-PipeScript.ps1

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
if ($TypeName.IsGeneric) {
8888
$TypeNameParams[$typeName.Name] =
8989
$typeName.GenericArguments |
90-
UnpackTypeConstraintArgs
90+
TypeConstraintToArguments
9191
} elseif (-not $TypeName.IsArray) {
9292
$TypeNameArgs += $TypeName.Name
9393
}
@@ -127,7 +127,7 @@
127127

128128

129129
# If the command is a ```[ScriptBlock]```
130-
if ($Command -is [scriptblock])
130+
if ($Command -is [scriptblock])
131131
{
132132
# Attempt to transpile it.
133133
$TranspiledScriptBlock = $Command | .>Pipescript @ErrorsAndWarnings
@@ -142,8 +142,28 @@
142142
})
143143
return
144144
}
145+
146+
if ($TranspilerErrors) {
147+
$failedMessage = @(
148+
"$($command.Source): " + "$($TranspilerErrors.Count) error(s)"
149+
if ($transpilerWarnings) {
150+
"$($TranspilerWarnings.Count) warning(s)"
151+
}
152+
) -join ','
153+
Write-Error $failedMessage -ErrorId Build.Failed -TargetObject (
154+
[PSCustomObject][ordered]@{
155+
Output = $pipescriptOutput
156+
Errors = $TranspilerErrors
157+
Warnings = $TranspilerWarnings
158+
Command = $Command
159+
Parameters = $InvokePipeScriptParameters
160+
}
161+
)
162+
}
163+
145164
# If it could not be transpiled into a [ScriptBlock] or [ScriptBlock[]]
146-
if ($transpiledScriptBlock -isnot [ScriptBlock] -and -not ($TranspiledScriptBlock -as [scriptblock[]])) {
165+
if ($TranspilerErrors -or
166+
($transpiledScriptBlock -isnot [ScriptBlock] -and -not ($TranspiledScriptBlock -as [scriptblock[]]))) {
147167
# error out.
148168
Write-Error "Command {$command} could not be transpiled into [ScriptBlock]s"
149169
return

New-PipeScript.ps1

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,16 @@ function New-PipeScript {
123123
# The script header.
124124
[Parameter(ValueFromPipelineByPropertyName)]
125125
[string]
126-
$Header
126+
$Header,
127+
# If provided, will automatically create parameters.
128+
# Parameters will be automatically created for any unassigned variables.
129+
[Alias('AutoParameterize','AutoParameters')]
130+
[switch]
131+
$AutoParameter,
132+
# The type used for automatically generated parameters.
133+
# By default, ```[PSObject]```.
134+
[type]
135+
$AutoParameterType = [PSObject]
127136
)
128137
begin {
129138
$ParametersToCreate = [Ordered]@{}
@@ -228,6 +237,24 @@ function New-PipeScript {
228237
# accumulate them.
229238
$allEndBlocks += $end
230239
}
240+
if ($AutoParameter) {
241+
$variableDefinitions = $Begin, $Process, $End |
242+
Where-Object { $_ } |
243+
Search-PipeScript -AstType VariableExpressionAST |
244+
Select-Object -ExpandProperty Result
245+
foreach ($var in $variableDefinitions) {
246+
$assigned = $var.GetAssignments()
247+
if ($assigned) { continue }
248+
$varName = $var.VariablePath.userPath.ToString()
249+
$ParametersToCreate[$varName] = @(
250+
@(
251+
"[Parameter(ValueFromPipelineByPropertyName)]"
252+
"[$($AutoParameterType.FullName -replace '^System\.')]"
253+
"$var"
254+
) -join [Environment]::NewLine
255+
)
256+
}
257+
}
231258
}
232259
end {
233260
# Take all of the accumulated parameters and create a parameter block

New-PipeScript.ps1.ps1

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,18 @@
5151
# The script header.
5252
[Parameter(ValueFromPipelineByPropertyName)]
5353
[string]
54-
$Header
54+
$Header,
55+
56+
# If provided, will automatically create parameters.
57+
# Parameters will be automatically created for any unassigned variables.
58+
[Alias('AutoParameterize','AutoParameters')]
59+
[switch]
60+
$AutoParameter,
61+
62+
# The type used for automatically generated parameters.
63+
# By default, ```[PSObject]```.
64+
[type]
65+
$AutoParameterType = [PSObject]
5566
)
5667

5768
begin {
@@ -164,6 +175,24 @@
164175
$allEndBlocks += $end
165176
}
166177

178+
if ($AutoParameter) {
179+
$variableDefinitions = $Begin, $Process, $End |
180+
Where-Object { $_ } |
181+
Search-PipeScript -AstType VariableExpressionAST |
182+
Select-Object -ExpandProperty Result
183+
foreach ($var in $variableDefinitions) {
184+
$assigned = $var.GetAssignments()
185+
if ($assigned) { continue }
186+
$varName = $var.VariablePath.userPath.ToString()
187+
$ParametersToCreate[$varName] = @(
188+
@(
189+
"[Parameter(ValueFromPipelineByPropertyName)]"
190+
"[$($AutoParameterType.FullName -replace '^System\.')]"
191+
"$var"
192+
) -join [Environment]::NewLine
193+
)
194+
}
195+
}
167196
}
168197

169198
end {

PipeScript.format.ps1xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-16"?>
2-
<!-- Generated with EZOut 1.8.7: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
2+
<!-- Generated with EZOut 1.8.8: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
33
<Configuration>
44
<ViewDefinitions>
55
<View>

PipeScript.psd1

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@{
2-
ModuleVersion = '0.0.13'
2+
ModuleVersion = '0.0.14'
33
Description = 'An Extensible Transpiler for PowerShell (and anything else)'
44
RootModule = 'PipeScript.psm1'
55
PowerShellVersion = '4.0'
@@ -19,6 +19,22 @@
1919
BuildModule = @('EZOut','Piecemeal','PipeScript','HelpOut', 'PSDevOps')
2020
Tags = 'PipeScript','PowerShell', 'Transpilation', 'Compiler'
2121
ReleaseNotes = @'
22+
## 0.0.14:
23+
* New Transpilers:
24+
* [RemoveParameter] (#159)
25+
* [RenameVariable] (#160)
26+
* Keyword Updates:
27+
* new now supports extended type creation (#164)
28+
* until now supports a TimeSpan, DateTime, or EventName string (#153)
29+
* AST Extended Type Enhancements:
30+
* [TypeConstraintAst] and [AttributeAst] now have .ResolvedCommand (#162)
31+
* Action Updates
32+
* Pulling just before push (#163)
33+
* Not running when there is not a current branch (#158)
34+
* Improving email determination (#156)
35+
* Invoke-PipeScript terminates transpiler errors when run interactively (#161)
36+
---
37+
2238
## 0.0.13:
2339
* New / Improved Keywords
2440
* assert keyword (Support for pipelines) (#143)

0 commit comments

Comments
 (0)