@@ -47,43 +47,111 @@ $UserEmail,
47
47
$UserName
48
48
)
49
49
50
+ # region Initial Logging
51
+
52
+ # Output the parameters passed to this script (for debugging)
50
53
" ::group::Parameters" | Out-Host
51
54
[PSCustomObject ]$PSBoundParameters | Format-List | Out-Host
52
55
" ::endgroup::" | Out-Host
53
56
54
- if ($env: GITHUB_ACTION_PATH ) {
55
- $PSDevOpsModulePath = Join-Path $env: GITHUB_ACTION_PATH ' PSDevOps.psd1'
56
- if (Test-path $PSDevOpsModulePath ) {
57
- Import-Module $PSDevOpsModulePath - Force - PassThru | Out-String
58
- } else {
59
- throw " PSDevOps not found"
60
- }
61
- } elseif (-not (Get-Module PSDevOps)) {
62
- throw " Action Path not found"
57
+ # Get the GitHub Event
58
+ $gitHubEvent =
59
+ if ($env: GITHUB_EVENT_PATH ) {
60
+ [IO.File ]::ReadAllText($env: GITHUB_EVENT_PATH ) | ConvertFrom-Json
61
+ } else { $null }
62
+
63
+ # Log the GitHub Event
64
+ @"
65
+ ::group::GitHubEvent
66
+ $ ( $gitHubEvent | ConvertTo-Json - Depth 100 )
67
+ ::endgroup::
68
+ "@ | Out-Host
69
+
70
+ # Check that there is a workspace (and throw if there is not)
71
+ if (-not $env: GITHUB_WORKSPACE ) { throw " No GitHub workspace" }
72
+
73
+ # endregion Initial Logging
74
+
75
+ # Check to ensure we are on a branch
76
+ $branchName = git rev- parse -- abrev- ref HEAD
77
+ # If we were not, return.
78
+ if (-not $branchName ) {
79
+ " ::warning::Not on a branch" | Out-Host
80
+ return
63
81
}
64
82
65
- " ::notice title=ModuleLoaded::PSDevOps Loaded from Path - $ ( $PSDevOpsModulePath ) " | Out-Host
83
+ # region Configure UserName and Email
84
+ if (-not $UserName ) {
85
+ $UserName =
86
+ if ($env: GITHUB_TOKEN ) {
87
+ Invoke-RestMethod - uri " https://api.github.com/user" - Headers @ {
88
+ Authorization = " token $env: GITHUB_TOKEN "
89
+ } |
90
+ Select-Object - First 1 - ExpandProperty name
91
+ } else {
92
+ $env: GITHUB_ACTOR
93
+ }
94
+ }
66
95
96
+ if (-not $UserEmail ) {
97
+ $GitHubUserEmail =
98
+ if ($env: GITHUB_TOKEN ) {
99
+ Invoke-RestMethod - uri " https://api.github.com/user/emails" - Headers @ {
100
+ Authorization = " token $env: GITHUB_TOKEN "
101
+ } |
102
+ Select-Object - First 1 - ExpandProperty email
103
+ } else {' ' }
104
+ $UserEmail =
105
+ if ($GitHubUserEmail ) {
106
+ $GitHubUserEmail
107
+ } else {
108
+ " $UserName @github.com"
109
+ }
110
+ }
111
+ git config -- global user.email $UserEmail
112
+ git config -- global user.name $UserName
113
+ # endregion Configure UserName and Email
67
114
68
- $ght =
69
- if ($GitHubToken ) {
70
- $GitHubToken
71
- } elseif ($env: GITHUB_TOKEN ) {
72
- $env: GITHUB_TOKEN
115
+ git pull | Out-Host
116
+
117
+
118
+ # region Load Action Module
119
+ $ActionModuleName = " EZOut"
120
+ $ActionModuleFileName = " $ActionModuleName .psd1"
121
+
122
+ # Try to find a local copy of the action's module.
123
+ # This allows the action to use the current branch's code instead of the action's implementation.
124
+ $PSD1Found = Get-ChildItem - Recurse - Filter " *.psd1" |
125
+ Where-Object Name -eq $ActionModuleFileName |
126
+ Select-Object - First 1
127
+
128
+ $ActionModulePath , $ActionModule =
129
+ # If there was a .PSD1 found
130
+ if ($PSD1Found ) {
131
+ $PSD1Found.FullName # import from there.
132
+ Import-Module $PSD1Found.FullName - Force - PassThru
133
+ }
134
+ # Otherwise, if we have a GITHUB_ACTION_PATH
135
+ elseif ($env: GITHUB_ACTION_PATH )
136
+ {
137
+ $actionModulePath = Join-Path $env: GITHUB_ACTION_PATH $ActionModuleFileName
138
+ if (Test-path $actionModulePath ) {
139
+ $actionModulePath
140
+ Import-Module $actionModulePath - Force - PassThru
141
+ } else {
142
+ throw " $actionModuleName not found"
143
+ }
144
+ }
145
+ elseif (-not (Get-Module $ActionModuleName )) {
146
+ throw " $actionModulePath could not be loaded."
73
147
}
74
- " ::group::Connecting to Github" | Out-Host
75
- $connectStart = [DateTime ]::now
76
- Connect-GitHub - PersonalAccessToken $GitHubToken - PassThru |
77
- ForEach-Object {
78
- $githubModule = $_
79
- " ::notice title=Connected::Connect-GitHub finished - $ ( $githubModule.ExportedCommands.Count ) Commands Imported" | Out-Host
80
- $githubModule.ExportedCommands.Keys -join [Environment ]::Newline | Out-Host
81
- } |
82
- Out-Host
83
- " ::endgroup::" | Out-Host
148
+
149
+ " ::notice title=ModuleLoaded::$actionModuleName Loaded from Path - $ ( $actionModulePath ) " | Out-Host
150
+ # endregion Load Action Module
151
+
84
152
85
153
$anyFilesChanged = $false
86
- $processScriptOutput = { process {
154
+ filter ProcessScriptOutput {
87
155
$out = $_
88
156
$outItem = Get-Item - Path $out - ErrorAction SilentlyContinue
89
157
$fullName , $shouldCommit =
@@ -98,11 +166,32 @@ $processScriptOutput = { process {
98
166
git commit - m " $ ( $out.Message ) "
99
167
} elseif ($out.CommitMessage ) {
100
168
git commit - m " $ ( $out.CommitMessage ) "
169
+ } elseif ($gitHubEvent.head_commit.message ) {
170
+ git commit - m " $ ( $gitHubEvent.head_commit.message ) "
101
171
}
102
172
$anyFilesChanged = $true
103
173
}
104
174
$out
105
- } }
175
+ }
176
+
177
+ # endregion Declare Functions and Variables
178
+
179
+ $ght =
180
+ if ($GitHubToken ) {
181
+ $GitHubToken
182
+ } elseif ($env: GITHUB_TOKEN ) {
183
+ $env: GITHUB_TOKEN
184
+ }
185
+ " ::group::Connecting to Github" | Out-Host
186
+ $connectStart = [DateTime ]::now
187
+ Connect-GitHub - PersonalAccessToken $GitHubToken - PassThru |
188
+ ForEach-Object {
189
+ $githubModule = $_
190
+ " ::notice title=Connected::Connect-GitHub finished - $ ( $githubModule.ExportedCommands.Count ) Commands Imported" | Out-Host
191
+ $githubModule.ExportedCommands.Keys -join [Environment ]::Newline | Out-Host
192
+ } |
193
+ Out-Host
194
+ " ::endgroup::" | Out-Host
106
195
107
196
108
197
if (-not $UserName ) { $UserName = $env: GITHUB_ACTOR }
@@ -117,11 +206,11 @@ git pull | Out-Host
117
206
$PSDevOpsScriptStart = [DateTime ]::Now
118
207
if ($PSDevOpsScript ) {
119
208
Invoke-Expression - Command $PSDevOpsScript |
120
- . $processScriptOutput |
209
+ ProcessScriptOutput |
121
210
Out-Host
122
211
}
123
212
$PSDevOpsScriptTook = [Datetime ]::Now - $PSDevOpsScriptStart
124
- " ::set-output name=PSDevOpsScriptRuntime::$ ( $PSDevOpsScriptTook.TotalMilliseconds ) " | Out-Host
213
+ # "::set-output name=PSDevOpsScriptRuntime::$($PSDevOpsScriptTook.TotalMilliseconds)" | Out-Host
125
214
126
215
$PSDevOpsPS1Start = [DateTime ]::Now
127
216
$PSDevOpsPS1List = @ ()
@@ -134,15 +223,15 @@ if (-not $SkipPSDevOpsPS1) {
134
223
$PSDevOpsPS1Count ++
135
224
" ::notice title=Running::$ ( $_.Fullname ) " | Out-Host
136
225
. $_.FullName |
137
- . $processScriptOutput |
226
+ ProcessScriptOutput |
138
227
Out-Host
139
228
}
140
229
}
141
230
$PSDevOpsPS1EndStart = [DateTime ]::Now
142
231
$PSDevOpsPS1Took = [Datetime ]::Now - $PSDevOpsPS1Start
143
- " ::set-output name=PSDevOpsPS1Count::$ ( $PSDevOpsPS1List.Length ) " | Out-Host
144
- " ::set-output name=PSDevOpsPS1Files::$ ( $PSDevOpsPS1List -join ' ;' ) " | Out-Host
145
- " ::set-output name=PSDevOpsPS1Runtime::$ ( $PSDevOpsPS1Took.TotalMilliseconds ) " | Out-Host
232
+ # "::set-output name=PSDevOpsPS1Count::$($PSDevOpsPS1List.Length)" | Out-Host
233
+ # "::set-output name=PSDevOpsPS1Files::$($PSDevOpsPS1List -join ';')" | Out-Host
234
+ # "::set-output name=PSDevOpsPS1Runtime::$($PSDevOpsPS1Took.TotalMilliseconds)" | Out-Host
146
235
if ($CommitMessage -or $anyFilesChanged ) {
147
236
if ($CommitMessage ) {
148
237
dir $env: GITHUB_WORKSPACE - Recurse |
@@ -155,10 +244,7 @@ if ($CommitMessage -or $anyFilesChanged) {
155
244
156
245
git commit - m $ExecutionContext.SessionState.InvokeCommand.ExpandString ($CommitMessage )
157
246
}
158
-
159
-
160
-
161
-
247
+
162
248
$checkDetached = git symbolic- ref - q HEAD
163
249
if (-not $LASTEXITCODE ) {
164
250
" ::notice::Pushing Changes" | Out-Host
0 commit comments