Module Build, Test and Release #376
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |