-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathaction.yml
209 lines (182 loc) · 7.94 KB
/
action.yml
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
name: UseIrregular
description: Regular Expressions Made Strangle Simple
inputs:
IrregularScript:
required: false
description: |
A PowerShell Script that uses Irregular.
Any files outputted from the script will be added to the repository.
If those files have a .Message attached to them, they will be committed with that message.
SkipIrregularPS1:
required: false
description: 'If set, will not process any files named *.irregular.ps1'
SkipRegexSource:
required: false
description: 'If set, will not process any files named *.regex.source.ps1'
CommitMessage:
required: false
description: If provided, will commit any remaining changes made to the workspace with this commit message.
UserEmail:
required: false
description: The user email associated with a git commit.
UserName:
required: false
description: The user name associated with a git commit.
branding:
icon: cpu
color: blue
runs:
using: composite
steps:
- name: Irregular
id: Irregular
shell: pwsh
env:
IrregularScript: ${{inputs.IrregularScript}}
CommitMessage: ${{inputs.CommitMessage}}
SkipIrregularPS1: ${{inputs.SkipIrregularPS1}}
UserEmail: ${{inputs.UserEmail}}
UserName: ${{inputs.UserName}}
SkipRegexSource: ${{inputs.SkipRegexSource}}
run: |
$Parameters = @{}
$Parameters.IrregularScript = ${env:IrregularScript}
$Parameters.SkipIrregularPS1 = ${env:SkipIrregularPS1}
$Parameters.SkipIrregularPS1 = $parameters.SkipIrregularPS1 -match 'true';
$Parameters.SkipRegexSource = ${env:SkipRegexSource}
$Parameters.SkipRegexSource = $parameters.SkipRegexSource -match 'true';
$Parameters.CommitMessage = ${env:CommitMessage}
$Parameters.UserEmail = ${env:UserEmail}
$Parameters.UserName = ${env:UserName}
foreach ($k in @($parameters.Keys)) {
if ([String]::IsNullOrEmpty($parameters[$k])) {
$parameters.Remove($k)
}
}
Write-Host "::debug:: Irregular $(@(foreach ($p in $Parameters.GetEnumerator()) {'-' + $p.Key + ' ' + $p.Value}) -join ' ')"
& {<#
.Synopsis
GitHub Action for Irregular
.Description
GitHub Action for Irregular. This will:
* Run all *.Irregular.ps1 files beneath the workflow directory
* Run all *.Regex.source.ps1 files beneath the workflow directory
* Run an .IrregularScript parameter.
Any files changed can be outputted by the script, and those changes can be checked back into the repo.
Make sure to use the "persistCredentials" option with checkout.
#>
param(
# A PowerShell Script that uses Irregular.
# Any files outputted from the script will be added to the repository.
# If those files have a .Message attached to them, they will be committed with that message.
[string]
$IrregularScript,
# If set, will not process any files named *.irregular.ps1
[switch]
$SkipIrregularPS1,
# If set, will not process any files named *.regex.source.ps1
[switch]
$SkipRegexSource,
# If provided, will commit any remaining changes made to the workspace with this commit message.
[string]
$CommitMessage,
# The user email associated with a git commit.
[string]
$UserEmail,
# The user name associated with a git commit.
[string]
$UserName
)
$ErrorActionPreference = 'continue'
"::group::Parameters" | Out-Host
[PSCustomObject]$PSBoundParameters | Format-List | Out-Host
"::endgroup::" | Out-Host
$PSD1Found = Get-ChildItem -Recurse -Filter "*.psd1" | Where-Object Name -eq 'Irregular.psd1' | Select-Object -First 1
if ($PSD1Found) {
$irregularModulePath = $PSD1Found
Import-Module $PSD1Found -Force -PassThru | Out-Host
} if ($env:GITHUB_ACTION_PATH) {
$irregularModulePath = Join-Path $env:GITHUB_ACTION_PATH 'Irregular.psd1'
if (Test-path $irregularModulePath) {
Import-Module $irregularModulePath -Force -PassThru | Out-String
} else {
throw "Irregular not found"
}
} elseif (-not (Get-Module Irregular)) {
throw "Action Path not found"
}
"::notice title=ModuleLoaded::Irregular Loaded from Path - $($irregularModulePath)" | Out-Host
$anyFilesChanged = $false
$processScriptOutput = { process {
$out = $_
$outItem = Get-Item -Path $out -ErrorAction SilentlyContinue
$fullName, $shouldCommit =
if ($out -is [IO.FileInfo]) {
$out.FullName, (git status $out.Fullname -s)
} elseif ($outItem) {
$outItem.FullName, (git status $outItem.Fullname -s)
}
if ($shouldCommit) {
git add $fullName
if ($out.Message) {
git commit -m "$($out.Message)"
} elseif ($out.CommitMessage) {
git commit -m "$($out.CommitMessage)"
}
$anyFilesChanged = $true
}
$out
} }
"::notice title=ModuleLoaded,file=$irregularModulePath::Irregular Loaded from Path" | Out-Host
if (-not $UserName) { $UserName = $env:GITHUB_ACTOR }
if (-not $UserEmail) { $UserEmail = "[email protected]" }
git config --global user.email $UserEmail
git config --global user.name $UserName
if (-not $env:GITHUB_WORKSPACE) { throw "No GitHub workspace" }
if ($IrregularScript) {
"::notice::Running Irregular Script" | Out-Host
Invoke-Expression -Command $IrregularScript |
. $processScriptOutput |
Out-Host
}
if (-not $SkipIrregularPS1) {
"::notice::Running Irregular .ps1" | Out-Host
Get-ChildItem -Recurse -Path $env:GITHUB_WORKSPACE |
Where-Object Name -Match '\.Irregular\.ps1$' |
ForEach-Object {
Write-Information "::notice file=$($_.FullName)::Running $($_.Name)"
$irregularPs1File = $_
try {
. $irregularPs1File.FullName |
. $processScriptOutput |
Out-Host
} catch {
"::error::$($_ | Out-String)" | Out-Host
}
}
}
if (-not $SkipRegexSource) {
Get-ChildItem -Recurse -Path $env:GITHUB_WORKSPACE |
Where-Object Name -Match '\.regex\.source\.ps1$' |
ForEach-Object {
Write-Information "::notice file=$($_.FullName)::Running $($_.Name)"
. $_.FullName |
. $processScriptOutput |
Out-Host
}
}
if ($CommitMessage -or $anyFilesChanged) {
if ($CommitMessage) {
dir $env:GITHUB_WORKSPACE -Recurse |
ForEach-Object {
$gitStatusOutput = git status $_.Fullname -s
if ($gitStatusOutput) {
git add $_.Fullname
}
}
git commit -m $ExecutionContext.SessionState.InvokeCommand.ExpandString($CommitMessage)
}
"::notice::Pushing" | Out-Host
$gitPushed = git push 2>&1
"Git Push Output: $($gitPushed | Out-String)"
}} @Parameters