Skip to content

Commit

Permalink
Merge pull request #122 from StartAutomating/GitHubWorkFlowImprovments
Browse files Browse the repository at this point in the history
GitHub Workflow Improvements
  • Loading branch information
StartAutomating authored Sep 28, 2021
2 parents 54a5cfb + 2d018d3 commit 6390480
Show file tree
Hide file tree
Showing 10 changed files with 630 additions and 109 deletions.
485 changes: 485 additions & 0 deletions .github/workflows/TestAndPublish.yml

Large diffs are not rendered by default.

92 changes: 0 additions & 92 deletions .github/workflows/UpdateModuleTag.yml

This file was deleted.

11 changes: 11 additions & 0 deletions GitHub/Jobs/ReleaseModule.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'
}, 'ReleaseModule'
)
}

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



2 changes: 1 addition & 1 deletion GitHub/Steps/PublishPowerShellGallery.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $($gitHubEvent | ConvertTo-Json -Depth 100)

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
"::warning::Pull Request has not merged, skipping Gallery Publish" | Out-Host
return
}

Expand Down
87 changes: 87 additions & 0 deletions GitHub/Steps/ReleaseModule.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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)'
)


$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 GitHub release" | 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)
$targetReleaseName = $targetVersion
$releasesURL = 'https://api.github.com/repos/${{github.repository}}/releases'
"Release URL: $releasesURL" | Out-Host
$listOfReleases = Invoke-RestMethod -Uri $releasesURL -Method Get -Headers @{
"Accept" = "application/vnd.github.v3+json"
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
}

$releaseExists = $listOfReleases | Where-Object tag_name -eq $targetVersion

if ($releaseExists) {
"::warning::Release '$($releaseExists.Name )' Already Exists" | Out-Host
return
}


Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
[Ordered]@{
owner = '${{github.owner}}'
repo = '${{github.repository}}'
tag_name = $targetVersion
name = "$($imported.Name) $targetVersion"
body =
if ($env:RELEASENOTES) {
$env:RELEASENOTES
} elseif ($imported.PrivateData.PSData.ReleaseNotes) {
$imported.PrivateData.PSData.ReleaseNotes
} else {
"$($imported.Name) $targetVersion"
}
draft = if ($env:RELEASEISDRAFT) { [bool]::Parse($env:RELEASEISDRAFT) } else { $false }
prerelease = if ($env:PRERELEASE) { [bool]::Parse($env:PRERELEASE) } else { $false }
} | ConvertTo-Json
) -Headers @{
"Accept" = "application/vnd.github.v3+json"
"Content-type" = "application/json"
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
}
17 changes: 14 additions & 3 deletions GitHub/Steps/RunPester.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ param(
$ModulePath,
# The Pester max version. By default, this is pinned to 4.99.99.
[string]
$PesterMaxVersion = '4.99.99'
$PesterMaxVersion = '4.99.99',

# If set, will not collect code coverage.
[switch]
$NoCoverage
)

$global:ErrorActionPreference = 'continue'
Expand All @@ -22,11 +26,18 @@ $importedPester = Import-Module Pester -Force -PassThru -MaximumVersion $PesterM
$importedModule = Import-Module $ModulePath -Force -PassThru
$importedPester, $importedModule | Out-Host

$codeCoverageParameters = @{
CodeCoverage = "$($importedModule | Split-Path)\*-*.ps1"
CodeCoverageOutputFile = ".\$moduleName.Coverage.xml"
}

if ($NoCoverage) {
$codeCoverageParameters = @{}
}


$result =
Invoke-Pester -PassThru -Verbose -OutputFile ".\$moduleName.TestResults.xml" -OutputFormat NUnitXml `
-CodeCoverage "$($importedModule | Split-Path)\*-*.ps1" -CodeCoverageOutputFile ".\$moduleName.Coverage.xml"
Invoke-Pester -PassThru -Verbose -OutputFile ".\$moduleName.TestResults.xml" -OutputFormat NUnitXml @codeCoverageParameters

"::set-output name=TotalCount::$($result.TotalCount)",
"::set-output name=PassedCount::$($result.PassedCount)",
Expand Down
2 changes: 1 addition & 1 deletion GitHub/Steps/TagModuleVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $($gitHubEvent | ConvertTo-Json -Depth 100)

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
"::warning::Pull Request has not merged, skipping Tagging" | Out-Host
return
}

Expand Down
6 changes: 6 additions & 0 deletions PSDevOps.GitHubWorkflow.psdevops.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#requires -Module PSDevOps
New-GitHubWorkflow -Name "Analyze, Test, Tag, and Publish" -On Push, PullRequest, Demand -Job PowerShellStaticAnalysis, TestPowerShellOnLinux, TagReleaseAndPublish -Environment @{
SYSTEM_ACCESSTOKEN = '${{ secrets.AZUREDEVOPSPAT }}'
NoCoverage = $true
}|
Set-Content .\.github\workflows\TestAndPublish.yml -Encoding UTF8 -PassThru
24 changes: 12 additions & 12 deletions PSDevOps.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{
ModuleVersion = '0.5.4.2'
ModuleVersion = '0.5.5'
RootModule = 'PSDevOps.psm1'
Description = 'PowerShell Tools for DevOps'
Guid = 'e6b56c5f-41ac-4ba4-8b88-2c063f683176'
Expand All @@ -9,6 +9,17 @@
ProjectURI = 'https://github.com/StartAutomating/PSDevOps'
LicenseURI = 'https://github.com/StartAutomating/PSDevOps/blob/master/LICENSE'
ReleaseNotes = @'
0.5.5:
---
* Azure DevOps: Adding support for Shared Queries (Fixes #117)
** Get-ADOWorkItem -SharedQuery can get shared queries
** New-ADOWorkItem -WIQL will create shared queries. -FolderName will create folders.
** Remove-ADOWorkItem -QueryID can remove a shared query by ID
* GitHub Workflows:
** Adding Job/Step definitions to Release Module
** Adding -NoCoverage to RunPester Step
** Creating Example workflow that publishes PSDevOps.
0.5.4.2:
---
* Adding Register-ADOArtifactFeed (Fixes #118)
Expand Down Expand Up @@ -94,17 +105,6 @@
** PSDevOps now includes a file to generate it's own build
** PublishTest/CodeCoverage Results steps will always() run
** Convert-BuildStep will add a .Name to each script step.
0.4.8
---
* Improved Tracing
** New Commands: Write-ADOOutput, Trace-ADOCommand/GitHubCommand
** Renaming Command / Adding Parameters: Set-ADOVariable -> Write-ADOVariable. Added -IsOutput & -IsReadOnly.
** Adding Trace-GitHubCommand/ADOCommand
** Improved logging of parameters in Convert-BuildStep
* New Functionality in Azure DevOps:
** Get-ADOProject now has -TestRun, -TestPlan, -Release, and -PendingApproval (and better progress bars)
** Get-ADOWorkItemType now has -Field
** Commands for Picklists: Add/Get/Remove/Update-ADOPicklist
'@
}
Colors = @{
Expand Down

0 comments on commit 6390480

Please sign in to comment.