Skip to content

Commit

Permalink
refactor(design): ♻️ optimize nuget build script
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-s-betke committed May 6, 2023
1 parent f8ad06d commit 13614b1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/common.build.shared.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if ( -not ( Test-Path variable:RepoRootPath ) -or ( [System.String]::IsNullOrEmp
[System.String] $ToolsPath = ( Join-Path -Path $RepoRootPath -ChildPath 'tools' -Resolve );

[System.String] $NuGetToolsPath = ( Join-Path -Path $ToolsPath -ChildPath 'nuget' -Resolve );
. $NuGetToolsPath/.build.ps1;
. $NuGetToolsPath/nuget.build.inc.ps1;

[System.String] $BuildToolsPath = ( Join-Path -Path $ToolsPath -ChildPath 'build' -Resolve );
[System.String] $UpdateFileLastWriteTimePath = ( Join-Path -Path $BuildToolsPath -ChildPath 'Update-FileLastWriteTime.ps1' -Resolve );
Expand Down
37 changes: 25 additions & 12 deletions tools/nuget/.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,36 @@
#Requires -Version 5.0
#Requires -Modules InvokeBuild

param(
[Parameter( Position = 0 )]
[System.String[]]
$Tasks
)

Set-StrictMode -Version Latest;
$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop;

[System.String] $NuGetVersion = 'latest';
$parameters = $PSBoundParameters;

[System.String] $NuGetPath = ( Join-Path -Path $PSScriptRoot -ChildPath 'nuget.exe' );
if ( Get-Command 'nuget.exe' -ErrorAction 'SilentlyContinue' )
if ( [System.IO.Path]::GetFileName( $MyInvocation.ScriptName ) -ne 'Invoke-Build.ps1' )
{
$NuGetPath = 'nuget.exe';
Invoke-Build -Task $Tasks -File $MyInvocation.MyCommand.Path @parameters;
return;
};


task nuget `
-If { -not ( Get-Command $NuGetPath -ErrorAction 'SilentlyContinue' ) } `
-Jobs {
$NuGetURI = "https://dist.nuget.org/win-x86-commandline/$NuGetVersion/nuget.exe";
Invoke-WebRequest $NuGetURI -OutFile $NuGetPath `
-Verbose:( $VerbosePreference -ne [System.Management.Automation.ActionPreference]::SilentlyContinue ) `
-Debug:( $DebugPreference -ne [System.Management.Automation.ActionPreference]::SilentlyContinue );
. $NuGetPath sources add -Name 'nuget.org' -Source 'https://api.nuget.org/v3/index.json';
. $PSScriptRoot/nuget.build.inc.ps1;

task clean {};

task distclean clean, {
Remove-BuildItem $NuGetLocalPath;
};

task maintainer-clean distclean;

task pre-build nuget;

task all pre-build;

task . all;
32 changes: 32 additions & 0 deletions tools/nuget/nuget.build.inc.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright © 2020 Sergei S. Betke

#Requires -Version 5.0
#Requires -Modules InvokeBuild

Set-StrictMode -Version Latest;

[System.String] $NuGetVersion = 'latest';

[System.String] $NuGetLocalPath = ( Join-Path -Path $PSScriptRoot -ChildPath 'nuget.exe' );
[System.String] $NuGetPath = ( Join-Path -Path $PSScriptRoot -ChildPath 'nuget.exe' );

if ( Get-Command 'nuget.exe' -ErrorAction 'SilentlyContinue' )
{
$NuGetPath = 'nuget.exe';
}
else
{
$NuGetPath = $NuGetLocalPath;
};


task nuget `
-If { -not ( Get-Command $NuGetPath -ErrorAction 'SilentlyContinue' ) } `
-Jobs {
$NuGetURI = "https://dist.nuget.org/win-x86-commandline/$NuGetVersion/nuget.exe";
Invoke-WebRequest $NuGetURI -OutFile $NuGetLocalPath `
-Verbose:( $VerbosePreference -ne [System.Management.Automation.ActionPreference]::SilentlyContinue ) `
-Debug:( $DebugPreference -ne [System.Management.Automation.ActionPreference]::SilentlyContinue );
$NuGetPath = $NuGetLocalPath;
. $NuGetPath sources add -Name 'nuget.org' -Source 'https://api.nuget.org/v3/index.json';
};

0 comments on commit 13614b1

Please sign in to comment.