Skip to content

Commit

Permalink
Updating workflows to use GitPub (Fixes #37)
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Oct 12, 2022
1 parent 7709e2b commit 14cb891
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 13 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/OnIssue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

name: OnIssueChanged
on:
issues:
workflow_dispatch:
jobs:
RunGitPub:
runs-on: ubuntu-latest
if: ${{ success() }}
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Use GitPub Action
uses: StartAutomating/GitPub@main
id: GitPub
with:
TargetBranch: edits-$([DateTime]::Now.ToString("r").Replace(":","-").Replace(" ", ""))
CommitMessage: Posting with GitPub [skip ci]
PublishParameters: |
{
"Get-GitPubIssue": {
"Repository": '${{github.repository}}'
},
"Get-GitPubRelease": {
"Repository": '${{github.repository}}'
},
"Publish-GitPubJekyll": {
"OutputPath": "docs/_posts"
}
}
94 changes: 88 additions & 6 deletions .github/workflows/TestAndPublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ jobs:
$Parameters.UserName = ${env:UserName}
$Parameters.TagVersionFormat = ${env:TagVersionFormat}
$Parameters.ReleaseNameFormat = ${env:ReleaseNameFormat}
$Parameters.ReleaseAsset = ${env:ReleaseAsset}
$Parameters.ReleaseAsset = $parameters.ReleaseAsset -split ';' -replace '^[''"]' -replace '[''"]$'
foreach ($k in @($parameters.Keys)) {
if ([String]::IsNullOrEmpty($parameters[$k])) {
$parameters.Remove($k)
Expand All @@ -331,7 +333,11 @@ jobs:
# The release name format (default value: '$($imported.Name) $($imported.Version)')
[string]
$ReleaseNameFormat = '$($imported.Name) $($imported.Version)'
$ReleaseNameFormat = '$($imported.Name) $($imported.Version)',
# Any assets to attach to the release. Can be a wildcard or file name.
[string[]]
$ReleaseAsset
)
Expand Down Expand Up @@ -381,7 +387,7 @@ jobs:
}
Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
$releasedIt = Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
[Ordered]@{
owner = '${{github.owner}}'
repo = '${{github.repository}}'
Expand All @@ -403,13 +409,62 @@ jobs:
"Content-type" = "application/json"
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
}
if (-not $releasedIt) {
throw "Release failed"
} else {
$releasedIt | Out-Host
}
$releaseUploadUrl = $releasedIt.upload_url -replace '\{.+$'
if ($ReleaseAsset) {
$fileList = Get-ChildItem -Recurse
$filesToRelease =
@(:nextFile foreach ($file in $fileList) {
foreach ($relAsset in $ReleaseAsset) {
if ($relAsset -match '[\*\?]') {
if ($file.Name -like $relAsset) {
$file; continue nextFile
}
} elseif ($file.Name -eq $relAsset -or $file.FullName -eq $relAsset) {
$file; continue nextFile
}
}
})
$releasedFiles = @{}
foreach ($file in $filesToRelease) {
if ($releasedFiles[$file.Name]) {
Write-Warning "Already attached file $($file.Name)"
continue
} else {
$fileBytes = [IO.File]::ReadAllBytes($file.FullName)
$releasedFiles[$file.Name] =
Invoke-RestMethod -Uri "${releaseUploadUrl}?name=$($file.Name)" -Headers @{
"Accept" = "application/vnd.github+json"
"ContentType" = "application/octet-stream"
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
} -Body $fileBytes
$releasedFiles[$file.Name]
}
}
"Attached $($releasedFiles.Count) file(s) to release" | Out-Host
}
} @Parameters
- name: PublishPowerShellGallery
id: PublishPowerShellGallery
shell: pwsh
run: |
$Parameters = @{}
$Parameters.ModulePath = ${env:ModulePath}
$Parameters.Exclude = ${env:Exclude}
$Parameters.Exclude = $parameters.Exclude -split ';' -replace '^[''"]' -replace '[''"]$'
foreach ($k in @($parameters.Keys)) {
if ([String]::IsNullOrEmpty($parameters[$k])) {
$parameters.Remove($k)
Expand All @@ -418,19 +473,33 @@ jobs:
Write-Host "::debug:: PublishPowerShellGallery $(@(foreach ($p in $Parameters.GetEnumerator()) {'-' + $p.Key + ' ' + $p.Value}) -join ' ')"
& {param(
[string]
$ModulePath
$ModulePath,
[string[]]
$Exclude = @('*.png', '*.mp4', '*.jpg','*.jpeg', '*.gif', 'docs[/\]*')
)
$gitHubEvent = if ($env:GITHUB_EVENT_PATH) {
[IO.File]::ReadAllText($env:GITHUB_EVENT_PATH) | ConvertFrom-Json
} else { $null }
if (-not $Exclude) {
$Exclude = @('*.png', '*.mp4', '*.jpg','*.jpeg', '*.gif','docs[/\]*')
}
@"
::group::GitHubEvent
$($gitHubEvent | ConvertTo-Json -Depth 100)
::endgroup::
"@ | Out-Host
@"
::group::PSBoundParameters
$($PSBoundParameters | ConvertTo-Json -Depth 100)
::endgroup::
"@ | Out-Host
if (-not ($gitHubEvent.head_commit.message -match "Merge Pull Request #(?<PRNumber>\d+)") -and
(-not $gitHubEvent.psobject.properties['inputs'])) {
"::warning::Pull Request has not merged, skipping Gallery Publish" | Out-Host
Expand Down Expand Up @@ -473,9 +542,24 @@ jobs:
if (Test-Path $moduleGitPath) {
Remove-Item -Recurse -Force $moduleGitPath
}
if ($Exclude) {
"::notice::Attempting to Exlcude $exclude" | Out-Host
Get-ChildItem $moduleTempPath -Recurse |
Where-Object {
foreach ($ex in $exclude) {
if ($_.FullName -like $ex) {
"::notice::Excluding $($_.FullName)" | Out-Host
return $true
}
}
} |
Remove-Item
}
Write-Host "Module Files:"
Get-ChildItem $moduleTempPath -Recurse
Write-Host "Publishing $moduleName [$($imported.Version)] to Gallery"
Write-Host "Publishing $moduleName [$($imported.Version)] to Gallery"
Publish-Module -Path $moduleTempPath -NuGetApiKey $gk
if ($?) {
Write-Host "Published to Gallery"
Expand All @@ -495,8 +579,6 @@ jobs:
uses: StartAutomating/PipeScript@main
- name: UseEZOut
uses: StartAutomating/EZOut@master
- name: UsePiecemeal
uses: StartAutomating/Piecemeal@main
- name: UseHelpOut
uses: StartAutomating/HelpOut@master

32 changes: 32 additions & 0 deletions GitHub/Jobs/RunGitPub.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@{
"runs-on" = "ubuntu-latest"
if = '${{ success() }}'
steps = @(
@{
name = 'Check out repository'
uses = 'actions/checkout@v2'
}
@{
name = 'Use GitPub Action'
uses = 'StartAutomating/GitPub@main'
id = 'GitPub'
with = @{
TargetBranch = 'edits-$([DateTime]::Now.ToString("r").Replace(":","-").Replace(" ", ""))'
CommitMessage = 'Posting with GitPub [skip ci]'
PublishParameters = @'
{
"Get-GitPubIssue": {
"Repository": '${{github.repository}}'
},
"Get-GitPubRelease": {
"Repository": '${{github.repository}}'
},
"Publish-GitPubJekyll": {
"OutputPath": "docs/_posts"
}
}
'@
}
}
)
}
11 changes: 4 additions & 7 deletions LightScript.GitHubWorkflow.psdevops.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#requires -Module PSDevOps
Push-Location $PSScriptRoot

New-GitHubWorkflow -Name "Analyze, Test, Tag, and Publish" -On Push, PullRequest, Demand -Job PowerShellStaticAnalysis, TestPowerShellOnLinux, TagReleaseAndPublish |
Import-BuildStep -Module LightScript
New-GitHubWorkflow -Name "Analyze, Test, Tag, and Publish" -On Push, PullRequest, Demand -Job PowerShellStaticAnalysis, TestPowerShellOnLinux, TagReleaseAndPublish, BuildModule |
Set-Content .\.github\workflows\TestAndPublish.yml -Encoding UTF8 -PassThru

New-GitHubWorkflow -Name "Run HelpOut" -On Push -Job HelpOut |
Set-Content .\.github\workflows\UpdateDocs.yml -Encoding UTF8 -PassThru

New-GitHubWorkflow -Name "Run EZOut" -On Push -Job RunEZOut |
Set-Content .\.github\workflows\RunEZOut.yml -Encoding UTF8 -PassThru
New-GitHubWorkflow -On Issue, Demand -Job RunGitPub -Name OnIssueChanged |
Set-Content (Join-Path $PSScriptRoot .github\workflows\OnIssue.yml) -Encoding UTF8 -PassThru

Pop-Location

0 comments on commit 14cb891

Please sign in to comment.