Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Version C# assemblies too #53

Merged
merged 2 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 34 additions & 34 deletions .github/workflows/build-and-test-powershell-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,42 @@ jobs:
shell: pwsh
run: $PSVersionTable

- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0
with:
versionSpec: '5.x'

- 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 = $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: Build the C# assemblies
shell: pwsh
run: ./build/Build-CSharpAssemblies.ps1 -Force
run: ./build/Build-CSharpAssemblies.ps1 -VersionNumber '${{ steps.git-version.outputs.assemblySemVer }}' -Force

- name: Generate PowerShellTips.json file
shell: pwsh
Expand Down Expand Up @@ -127,39 +160,6 @@ jobs:
}
Invoke-Pester -Configuration $pesterConfig

- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0
with:
versionSpec: '5.x'

- 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 Down
7 changes: 5 additions & 2 deletions build/Build-CSharpAssemblies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $false, HelpMessage = 'The version number to build the assemblies with, in the format "Major.Minor.Build.Revision". Default is "1.0.0.0".')]
[string] $VersionNumber = '1.0.0.0',

[Parameter(Mandatory = $false, HelpMessage = 'If specified, the module DLL files will be rebuilt even if they already exist. Otherwise, they will only be built if they do not exist.')]
[switch] $Force
)
Expand All @@ -29,8 +32,8 @@ if ($removeDllFilesError)
throw "Error deleting the DLL files in '$moduleClassesDirectoryPath'. They are likely in use by another process that imported tiPS. Try closing all PowerShell sessions and running the script again. Error: $removeDllFilesError"
}

Write-Output "Building C# sln '$csharpSlnFilePath' in Release mode."
& dotnet build "$csharpSlnFilePath" --configuration Release
Write-Output "Building C# sln '$csharpSlnFilePath' in Release mode with version number '$VersionNumber'."
& dotnet build "$csharpSlnFilePath" --configuration Release -p:Version=$VersionNumber

Write-Output "Copying the DLL files in '$csharpClassesDllDirectoryPath' to the module's Classes directory '$moduleClassesDirectoryPath'."
Copy-Item -Path "$csharpClassesDllDirectoryPath/*" -Destination $moduleClassesDirectoryPath -Include '*.dll' -Force
Loading