Skip to content

Commit 8daa461

Browse files
author
James Brundage
committed
fix: PSJekyll Action ( Fixes #16 )
Adding -TargetBranch
1 parent f0d2239 commit 8daa461

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

Build/GitHub/Actions/PSJekyllAction.ps1

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ $SkipPSJekyllPS1,
3030
[string[]]
3131
$InstallModule,
3232

33+
# If provided, will checkout a new branch before making the changes.
34+
[string]
35+
$TargetBranch,
36+
3337
# If provided, will commit any remaining changes made to the workspace with this commit message.
3438
[string]
3539
$CommitMessage,
@@ -115,6 +119,14 @@ function InitializeAction {
115119

116120
# Pull down any changes
117121
git pull | Out-Host
122+
123+
if ($TargetBranch) {
124+
"::notice title=Expanding target branch string $targetBranch" | Out-Host
125+
$TargetBranch = $ExecutionContext.SessionState.InvokeCommand.ExpandString($TargetBranch)
126+
"::notice title=Checking out target branch::$targetBranch" | Out-Host
127+
git checkout -b $TargetBranch | Out-Host
128+
git pull | Out-Host
129+
}
118130
}
119131

120132
function InvokeActionModule {
@@ -227,7 +239,11 @@ function PushActionOutput {
227239
$checkDetached = git symbolic-ref -q HEAD
228240
if (-not $LASTEXITCODE) {
229241
"::notice::Pushing Changes" | Out-Host
230-
git push
242+
if ($TargetBranch -and $anyFilesChanged) {
243+
git push --set-upstream origin $TargetBranch
244+
} elseif ($anyFilesChanged) {
245+
git push
246+
}
231247
"Git Push Output: $($gitPushed | Out-String)"
232248
} else {
233249
"::notice::Not pushing changes (on detached head)" | Out-Host

action.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ inputs:
1414
InstallModule:
1515
required: false
1616
description: A list of modules to be installed from the PowerShell gallery before scripts run.
17+
TargetBranch:
18+
required: false
19+
description: If provided, will checkout a new branch before making the changes.
1720
CommitMessage:
1821
required: false
1922
description: If provided, will commit any remaining changes made to the workspace with this commit message.
@@ -39,13 +42,15 @@ runs:
3942
PSJekyllScript: ${{inputs.PSJekyllScript}}
4043
CommitMessage: ${{inputs.CommitMessage}}
4144
UserName: ${{inputs.UserName}}
45+
TargetBranch: ${{inputs.TargetBranch}}
4246
run: |
4347
$Parameters = @{}
4448
$Parameters.PSJekyllScript = ${env:PSJekyllScript}
4549
$Parameters.SkipPSJekyllPS1 = ${env:SkipPSJekyllPS1}
4650
$Parameters.SkipPSJekyllPS1 = $parameters.SkipPSJekyllPS1 -match 'true';
4751
$Parameters.InstallModule = ${env:InstallModule}
4852
$Parameters.InstallModule = $parameters.InstallModule -split ';' -replace '^[''"]' -replace '[''"]$'
53+
$Parameters.TargetBranch = ${env:TargetBranch}
4954
$Parameters.CommitMessage = ${env:CommitMessage}
5055
$Parameters.UserEmail = ${env:UserEmail}
5156
$Parameters.UserName = ${env:UserName}
@@ -87,6 +92,10 @@ runs:
8792
[string[]]
8893
$InstallModule,
8994
95+
# If provided, will checkout a new branch before making the changes.
96+
[string]
97+
$TargetBranch,
98+
9099
# If provided, will commit any remaining changes made to the workspace with this commit message.
91100
[string]
92101
$CommitMessage,
@@ -172,6 +181,14 @@ runs:
172181
173182
# Pull down any changes
174183
git pull | Out-Host
184+
185+
if ($TargetBranch) {
186+
"::notice title=Expanding target branch string $targetBranch" | Out-Host
187+
$TargetBranch = $ExecutionContext.SessionState.InvokeCommand.ExpandString($TargetBranch)
188+
"::notice title=Checking out target branch::$targetBranch" | Out-Host
189+
git checkout -b $TargetBranch | Out-Host
190+
git pull | Out-Host
191+
}
175192
}
176193
177194
function InvokeActionModule {
@@ -284,7 +301,11 @@ runs:
284301
$checkDetached = git symbolic-ref -q HEAD
285302
if (-not $LASTEXITCODE) {
286303
"::notice::Pushing Changes" | Out-Host
287-
git push
304+
if ($TargetBranch -and $anyFilesChanged) {
305+
git push --set-upstream origin $TargetBranch
306+
} elseif ($anyFilesChanged) {
307+
git push
308+
}
288309
"Git Push Output: $($gitPushed | Out-String)"
289310
} else {
290311
"::notice::Not pushing changes (on detached head)" | Out-Host

0 commit comments

Comments
 (0)