-
Notifications
You must be signed in to change notification settings - Fork 2
206 lines (189 loc) · 8.09 KB
/
ModuleBuildTestRelease.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: Module Build, Test and Release
on:
push:
branches:
- main
paths-ignore:
- CHANGELOG.md
- README.md
tags:
- v*
#tags-ignore:
#- '*-*'
pull_request:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
env:
buildFolderName: output
buildArtifactName: output
testResultFolderName: testResults
defaultBranch: main
Agent.Source.Git.ShallowFetchDepth: 0
jobs:
Build_Stage_Package_Module:
name: Package Module
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Calculate ModuleVersion (GitVersion)
id: GitVersion
run: |
$m365dscModule = Find-Module -Name Microsoft365DSC
$m365dscCRModule = Find-Module -Name M365DSC.CompositeResources -ErrorAction SilentlyContinue
$m365dscCRGModule = Find-Module -Name M365DSC.CRG
[Version]$m365dscVersion = $m365dscModule.Version
$m365dscVersionRevision = $m365dscVersion.Revision.ToString()
$m365dscVersion = [Version]::new($m365dscVersion.Major, $m365dscVersion.Minor, $m365dscVersion.Build, 0)
if ($null -ne $m365dscCRModule)
{
[Version]$m365dscCRVersion = $m365dscCRModule.Version
$m365dscCRVersionRevision = $m365dscCRVersion.Revision.ToString()
$m365dscCRVersion = [Version]::new($m365dscCRVersion.Major, $m365dscCRVersion.Minor, $m365dscCRVersion.Build, 0)
}
else
{
$m365dscCRVersion = [Version]'0.0.0.0'
$m365dscCRModule = @{ Version = $m365dscCRVersion }
}
if (($m365dscVersion -gt $m365dscCRVersion) -or `
($m365dscCRVersion -eq $m365dscCRVersion -and $m365dscVersionRevision -ne $m365dscCRVersionRevision[0]))
{
Write-Output "Version of Microsoft365DSC is newer than M365DSC.CompositeResources."
Write-Output " "
Write-Output "Versions:"
Write-Output "Microsoft365DSC : v$($m365dscModule.Version)"
Write-Output "M365DSC.CompositeResources: v$($m365dscCRModule.Version)"
Write-Output " "
$newVersion = "{0}00" -f $m365dscModule.Version
Write-Output "New M365DSC.CompositeResources version: v$($newVersion.ToString())"
Write-Output " "
Write-Output "Installing Microsoft365DSC and generating new module:"
Install-Module Microsoft365DSC -Confirm:$false -Force
Write-Output "ModuleVersion=$($newVersion.ToString())" >> $env:GITHUB_OUTPUT
}
else
{
Write-Output "Version of Microsoft365DSC is older than or the same as M365DSC.CompositeResources."
Write-Output " "
Write-Output "Versions:"
Write-Output "Microsoft365DSC : v$($m365dscModule.Version)"
Write-Output "M365DSC.CompositeResources: v$($m365dscCRModule.Version)"
Write-Output " "
if ($m365dscCRGModule.PublishedDate -gt $m365dscCRModule.PublishedDate)
{
Write-Output "PublishedDate of module M365DSC.CRG is newer than M365DSC.CompositeResources."
Write-Output " "
Write-Output "PublishedDates:"
Write-Output "M365DSC.CRG : $("{0:yyyy}-{0:MM}-{0:dd} {0:HH}:{0:mm}:{0:ss}" -f $m365dscCRGModule.PublishedDate)"
Write-Output "M365DSC.CompositeResources: $("{0:yyyy}-{0:MM}-{0:dd} {0:HH}:{0:mm}:{0:ss}" -f $m365dscCRModule.PublishedDate)"
Write-Output " "
$oldVersion = [Version]$m365dscCRModule.Version
$newVersion = [Version]::new($oldVersion.Major,$oldVersion.Minor,$oldVersion.Build,$oldVersion.Revision + 1)
Write-Output "New M365DSC.CompositeResources version: v$($newVersion.ToString())"
Write-Output " "
Write-Output "Installing Microsoft365DSC and generating new module."
Install-Module Microsoft365DSC -Confirm:$false -Force
Write-Output "ModuleVersion=$($newVersion.ToString())" >> $env:GITHUB_OUTPUT
}
else
{
Write-Output "No new version of Microsoft365DSC found. Skipping build."
Write-Output "SkipWorkflow=true" >> $env:GITHUB_OUTPUT
}
}
shell: powershell
- name: Build & Package Module
if: steps.GitVersion.outputs.SkipWorkflow != 'true'
shell: powershell
run: |
./build.ps1 -ResolveDependency -Tasks Build # Pack' -> Changed from Pack to Build. Pack does not work with nested required modules.
<# Commenting out because of issues with publishing. DscBuildHelpers module is required.
$module = Get-Module M365DSC.CompositeResources -ListAvailable
$OutputDirectory = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'output'
Write-Output "Registring Output repository: $OutputDirectory"
$RepositoryParams = @{
Name = 'output'
SourceLocation = $OutputDirectory
PublishLocation = $OutputDirectory
ErrorAction = 'Stop'
}
$null = Register-PSRepository @RepositoryParams
Write-Output "Publishing module to output repository: $($module.ModuleBase)"
$PublishModuleParams = @{
Path = $module.ModuleBase
Repository = 'output'
ErrorAction = 'Stop'
Force = $true
}
Publish-Module @PublishModuleParams
Write-Output "Removing Output repository"
$null = Unregister-PSRepository -Name output -ErrorAction SilentlyContinue
#>
env:
ModuleVersion: ${{ steps.GitVersion.outputs.ModuleVersion }}
- name: Publish Build Artifact
if: steps.GitVersion.outputs.SkipWorkflow != 'true'
uses: actions/upload-artifact@v3
with:
name: ${{ env.buildArtifactName }}
path: ${{ env.buildFolderName }}/
outputs:
ModuleVersion: ${{ steps.GitVersion.outputs.ModuleVersion }}
SkipWorkflow: ${{ steps.GitVersion.outputs.SkipWorkflow }}
Test_Stage_test_windows_ps:
name: Windows (Windows PowerShell)
runs-on: windows-latest
needs:
- Build_Stage_Package_Module
if: needs.Build_Stage_Package_Module.outputs.SkipWorkflow != 'true'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download Build Artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.buildArtifactName }}
path: ${{ env.buildFolderName }}/
- name: Run Tests
shell: powershell
run: |
Install-Module Microsoft365DSC -Confirm:$false -Force
./build.ps1 -Tasks Test
env:
ModuleVersion: ${{ needs.Build_Stage_Package_Module.outputs.ModuleVersion }}
- name: Publish Test Artifact
uses: actions/upload-artifact@v3
with:
path: ${{ env.buildFolderName }}/${{ env.testResultFolderName }}/
name: CodeCoverageWinPS51
Deploy_Stage_Deploy_Module:
name: Deploy Module
runs-on: ubuntu-latest
needs:
- Build_Stage_Package_Module
- Test_Stage_test_windows_ps
if: (success() && ((github.ref == 'refs/heads/main') || startsWith(github.ref, 'refs/tags/')) && (contains(github.repository_owner, 'ykuijs')))
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download Build Artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.buildArtifactName }}
path: ${{ env.buildFolderName }}/
- name: Publish Release
shell: pwsh
run: |
Install-Module Microsoft365DSC -Confirm:$false -Force
./build.ps1 -Tasks Publish
env:
GitHubToken: ${{ secrets.GITHUB_TOKEN }}
GalleryApiToken: ${{ secrets.GalleryApiToken }}
ReleaseBranch: ${{ env.defaultBranch }}
MainGitBranch: ${{ env.defaultBranch }}
ModuleVersion: ${{ needs.Build_Stage_Package_Module.outputs.ModuleVersion }}