Skip to content

Commit 6390480

Browse files
Merge pull request #122 from StartAutomating/GitHubWorkFlowImprovments
GitHub Workflow Improvements
2 parents 54a5cfb + 2d018d3 commit 6390480

File tree

10 files changed

+630
-109
lines changed

10 files changed

+630
-109
lines changed

.github/workflows/TestAndPublish.yml

Lines changed: 485 additions & 0 deletions
Large diffs are not rendered by default.

.github/workflows/UpdateModuleTag.yml

Lines changed: 0 additions & 92 deletions
This file was deleted.

GitHub/Jobs/ReleaseModule.psd1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@{
2+
"runs-on" = "ubuntu-latest"
3+
if = '${{ success() }}'
4+
steps = @(
5+
@{
6+
name = 'Check out repository'
7+
uses = 'actions/checkout@v2'
8+
}, 'ReleaseModule'
9+
)
10+
}
11+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@{
2+
"runs-on" = "ubuntu-latest"
3+
if = '${{ success() }}'
4+
steps = @(
5+
@{
6+
name = 'Check out repository'
7+
uses = 'actions/checkout@v2'
8+
}, 'TagModuleVersion','ReleaseModule','PublishPowerShellGallery'
9+
)
10+
}
11+
12+
13+

GitHub/Steps/PublishPowerShellGallery.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $($gitHubEvent | ConvertTo-Json -Depth 100)
1515

1616
if (-not ($gitHubEvent.head_commit.message -match "Merge Pull Request #(?<PRNumber>\d+)") -and
1717
(-not $gitHubEvent.psobject.properties['inputs'])) {
18-
"::warning::Pull Request has not merged, skipping" | Out-Host
18+
"::warning::Pull Request has not merged, skipping Gallery Publish" | Out-Host
1919
return
2020
}
2121

GitHub/Steps/ReleaseModule.ps1

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
param(
2+
[string]
3+
$ModulePath,
4+
5+
# The user email associated with a git commit.
6+
[string]
7+
$UserEmail,
8+
9+
# The user name associated with a git commit.
10+
[string]
11+
$UserName,
12+
13+
# The tag version format (default value: 'v$(imported.Version)')
14+
# This can expand variables. $imported will contain the imported module.
15+
[string]
16+
$TagVersionFormat = 'v$($imported.Version)'
17+
)
18+
19+
20+
$gitHubEvent = if ($env:GITHUB_EVENT_PATH) {
21+
[IO.File]::ReadAllText($env:GITHUB_EVENT_PATH) | ConvertFrom-Json
22+
} else { $null }
23+
24+
25+
@"
26+
::group::GitHubEvent
27+
$($gitHubEvent | ConvertTo-Json -Depth 100)
28+
::endgroup::
29+
"@ | Out-Host
30+
31+
if (-not ($gitHubEvent.head_commit.message -match "Merge Pull Request #(?<PRNumber>\d+)") -and
32+
(-not $gitHubEvent.psobject.properties['inputs'])) {
33+
"::warning::Pull Request has not merged, skipping GitHub release" | Out-Host
34+
return
35+
}
36+
37+
38+
39+
$imported =
40+
if (-not $ModulePath) {
41+
$orgName, $moduleName = $env:GITHUB_REPOSITORY -split "/"
42+
Import-Module ".\$moduleName.psd1" -Force -PassThru -Global
43+
} else {
44+
Import-Module $modulePath -Force -PassThru -Global
45+
}
46+
47+
if (-not $imported) { return }
48+
49+
$targetVersion =$ExecutionContext.InvokeCommand.ExpandString($TagVersionFormat)
50+
$targetReleaseName = $targetVersion
51+
$releasesURL = 'https://api.github.com/repos/${{github.repository}}/releases'
52+
"Release URL: $releasesURL" | Out-Host
53+
$listOfReleases = Invoke-RestMethod -Uri $releasesURL -Method Get -Headers @{
54+
"Accept" = "application/vnd.github.v3+json"
55+
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
56+
}
57+
58+
$releaseExists = $listOfReleases | Where-Object tag_name -eq $targetVersion
59+
60+
if ($releaseExists) {
61+
"::warning::Release '$($releaseExists.Name )' Already Exists" | Out-Host
62+
return
63+
}
64+
65+
66+
Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
67+
[Ordered]@{
68+
owner = '${{github.owner}}'
69+
repo = '${{github.repository}}'
70+
tag_name = $targetVersion
71+
name = "$($imported.Name) $targetVersion"
72+
body =
73+
if ($env:RELEASENOTES) {
74+
$env:RELEASENOTES
75+
} elseif ($imported.PrivateData.PSData.ReleaseNotes) {
76+
$imported.PrivateData.PSData.ReleaseNotes
77+
} else {
78+
"$($imported.Name) $targetVersion"
79+
}
80+
draft = if ($env:RELEASEISDRAFT) { [bool]::Parse($env:RELEASEISDRAFT) } else { $false }
81+
prerelease = if ($env:PRERELEASE) { [bool]::Parse($env:PRERELEASE) } else { $false }
82+
} | ConvertTo-Json
83+
) -Headers @{
84+
"Accept" = "application/vnd.github.v3+json"
85+
"Content-type" = "application/json"
86+
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
87+
}

GitHub/Steps/RunPester.ps1

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ param(
1010
$ModulePath,
1111
# The Pester max version. By default, this is pinned to 4.99.99.
1212
[string]
13-
$PesterMaxVersion = '4.99.99'
13+
$PesterMaxVersion = '4.99.99',
14+
15+
# If set, will not collect code coverage.
16+
[switch]
17+
$NoCoverage
1418
)
1519

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

29+
$codeCoverageParameters = @{
30+
CodeCoverage = "$($importedModule | Split-Path)\*-*.ps1"
31+
CodeCoverageOutputFile = ".\$moduleName.Coverage.xml"
32+
}
33+
34+
if ($NoCoverage) {
35+
$codeCoverageParameters = @{}
36+
}
2537

2638

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

3142
"::set-output name=TotalCount::$($result.TotalCount)",
3243
"::set-output name=PassedCount::$($result.PassedCount)",

GitHub/Steps/TagModuleVersion.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ $($gitHubEvent | ConvertTo-Json -Depth 100)
3535

3636
if (-not ($gitHubEvent.head_commit.message -match "Merge Pull Request #(?<PRNumber>\d+)") -and
3737
(-not $gitHubEvent.psobject.properties['inputs'])) {
38-
"::warning::Pull Request has not merged, skipping" | Out-Host
38+
"::warning::Pull Request has not merged, skipping Tagging" | Out-Host
3939
return
4040
}
4141

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#requires -Module PSDevOps
2+
New-GitHubWorkflow -Name "Analyze, Test, Tag, and Publish" -On Push, PullRequest, Demand -Job PowerShellStaticAnalysis, TestPowerShellOnLinux, TagReleaseAndPublish -Environment @{
3+
SYSTEM_ACCESSTOKEN = '${{ secrets.AZUREDEVOPSPAT }}'
4+
NoCoverage = $true
5+
}|
6+
Set-Content .\.github\workflows\TestAndPublish.yml -Encoding UTF8 -PassThru

PSDevOps.psd1

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@{
2-
ModuleVersion = '0.5.4.2'
2+
ModuleVersion = '0.5.5'
33
RootModule = 'PSDevOps.psm1'
44
Description = 'PowerShell Tools for DevOps'
55
Guid = 'e6b56c5f-41ac-4ba4-8b88-2c063f683176'
@@ -9,6 +9,17 @@
99
ProjectURI = 'https://github.com/StartAutomating/PSDevOps'
1010
LicenseURI = 'https://github.com/StartAutomating/PSDevOps/blob/master/LICENSE'
1111
ReleaseNotes = @'
12+
0.5.5:
13+
---
14+
* Azure DevOps: Adding support for Shared Queries (Fixes #117)
15+
** Get-ADOWorkItem -SharedQuery can get shared queries
16+
** New-ADOWorkItem -WIQL will create shared queries. -FolderName will create folders.
17+
** Remove-ADOWorkItem -QueryID can remove a shared query by ID
18+
* GitHub Workflows:
19+
** Adding Job/Step definitions to Release Module
20+
** Adding -NoCoverage to RunPester Step
21+
** Creating Example workflow that publishes PSDevOps.
22+
1223
0.5.4.2:
1324
---
1425
* Adding Register-ADOArtifactFeed (Fixes #118)
@@ -94,17 +105,6 @@
94105
** PSDevOps now includes a file to generate it's own build
95106
** PublishTest/CodeCoverage Results steps will always() run
96107
** Convert-BuildStep will add a .Name to each script step.
97-
0.4.8
98-
---
99-
* Improved Tracing
100-
** New Commands: Write-ADOOutput, Trace-ADOCommand/GitHubCommand
101-
** Renaming Command / Adding Parameters: Set-ADOVariable -> Write-ADOVariable. Added -IsOutput & -IsReadOnly.
102-
** Adding Trace-GitHubCommand/ADOCommand
103-
** Improved logging of parameters in Convert-BuildStep
104-
* New Functionality in Azure DevOps:
105-
** Get-ADOProject now has -TestRun, -TestPlan, -Release, and -PendingApproval (and better progress bars)
106-
** Get-ADOWorkItemType now has -Field
107-
** Commands for Picklists: Add/Get/Remove/Update-ADOPicklist
108108
'@
109109
}
110110
Colors = @{

0 commit comments

Comments
 (0)