Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions .github/workflows/UpdateModuleTag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: UpdateModuleTag
on:
workflow_dispatch:
pull_request:
branches:
- main
- master
paths-ignore:
- 'docs/**'
- '*.help.txt'
- '*.md'

jobs:
UpdateModuleTag:
if: ${{github.event.action == 'closed' && github.event.merged == true}}
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: TagModuleVersion
id: TagModuleVersion
shell: pwsh
run: |
$Parameters = @{}
$Parameters.ModulePath = ${env:ModulePath}
$Parameters.UserEmail = ${env:UserEmail}
$Parameters.UserName = ${env:UserName}
$Parameters.TagVersionFormat = ${env:TagVersionFormat}
$Parameters.TagAnnotationFormat = ${env:TagAnnotationFormat}
foreach ($k in @($parameters.Keys)) {
if ([String]::IsNullOrEmpty($parameters[$k])) {
$parameters.Remove($k)
}
}
Write-Host "::debug:: TagModuleVersion $(@(foreach ($p in $Parameters.GetEnumerator()) {'-' + $p.Key + ' ' + $p.Value}) -join ' ')"
& {param(
[string]
$ModulePath,

# The user email associated with a git commit.
[string]
$UserEmail,

# The user name associated with a git commit.
[string]
$UserName,

# The tag version format (default value: 'v$(imported.Version)')
# This can expand variables. $imported will contain the imported module.
[string]
$TagVersionFormat = 'v$($imported.Version)',

# The tag version format (default value: '$($imported.Name) $(imported.Version)')
# This can expand variables. $imported will contain the imported module.
[string]
$TagAnnotationFormat = '$($imported.Name) $($imported.Version)'
)

$imported =
if (-not $ModulePath) {
$orgName, $moduleName = $env:BUILD_REPOSITORY_ID -split "/"
Import-Module ".\$moduleName.psd1" -Force -PassThru -Global
} else {
Import-Module $modulePath -Force -PassThru -Global
}

if (-not $imported) { return }

$targetVersion =$ExecutionContext.InvokeCommand.ExpandString($TagVersionFormat)

$versionTagExists = git tag --list | Where-Object { $_ -eq $targetVersion }

if ($versionTagExists) {
"::warning::Version $($versionTagExists)"
return
}

if (-not $UserName) { $UserName = $env:GITHUB_ACTOR }
if (-not $UserEmail) { $UserEmail = "$UserName@github.com" }
git config --global user.email $UserEmail
git config --global user.name $UserName

git tag -a $targetVersion -m $ExecutionContext.InvokeCommand.ExpandString($TagAnnotationFormat)
git push --tags

if ($env:GITHUB_ACTOR) {
exit 0
}


} @Parameters

14 changes: 14 additions & 0 deletions Convert-BuildStep.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,20 @@ $collectParameters
Import-Module `$($modulePathVariable) -Force -PassThru
$logParameters
$Name `@Parameters
"@)
$innerScript = $sb
} elseif ($BuildOption.RootDirectory -and $ScriptBlock.File -and
$ScriptBlock.File -like "$($BuildOption.RootDirectory)*") {
$relativeScriptPath =
$ScriptBlock.File.Substring(
$BuildOption.RootDirectory.Length
).TrimStart(
[IO.Path]::DirectorySeparatorChar
).Replace('\','/')
$sb = [ScriptBlock]::Create(@"
$CollectParameters
$logParameters
& './$relativeScriptPath' `@Parameters
"@)
$innerScript = $sb
} else {
Expand Down
26 changes: 24 additions & 2 deletions Expand-BuildStep.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
}

$splatMe.Remove('StepMap')
:nextKey foreach ($kv in $stepMap.GetEnumerator()) {

:nextKey foreach ($kv in $stepMap.GetEnumerator()) {
if ($kv.Key.EndsWith('s') -and -not $singleton) { # Already pluralized
$thingType = $kv.Key.Substring(0,$kv.Key.Length -1)
$propName = $kv.Key
Expand All @@ -117,8 +118,9 @@
$propName = $kv.Key
} else {
$thingType = $kv.Key
$thingTypePlural = $kv.Key + 's'
$propName =
if ($SingleItemName -notcontains $thingType -and
if ($SingleItemName -notcontains $thingType -and
$thingType -notmatch '\W$' -and
$theComponentNames.Keys -contains $thingType) {
$kv.Key.Substring(0,1).ToLower() + $kv.Key.Substring(1) + 's'
Expand Down Expand Up @@ -312,6 +314,26 @@
$outObject[$propName] -isnot [Collections.IList]) {
$outObject[$propName] = @($outObject[$propName])
}

if ($SingleItemName -contains $propName -and
$outObject[$propName] -is [Collections.IList]) {
$newOut = [Ordered]@{}
foreach ($obj in $outObject[$propName]) {
if ($obj -is [Collections.IDictionary]) {
$k = @($obj.Keys)[0]
if ($obj.Count -eq 1 -and
$obj.Keys -contains $k) {
$newOut[$k] = $obj.$k
} else {
$newOut[$k] = $obj
}
}
elseif ($obj -is [string]) {
$newOut[$obj] = [Ordered]@{}
}
}
$outObject[$propName] = $newOut
}
}
}
$outObject
Expand Down
12 changes: 12 additions & 0 deletions GitHub/Jobs/PublishToGallery.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@{
"runs-on" = "ubuntu-latest"
if = '${{ success() }}'
steps = @(
@{
name = 'Check out repository'
uses = 'actions/checkout@v2'
}, 'PublishPowerShellGallery'
)
}


11 changes: 11 additions & 0 deletions GitHub/Jobs/UpdateModuleTag.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@{
"runs-on" = "ubuntu-latest"
if = '${{ success() }}'
steps = @(
@{
name = 'Check out repository'
uses = 'actions/checkout@v2'
}, 'TagModuleVersion'
)
}

2 changes: 1 addition & 1 deletion GitHub/On/Demand.psd1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
'workflow_dispatch'
@{'workflow_dispatch'=@{}}
10 changes: 10 additions & 0 deletions GitHub/On/PullRequestMerged.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@{
pull_request = @{
branches =@('main','master')
if = @'
${{github.event.action == 'closed' && github.event.merged == true}}
'@
"paths-ignore" = @("docs/**","*.help.txt", "*.md")
}
}

8 changes: 8 additions & 0 deletions GitHub/On/PullToMain.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@{
pull_request = @{
branches =@('main','master')
"paths-ignore" = @("docs/**","*.help.txt", "*.md")
}
}


2 changes: 1 addition & 1 deletion GitHub/On/Push.psd1
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
'push'
@{'push'=@{}}

68 changes: 68 additions & 0 deletions GitHub/Steps/PublishPowerShellGallery.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
param(
[string]
$ModulePath
)
$gitHubEvent = if ($env:GITHUB_EVENT_PATH) {
[IO.File]::ReadAllText($env:GITHUB_EVENT_PATH) | ConvertFrom-Json
} else { $null }


@"
::group::GitHubEvent
$($gitHubEvent | 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" | Out-Host
return
}


$imported =
if (-not $ModulePath) {
$orgName, $moduleName = $env:GITHUB_REPOSITORY -split "/"
Import-Module ".\$moduleName.psd1" -Force -PassThru -Global
} else {
Import-Module $modulePath -Force -PassThru -Global
}

if (-not $imported) { return }

$foundModule = try { Find-Module -Name $imported.Name -ErrorAction SilentlyContinue } catch {}

if ($foundModule -and $foundModule.Version -ge $imported.Version) {
"::warning::Gallery Version of $moduleName is more recent ($($foundModule.Version) >= $($imported.Version))" | Out-Host
} else {

$gk = '${{secrets.GALLERYKEY}}'

$rn = Get-Random
$moduleTempFolder = Join-Path $pwd "$rn"
$moduleTempPath = Join-Path $moduleTempFolder $moduleName
New-Item -ItemType Directory -Path $moduleTempPath -Force | Out-Host

Write-Host "Staging Directory: $ModuleTempPath"

$imported | Split-Path |
Get-ChildItem -Force |
Where-Object Name -NE $rn |
Copy-Item -Destination $moduleTempPath -Recurse

$moduleGitPath = Join-Path $moduleTempPath '.git'
Write-Host "Removing .git directory"
if (Test-Path $moduleGitPath) {
Remove-Item -Recurse -Force $moduleGitPath
}
Write-Host "Module Files:"
Get-ChildItem $moduleTempPath -Recurse
Write-Host "Publishing $moduleName [$($imported.Version)] to Gallery"
Publish-Module -Path $moduleTempPath -NuGetApiKey $gk
if ($?) {
Write-Host "Published to Gallery"
} else {
Write-Host "Gallery Publish Failed"
exit 1
}
}
2 changes: 1 addition & 1 deletion GitHub/Steps/RunScriptCop.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ $importedModule |
Out-Host

foreach ($issue in $scriptCopIssues) {
Write-GitWarning -Message "$($issue.ItemWithProblem): $($issue.Problem)"
Write-GitHubWarning -Message "$($issue.ItemWithProblem): $($issue.Problem)"
}
81 changes: 81 additions & 0 deletions GitHub/Steps/TagModuleVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
param(
[string]
$ModulePath,

# The user email associated with a git commit.
[string]
$UserEmail,

# The user name associated with a git commit.
[string]
$UserName,

# The tag version format (default value: 'v$(imported.Version)')
# This can expand variables. $imported will contain the imported module.
[string]
$TagVersionFormat = 'v$($imported.Version)',

# The tag version format (default value: '$($imported.Name) $(imported.Version)')
# This can expand variables. $imported will contain the imported module.
[string]
$TagAnnotationFormat = '$($imported.Name) $($imported.Version)'
)


$gitHubEvent = if ($env:GITHUB_EVENT_PATH) {
[IO.File]::ReadAllText($env:GITHUB_EVENT_PATH) | ConvertFrom-Json
} else { $null }


@"
::group::GitHubEvent
$($gitHubEvent | 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" | Out-Host
return
}



$imported =
if (-not $ModulePath) {
$orgName, $moduleName = $env:GITHUB_REPOSITORY -split "/"
Import-Module ".\$moduleName.psd1" -Force -PassThru -Global
} else {
Import-Module $modulePath -Force -PassThru -Global
}

if (-not $imported) { return }

$targetVersion =$ExecutionContext.InvokeCommand.ExpandString($TagVersionFormat)
$existingTags = git tag --list

@"
Target Version: $targetVersion

Existing Tags:
$($existingTags -join [Environment]::NewLine)
"@ | Out-Host

$versionTagExists = $existingTags | Where-Object { $_ -match $targetVersion }

if ($versionTagExists) {
"::warning::Version $($versionTagExists)"
return
}

if (-not $UserName) { $UserName = $env:GITHUB_ACTOR }
if (-not $UserEmail) { $UserEmail = "$UserName@github.com" }
git config --global user.email $UserEmail
git config --global user.name $UserName

git tag -a $targetVersion -m $ExecutionContext.InvokeCommand.ExpandString($TagAnnotationFormat)
git push origin --tags

if ($env:GITHUB_ACTOR) {
exit 0
}
4 changes: 3 additions & 1 deletion New-GitHubWorkflow.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function New-GitHubWorkflow {
$workflowOptions = @{}
$expandGitHubBuildStep = @{
BuildSystem = $mynoun
SingleItemName = 'On','Name'
SingleItemName = 'Name','On'
DictionaryItemName = 'Jobs', 'Inputs','Outputs'
BuildOption = $workflowOptions
}
Expand Down Expand Up @@ -133,6 +133,8 @@ function New-GitHubWorkflow {

#endregion Map Dynamic Input

if ($RootDirectory) { $workflowOptions.RootDirectory = $RootDirectory}

#region Expand Input
$expandSplat = @{} + $PSBoundParameters
foreach ($k in @($expandSplat.Keys)) {
Expand Down