Skip to content

Commit

Permalink
build works
Browse files Browse the repository at this point in the history
  • Loading branch information
tig committed Nov 6, 2023
1 parent 9cab7ec commit 494ab28
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,20 @@ if ($null -eq $Version -or "" -eq $Version) {
$prevVersionParts = $prevVersion -split '\.'
$build = [int]$prevVersionParts[3] + 1
$Version = "{0}.{1}.{2}.{3}" -f $prevVersionParts[0], $prevVersionParts[1], $prevVersionParts[2], $build
"Extracted version number from $ModulePath/$ModuleName.psd1: $Version"
"Got version from $ModulePath/$ModuleName.psd1: $Version"
}
else {
throw "Version not found in $ModulePath/$ModuleName.psd1."
}
}
else {
"No previous version found. Assuming this is the first build."
"Getting the Verison using dotnet-gitversion..."
# No previous version found. Assuming this is the first build.
$prevVersion = dotnet-gitversion /showvariable MajorMinorPatch
$Version = "$($prevVersion).$($build)"
"Got version from dotnet-gitversion: $Version"
}
}

"Building Version: $Version"

# Ensure we're using the correct version of ConsoleGuiTools
# If there's a local repository, use the latest version from there and set the RequiredVersion in the .psd1 file
# If there's NOT a local repo, use the latest version from the PowerShell Gallery and set the ModuleVersion in the .psd1 file
Expand All @@ -49,28 +47,28 @@ if ($localRepository) {
$v = Get-ChildItem "${localRepositoryPath}/${ocgvModule}*.nupkg" | Select-Object -ExpandProperty Name | Sort-Object -Descending | Select-Object -First 1
if ($v -match "$ocgvModule.(.*?).nupkg") {
$v = [Version]::new($Matches[1])
"$ocgvModule v$v found in local repository"
" $ocgvModule v$v found in local repository"
}
}

if ($null -eq $ocgvVersion) {
$module = (Find-Module $ocgvModule) | Select-Object -ExpandProperty Version | Sort-Object -Descending | Select-Object -First 1
$v = [Version]::new($module)
"$ocgvModule v$v found in PSGallery"
" $ocgvModule v$v found in PSGallery"
}

$ocgvVersion = "$($v.Major).$($v.Minor).$($v.Build).$($v.Revision)"
"Installing $ocgvModule v$ocgvVersion to ensure it is loaded from the local repo."
" Installing $ocgvModule v$ocgvVersion to ensure it is loaded."
Install-Module $ocgvModule -MinimumVersion $ocgvVersion -Force -Verbose -SkipPublisherCheck
"Updating RequiredVersion for $ocgvModule v$ocgvVersion in $PsdPath"
" Updating RequiredVersion for $ocgvModule v$ocgvVersion in $PsdPath"
Update-ModuleManifest -RequiredModules @(
@{ModuleName = "PSReadline"; ModuleVersion = "2.1" },
@{ModuleName = $ocgvModule; ModuleVersion = $ocgvVersion }
) -Path $PsdPath -ErrorAction Stop

$OldModule = Get-Module $ModuleName -ErrorAction SilentlyContinue
if ($OldModule) {
"Removing $ModuleName $($OldModule.Version)"
"Removing and uninstalling old version: $ModuleName $($OldModule.Version)"
Remove-Item $ModulePath -Recurse -Force -ErrorAction SilentlyContinue
Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue
Remove-Module Microsoft.PowerShell.ConsoleGuiTools
Expand All @@ -80,14 +78,15 @@ if ($OldModule) {
$localRepository = Get-PSRepository | Where-Object { $_.Name -eq 'local' }
if ($localRepository) {
$localRepositoryPath = $localRepository | Select-Object -ExpandProperty SourceLocation
" Un-publishing $ModuleName $($OldModule.Version) from local repository at $localRepositoryPath"
"Un-publishing $ModuleName $($OldModule.Version) from local repository at $localRepositoryPath"
Remove-Item "${localRepositoryPath}/${ModuleName}*.nupkg" -Recurse -Force -ErrorAction SilentlyContinue
}

"Building $ModuleName $Version to $ModulePath"
Build-Module -SemVer $Version -OutputDirectory ".${ModulePath}" -SourcePath ./Source -ErrorAction Stop

if ($localRepository) {
"Local repository found; importing for testing..."
" Removing $ModuleName"
Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue
" Publishing $ModuleName to local repository at $localRepositoryPath"
Expand Down

0 comments on commit 494ab28

Please sign in to comment.