Skip to content

Commit

Permalink
Merge pull request #52 from deadlydog/FixUpVersioningWithAction
Browse files Browse the repository at this point in the history
Fix up versioning with action
  • Loading branch information
deadlydog authored Mar 16, 2024
2 parents d0b2ee4 + e3a88bd commit e6b9d45
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions .github/workflows/build-and-test-powershell-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,34 @@ jobs:
with:
versionSpec: '5.x'

- name: Determine the new version
- name: Get git metadata used for new version number
id: git-version
uses: gittools/actions/gitversion/execute@v0

- name: Determine the new version number
shell: pwsh
run: |
[string] $newVersionNumber = '${{ steps.git-version.outputs.majorMinorPatch }}'
[string] $prereleaseLabel = '${{ steps.git-version.outputs.preReleaseTag }}'
[string] $manuallyProvidedVersionNumber = '${{ inputs.versionNumber }}'
if (-not [string]::IsNullOrWhiteSpace($manuallyProvidedVersionNumber)) {
Write-Output "Using manually provided version number '$manuallyProvidedVersionNumber'."
$newVersionNumber = $manuallyProvidedVersionNumber
}
# The preReleaseTag is empty when building the default branch, so manually create a prerelease version number if needed.
if ([string]::IsNullOrWhiteSpace($prereleaseLabel)) {
[string] $dateTime = (Get-Date -Format 'yyyyMMddTHHmmss')
$prereleaseLabel = 'ci' + $dateTime + 'SHA' + '${{ steps.git-version.outputs.shortSha }}'
}
# PowerShell prerelease labels can only contain the characters 'a-zA-Z0-9', so sanitize it if needed.
$newVersionNumberPrereleaseLabel = $prereleaseLabel -replace '[^a-zA-Z0-9]', ''
Write-Output "Setting new environment variables 'NewVersionNumberMajorMinorPatch=$newVersionNumber' and 'NewVersionNumberPrereleaseLabel=$newVersionNumberPrereleaseLabel'."
"NewVersionNumberMajorMinorPatch=$newVersionNumber" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"NewVersionNumberPrereleaseLabel=$newVersionNumberPrereleaseLabel" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Create Stable and Prerelease module artifacts
shell: pwsh
run: |
Expand All @@ -145,11 +169,8 @@ jobs:
[string] $moduleManifestFileName = $moduleName + '.psd1'
[string] $prereleaseArtifactModuleDirectoryPath = Join-Path -Path $Env:prereleaseModuleArtifactDirectoryPath -ChildPath $moduleName
[string] $stableArtifactModuleDirectoryPath = Join-Path -Path $Env:stableModuleArtifactDirectoryPath -ChildPath $moduleName
Write-Output "Getting version numbers to use."
[string] $newVersionNumber = '${{ steps.git-version.outputs.majorMinorPatch }}'
# Prerelease version numbers can only contain 'a-zA-Z0-9' characters.
[string] $prereleaseVersionNumberPostfix = '${{ steps.git-version.outputs.preReleaseTag }}' -replace '[^a-zA-Z0-9]', ''
[string] $newVersionNumber = $Env:NewVersionNumberMajorMinorPatch
[string] $newVersionNumberPrereleaseLabel = $Env:NewVersionNumberPrereleaseLabel
Write-Output "Copying the module files to the Prerelease artifact directory '$prereleaseArtifactModuleDirectoryPath'."
Copy-Item -Path $moduleDirectoryPath -Destination $prereleaseArtifactModuleDirectoryPath -Exclude '*.Tests.ps1' -Recurse -Force
Expand All @@ -162,8 +183,8 @@ jobs:
[string] $prereleaseManifestFilePath = Join-Path -Path $prereleaseArtifactModuleDirectoryPath -ChildPath $moduleManifestFileName
[string] $stableManifestFilePath = Join-Path -Path $stableArtifactModuleDirectoryPath -ChildPath $moduleManifestFileName
Write-Output "Updating the prerelease manifest's version number to '$newVersionNumber-$prereleaseVersionNumberPostfix'."
Update-ModuleManifest -Path $prereleaseManifestFilePath -ModuleVersion $newVersionNumber -Prerelease $prereleaseVersionNumberPostfix
Write-Output "Updating the prerelease manifest's version number to '$newVersionNumber-$newVersionNumberPrereleaseLabel'."
Update-ModuleManifest -Path $prereleaseManifestFilePath -ModuleVersion $newVersionNumber -Prerelease $newVersionNumberPrereleaseLabel
Write-Output "Updating the stable manifest's version number to '$newVersionNumber'."
Update-ModuleManifest -Path $stableManifestFilePath -ModuleVersion $newVersionNumber
Expand All @@ -188,7 +209,7 @@ jobs:
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
shell: pwsh
run: |
[string] $newVersionNumber = '${{ steps.git-version.outputs.majorMinorPatch }}'
[string] $newVersionNumber = $Env:NewVersionNumberMajorMinorPatch
[string] $newVersionTag = "v$newVersionNumber"
# To avoid a 403 error on 'git push', ensure you have granted your GitHub Actions workflow read/write permission.
Expand Down

0 comments on commit e6b9d45

Please sign in to comment.