Skip to content

Commit

Permalink
refactor: Have deploy grab the module name dynamically instead of har…
Browse files Browse the repository at this point in the history
…dcoding it in multiple places
  • Loading branch information
deadlydog committed Oct 22, 2023
1 parent c14ce5f commit 353fdd7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build-and-test-powershell-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ on:
type: string
default: ''
outputs:
powerShellModuleName:
description: 'The name of the PowerShell module being built.'
value: ${{ jobs.build-and-test.outputs.powerShellModuleName }}
prereleaseModuleArtifactName:
description: 'The name of the prerelease module artifact created by the build.'
value: ${{ jobs.build-and-test.outputs.prereleaseModuleArtifactName }}
Expand All @@ -26,7 +29,7 @@ on:
value: ${{ jobs.build-and-test.outputs.deployFilesArtifactName }}

env:
powerShellModuleName: 'tiPS' # Must match the name in the deployment workflow.
powerShellModuleName: 'tiPS'
powerShellModuleDirectoryPath: './src/tiPS'
powerShellModuleManifestFileName: 'tiPS.psd1'
deployFilesDirectoryPath: './deploy'
Expand All @@ -42,6 +45,7 @@ jobs:
build-and-test:
runs-on: windows-latest # Use Windows agent to ensure dotnet.exe is available to build C# assemblies.
outputs:
powerShellModuleName: ${{ env.powerShellModuleName }}
prereleaseModuleArtifactName: ${{ env.prereleaseModuleArtifactName }}
stableModuleArtifactName: ${{ env.stableModuleArtifactName }}
deployFilesArtifactName: ${{ env.deployFilesArtifactName }}
Expand Down
25 changes: 12 additions & 13 deletions .github/workflows/build-test-and-deploy-powershell-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ on:
default: ''

env:
powerShellModuleName: 'tiPS' # Must match the name in the build workflow.
artifactsDirectoryPath: './artifacts'

jobs:
Expand All @@ -39,14 +38,14 @@ jobs:
- name: Publish prerelease PowerShell module
shell: pwsh
run: |
[string] $moduleDirectoryPath = "$Env:artifactsDirectoryPath/$Env:powerShellModuleName"
[string] $moduleDirectoryPath = "$Env:artifactsDirectoryPath/${{ needs.run-build-and-test.outputs.powerShellModuleName }}"
Publish-Module -Path $moduleDirectoryPath -NuGetApiKey '${{ secrets.POWERSHELL_GALLERY_API_KEY }}' -Verbose
- name: Make prerelease version number available to downstream jobs
id: output-version-number
shell: pwsh
run: |
[string] $moduleManifestPath = "$Env:artifactsDirectoryPath/$Env:powerShellModuleName/$Env:powerShellModuleName.psd1"
[string] $moduleManifestPath = "$Env:artifactsDirectoryPath/${{ needs.run-build-and-test.outputs.powerShellModuleName }}.psd1"
Write-Output "Reading module manifest from '$moduleManifestPath'."
[hashtable] $manifest = Get-Content -Path $moduleManifestPath -Raw | Invoke-Expression
[string] $versionNumber = $manifest.ModuleVersion
Expand Down Expand Up @@ -74,7 +73,7 @@ jobs:
- name: Install prerelease module from PowerShell Gallery
shell: pwsh
run: |
[string] $moduleName = $Env:powerShellModuleName
[string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
[string] $prereleaseVersionNumber = '${{ needs.publish-prerelease-module.outputs.prereleaseVersionNumber }}'
Write-Output "Installing the module '$moduleName' prerelease version '$prereleaseVersionNumber' from the PowerShell Gallery."
Expand Down Expand Up @@ -102,7 +101,7 @@ jobs:
Invoke-Pester -Configuration $pesterConfig
Write-Output "Displaying the installed module version that was used for the smoke tests."
Get-Module -Name $Env:powerShellModuleName
Get-Module -Name '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
test-prerelease-module-in-windows-powershell:
needs: publish-prerelease-module
Expand All @@ -115,7 +114,7 @@ jobs:
- name: Install prerelease module from PowerShell Gallery
shell: powershell
run: |
[string] $moduleName = $Env:powerShellModuleName
[string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
[string] $prereleaseVersionNumber = '${{ needs.publish-prerelease-module.outputs.prereleaseVersionNumber }}'
Write-Output "Installing the module '$moduleName' prerelease version '$prereleaseVersionNumber' from the PowerShell Gallery."
Expand Down Expand Up @@ -143,7 +142,7 @@ jobs:
Invoke-Pester -Configuration $pesterConfig
Write-Output "Displaying the installed module version that was used for the smoke tests."
Get-Module -Name $Env:powerShellModuleName
Get-Module -Name '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
publish-stable-module:
needs: [test-prerelease-module-in-pwsh, test-prerelease-module-in-windows-powershell]
Expand All @@ -161,14 +160,14 @@ jobs:
- name: Publish stable PowerShell module
shell: pwsh
run: |
[string] $moduleDirectoryPath = "$Env:artifactsDirectoryPath/$Env:powerShellModuleName"
[string] $moduleDirectoryPath = "$Env:artifactsDirectoryPath/${{ needs.run-build-and-test.outputs.powerShellModuleName }}"
Publish-Module -Path $moduleDirectoryPath -NuGetApiKey '${{ secrets.POWERSHELL_GALLERY_API_KEY }}' -Verbose
- name: Make stable version number available to downstream jobs
id: output-version-number
shell: pwsh
run: |
[string] $moduleManifestPath = "$Env:artifactsDirectoryPath/$Env:powerShellModuleName/$Env:powerShellModuleName.psd1"
[string] $moduleManifestPath = "$Env:artifactsDirectoryPath/${{ needs.run-build-and-test.outputs.powerShellModuleName }}/${{ needs.run-build-and-test.outputs.powerShellModuleName }}.psd1"
Write-Output "Reading module manifest from '$moduleManifestPath'."
[hashtable] $manifest = Get-Content -Path $moduleManifestPath -Raw | Invoke-Expression
[string] $versionNumber = $manifest.ModuleVersion
Expand All @@ -194,7 +193,7 @@ jobs:
- name: Install stable module from PowerShell Gallery
shell: pwsh
run: |
[string] $moduleName = $Env:powerShellModuleName
[string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
[string] $stableVersionNumber = '${{ needs.publish-stable-module.outputs.stableVersionNumber }}'
Write-Output "Installing the module '$moduleName' stable version '$stableVersionNumber' from the PowerShell Gallery."
Expand Down Expand Up @@ -222,7 +221,7 @@ jobs:
Invoke-Pester -Configuration $pesterConfig
Write-Output "Displaying the installed module version that was used for the smoke tests."
Get-Module -Name $Env:powerShellModuleName
Get-Module -Name '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
test-stable-module-in-windows-powershell:
needs: publish-stable-module
Expand All @@ -235,7 +234,7 @@ jobs:
- name: Install stable module from PowerShell Gallery
shell: powershell
run: |
[string] $moduleName = $Env:powerShellModuleName
[string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
[string] $stableVersionNumber = '${{ needs.publish-stable-module.outputs.stableVersionNumber }}'
Write-Output "Installing the module '$moduleName' stable version '$stableVersionNumber' from the PowerShell Gallery."
Expand Down Expand Up @@ -263,4 +262,4 @@ jobs:
Invoke-Pester -Configuration $pesterConfig
Write-Output "Displaying the installed module version that was used for the smoke tests."
Get-Module -Name $Env:powerShellModuleName
Get-Module -Name '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'

0 comments on commit 353fdd7

Please sign in to comment.