Skip to content

Commit 82c767e

Browse files
author
James Brundage
committed
workflow updates (simplifying gitpub) [skip ci]
1 parent 0af5725 commit 82c767e

File tree

3 files changed

+134
-29
lines changed

3 files changed

+134
-29
lines changed

.github/workflows/OnIssue.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ jobs:
1919
PublishParameters: |
2020
{
2121
"Get-GitPubIssue": {
22-
"UserName": '${{github.repository_owner}}',
23-
"Repository": "PipeScript"
22+
"Repository": '${{github.repository}}'
2423
},
2524
"Get-GitPubRelease": {
26-
"UserName": '${{github.repository_owner}}',
27-
"Repository": "PipeScript"
25+
"Repository": '${{github.repository}}'
2826
},
2927
"Publish-GitPubJekyll": {
3028
"OutputPath": "docs/_posts"

.github/workflows/TestAndPublish.yml

Lines changed: 100 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ jobs:
306306
$Parameters.UserName = ${env:UserName}
307307
$Parameters.TagVersionFormat = ${env:TagVersionFormat}
308308
$Parameters.ReleaseNameFormat = ${env:ReleaseNameFormat}
309+
$Parameters.ReleaseAsset = ${env:ReleaseAsset}
310+
$Parameters.ReleaseAsset = $parameters.ReleaseAsset -split ';' -replace '^[''"]' -replace '[''"]$'
309311
foreach ($k in @($parameters.Keys)) {
310312
if ([String]::IsNullOrEmpty($parameters[$k])) {
311313
$parameters.Remove($k)
@@ -331,7 +333,11 @@ jobs:
331333
332334
# The release name format (default value: '$($imported.Name) $($imported.Version)')
333335
[string]
334-
$ReleaseNameFormat = '$($imported.Name) $($imported.Version)'
336+
$ReleaseNameFormat = '$($imported.Name) $($imported.Version)',
337+
338+
# Any assets to attach to the release. Can be a wildcard or file name.
339+
[string[]]
340+
$ReleaseAsset
335341
)
336342
337343
@@ -377,32 +383,80 @@ jobs:
377383
378384
if ($releaseExists) {
379385
"::warning::Release '$($releaseExists.Name )' Already Exists" | Out-Host
380-
return
386+
$releasedIt = $releaseExists
387+
} else {
388+
$releasedIt = Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
389+
[Ordered]@{
390+
owner = '${{github.owner}}'
391+
repo = '${{github.repository}}'
392+
tag_name = $targetVersion
393+
name = $ExecutionContext.InvokeCommand.ExpandString($ReleaseNameFormat)
394+
body =
395+
if ($env:RELEASENOTES) {
396+
$env:RELEASENOTES
397+
} elseif ($imported.PrivateData.PSData.ReleaseNotes) {
398+
$imported.PrivateData.PSData.ReleaseNotes
399+
} else {
400+
"$($imported.Name) $targetVersion"
401+
}
402+
draft = if ($env:RELEASEISDRAFT) { [bool]::Parse($env:RELEASEISDRAFT) } else { $false }
403+
prerelease = if ($env:PRERELEASE) { [bool]::Parse($env:PRERELEASE) } else { $false }
404+
} | ConvertTo-Json
405+
) -Headers @{
406+
"Accept" = "application/vnd.github.v3+json"
407+
"Content-type" = "application/json"
408+
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
409+
}
381410
}
382411
383412
384-
Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
385-
[Ordered]@{
386-
owner = '${{github.owner}}'
387-
repo = '${{github.repository}}'
388-
tag_name = $targetVersion
389-
name = $ExecutionContext.InvokeCommand.ExpandString($ReleaseNameFormat)
390-
body =
391-
if ($env:RELEASENOTES) {
392-
$env:RELEASENOTES
393-
} elseif ($imported.PrivateData.PSData.ReleaseNotes) {
394-
$imported.PrivateData.PSData.ReleaseNotes
395-
} else {
396-
"$($imported.Name) $targetVersion"
413+
414+
415+
416+
if (-not $releasedIt) {
417+
throw "Release failed"
418+
} else {
419+
$releasedIt | Out-Host
420+
}
421+
422+
$releaseUploadUrl = $releasedIt.upload_url -replace '\{.+$'
423+
424+
if ($ReleaseAsset) {
425+
$fileList = Get-ChildItem -Recurse
426+
$filesToRelease =
427+
@(:nextFile foreach ($file in $fileList) {
428+
foreach ($relAsset in $ReleaseAsset) {
429+
if ($relAsset -match '[\*\?]') {
430+
if ($file.Name -like $relAsset) {
431+
$file; continue nextFile
432+
}
433+
} elseif ($file.Name -eq $relAsset -or $file.FullName -eq $relAsset) {
434+
$file; continue nextFile
435+
}
397436
}
398-
draft = if ($env:RELEASEISDRAFT) { [bool]::Parse($env:RELEASEISDRAFT) } else { $false }
399-
prerelease = if ($env:PRERELEASE) { [bool]::Parse($env:PRERELEASE) } else { $false }
400-
} | ConvertTo-Json
401-
) -Headers @{
402-
"Accept" = "application/vnd.github.v3+json"
403-
"Content-type" = "application/json"
404-
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
437+
})
438+
439+
$releasedFiles = @{}
440+
foreach ($file in $filesToRelease) {
441+
if ($releasedFiles[$file.Name]) {
442+
Write-Warning "Already attached file $($file.Name)"
443+
continue
444+
} else {
445+
$fileBytes = [IO.File]::ReadAllBytes($file.FullName)
446+
$releasedFiles[$file.Name] =
447+
Invoke-RestMethod -Uri "${releaseUploadUrl}?name=$($file.Name)" -Headers @{
448+
"Accept" = "application/vnd.github+json"
449+
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
450+
} -Body $fileBytes -ContentType Application/octet-stream
451+
$releasedFiles[$file.Name]
452+
}
453+
}
454+
455+
"Attached $($releasedFiles.Count) file(s) to release" | Out-Host
405456
}
457+
458+
459+
406460
} @Parameters
407461
- name: PublishPowerShellGallery
408462
id: PublishPowerShellGallery
@@ -516,18 +570,39 @@ jobs:
516570
}
517571
}
518572
} @Parameters
519-
BuildModule:
573+
UsePiecemeal:
574+
runs-on: ubuntu-latest
575+
if: ${{ success() }}
576+
steps:
577+
- name: Check out repository
578+
uses: actions/checkout@v2
579+
- name: UsePiecemeal
580+
uses: StartAutomating/Piecemeal@main
581+
BuildPipeScript:
520582
runs-on: ubuntu-latest
521583
if: ${{ success() }}
522584
steps:
523585
- name: Check out repository
524586
uses: actions/checkout@v2
525587
- name: BuildPipeScript
526588
uses: StartAutomating/PipeScript@main
589+
RunEZOut:
590+
runs-on: ubuntu-latest
591+
if: ${{ success() }}
592+
steps:
593+
- name: Check out repository
594+
uses: actions/checkout@v2
527595
- name: UseEZOut
528596
uses: StartAutomating/EZOut@master
529-
- name: UsePiecemeal
530-
uses: StartAutomating/Piecemeal@main
597+
- name: Push Changes
598+
shell: pwsh
599+
run: git push; exit 0
600+
HelpOut:
601+
runs-on: ubuntu-latest
602+
if: ${{ success() }}
603+
steps:
604+
- name: Check out repository
605+
uses: actions/checkout@v2
531606
- name: UseHelpOut
532607
uses: StartAutomating/HelpOut@master
533608
env:

Github/Jobs/RunGitPub.psd1

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@{
2+
"runs-on" = "ubuntu-latest"
3+
if = '${{ success() }}'
4+
steps = @(
5+
@{
6+
name = 'Check out repository'
7+
uses = 'actions/checkout@v2'
8+
}
9+
@{
10+
name = 'Use GitPub Action'
11+
uses = 'StartAutomating/GitPub@main'
12+
id = 'GitPub'
13+
with = @{
14+
TargetBranch = 'edits-$([DateTime]::Now.ToString("r").Replace(":","-").Replace(" ", ""))'
15+
CommitMessage = 'Posting with GitPub [skip ci]'
16+
PublishParameters = @'
17+
{
18+
"Get-GitPubIssue": {
19+
"Repository": '${{github.repository}}'
20+
},
21+
"Get-GitPubRelease": {
22+
"Repository": '${{github.repository}}'
23+
},
24+
"Publish-GitPubJekyll": {
25+
"OutputPath": "docs/_posts"
26+
}
27+
}
28+
'@
29+
}
30+
}
31+
)
32+
}

0 commit comments

Comments
 (0)