|
2 | 2 | # GraphicalTools includes two modules: Microsoft.PowerShell.GraphicalTools and Microsoft.PowerShell.ConsoleGuiTools |
3 | 3 | # To build them all leave -ModuleName off the `InvokeBuild` command (e.g. Invoke-Build Build). |
4 | 4 | # To build only one, specify it using the -ModuleName paramater (e.g. Invoke-Build Build -ModuleName Microsoft.PowerShell.ConsoleGuiTools). |
| 5 | +$ModuleName = "Microsoft.PowerShell.ConsoleGuiTools" |
| 6 | +$BuildPath = "$PSScriptRoot/module/$ModuleName" |
| 7 | +$PsdPath = "src/$ModuleName/$ModulePath/$($ModuleName).psd1" |
| 8 | + |
| 9 | +# Assume this is the first build |
| 10 | +$build = 0 |
| 11 | + |
| 12 | +$psd1Content = Get-Content $PsdPath -Raw -ErrorAction SilentlyContinue |
| 13 | +if ($psd1Content) { |
| 14 | + # Extract the ModuleVersion from the .psd1 content using regular expression |
| 15 | + if ($psd1Content -match "ModuleVersion\s+=\s+'(.*?)'") { |
| 16 | + $prevVersion = $Matches[1] |
| 17 | + $prevVersionParts = $prevVersion -split '\.' |
| 18 | + $build = [int]$prevVersionParts[3] + 1 |
| 19 | + $ModuleVersion = "{0}.{1}.{2}.{3}" -f $prevVersionParts[0], $prevVersionParts[1], $prevVersionParts[2], $build |
| 20 | + } |
| 21 | + else { |
| 22 | + "No previous version found. Assuming this is the first build." |
| 23 | + # Get the ModuleVersion using dotnet-gitversion |
| 24 | + $prevVersion = "1.0.0.0" |
| 25 | + $ModuleVersion = "$($prevVersion)" |
| 26 | + } |
| 27 | + "Rewriting $PsdPath with new ModuleVersion: $ModuleVersion" |
| 28 | + $updatedpsd1Content = $psd1Content -replace "ModuleVersion\s+=\s+'([\d\.]+)'", "ModuleVersion = '$ModuleVersion'" |
| 29 | + $updatedpsd1Content | Out-File -FilePath $PsdPath -Encoding ascii |
| 30 | +} |
| 31 | +else { |
| 32 | + throw "$PsdPath not found." |
| 33 | +} |
| 34 | + |
| 35 | +"Buildihg $ModuleName..." |
| 36 | +Invoke-Build Build -ModuleName $ModuleName |
| 37 | + |
| 38 | +# Publish to a local PSRepository to enable downstream dependenies to use development builds |
| 39 | +# - If `local` doesn't exist, create with `Register-PSRepository -Name local -SourceLocation "~/psrepo" -InstallationPolicy Trusted` |
| 40 | +$localRepository = Get-PSRepository | Where-Object { $_.Name -eq 'local' } |
| 41 | +if ($localRepository) { |
| 42 | + $localRepositoryPath = $localRepository | Select-Object -ExpandProperty SourceLocation |
| 43 | + # Un-publishing $ModuleName from local repository at $localRepositoryPath" |
| 44 | + Remove-Item "${localRepositoryPath}/${ModuleName}.{$ModuleVersion}.nupkg" -Recurse -Force -ErrorAction SilentlyContinue |
| 45 | + "Publishing ${localRepositoryPath}/${ModuleName}.$ModuleVersion.nupkg to `local'" |
| 46 | + Publish-Module -Path $BuildPath -Repository 'local' |
| 47 | +} |
5 | 48 |
|
6 | | -# Build... |
7 | | -Invoke-Build Build -ModuleName Microsoft.PowerShell.ConsoleGuiTools |
8 | 49 |
|
9 | 50 | # Run what was built as a bit of test of: |
10 | 51 | # - Scale: recursive ls of the project |
11 | 52 | # - Filter: proving regex works |
12 | 53 | # - SelectMultiple |
13 | | -pwsh -noprofile -command "Import-Module -verbose '$PSScriptRoot/module/Microsoft.PowerShell.ConsoleGuiTools'; Get-ChildItem -Recurse | Out-ConsoleGridView -OutputMode Multiple -Title 'Imported Modules' -Filter \.xml" |
| 54 | +$testCommand = "Get-ChildItem -Recurse | Out-ConsoleGridView -Debug -OutputMode Multiple -Title 'Imported Modules' -Filter \.xml" |
| 55 | +"Running test in new pwsh session: $testCommand" |
| 56 | +pwsh -noprofile -command "Import-Module -verbose $BuildPath; $testCommand" |
| 57 | +"Test exited. Build complete." |
0 commit comments