Skip to content

Commit 7904bfd

Browse files
authored
Updating Nuget.exe that is supported on Test Gallery (#3290)
* Updating Nuget.exe that is supported on Test Gallery * Adding signed copy of nuget.exe 3.4.4.1321 that is currently being used by PS branch * adding nuget feed into build.proj. Adding diagnostic logs to PublishModule.ps1 * Updating nuget package restore directory for product and test * Updating packages paths for tests * Repacking after updating signed nuget package by adding psm1 dependency to the module. If not done, Test Gallyer/PS Gallery will fail to accept the package when try to push the nuget package as the package contents have changed after signing it * Updating the copy of nuget exe that would repack nuget during build process. Test Gallery is still v2 based, hence will not accept any other version of nuget.exe while pushing/publishing it to Test Gallery. * Adding more logging in publish module. Adding null check for unregistering Repositories at the end of PublishModule
1 parent 9a81ee2 commit 7904bfd

File tree

6 files changed

+68
-15
lines changed

6 files changed

+68
-15
lines changed

AzurePowershell.Test.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
<Message Importance="high" Text="Running XUnit tests" />
101101
<MakeDir Directories="$(TestOutputDirectory)" ContinueOnError="false" />
102102
<Exec
103-
Command="$(MSBuildProjectDirectory)\packages\xunit.runner.console.2.0.0\tools\xunit.console.x86.exe &quot;%(XUnitTests.Identity)&quot; -parallel none -maxthreads 0 -trait &quot;AcceptanceType=CheckIn&quot; -html &quot;$(TestOutputDirectory)\%(XUnitTests.Filename).html&quot;"
103+
Command="$(LibrarySourceFolder)\packages\xunit.runner.console.2.0.0\tools\xunit.console.x86.exe &quot;%(XUnitTests.Identity)&quot; -parallel none -maxthreads 0 -trait &quot;AcceptanceType=CheckIn&quot; -html &quot;$(TestOutputDirectory)\%(XUnitTests.Filename).html&quot;"
104104
Timeout="$(TestTimeout)" ContinueOnError="false" Condition=" @(XUnitTests) != '' "/>
105105
<OnError ExecuteTargets="TimeoutErrorHandler"/>
106106
</Target>
@@ -109,7 +109,7 @@
109109
<Message Importance="high" Text="Running XUnit tests" />
110110
<MakeDir Directories="$(TestOutputDirectory)" ContinueOnError="false" />
111111
<Exec
112-
Command="$(MSBuildProjectDirectory)\packages\xunit.runner.console.2.0.0\tools\xunit.console.x86.exe &quot;%(XUnitTests.Identity)&quot; -notrait &quot;RunType=LiveOnly&quot; -html &quot;$(TestOutputDirectory)\%(XUnitTests.Filename).html&quot;"
112+
Command="$(LibrarySourceFolder)\packages\xunit.runner.console.2.0.0\tools\xunit.console.x86.exe &quot;%(XUnitTests.Identity)&quot; -notrait &quot;RunType=LiveOnly&quot; -html &quot;$(TestOutputDirectory)\%(XUnitTests.Filename).html&quot;"
113113
Timeout="$(TestTimeout)" ContinueOnError="false"/>
114114
<OnError ExecuteTargets="TimeoutErrorHandler"/>
115115
</Target>

build.proj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,14 @@
132132
Encoding="Unicode"/>
133133

134134
<Exec Command="$(NuGetCommand) sources add -Name LocalFeed -Source &quot;$(MSBuildProjectDirectory)\tools\LocalFeed&quot; $(NuGetRestoreConfigSwitch)"/>
135+
<Exec Command="$(NuGetCommand) sources add -Name nugetRemote -Source &quot;https://api.nuget.org/v3/index.json&quot; $(NuGetRestoreConfigSwitch)"/>
135136

136137
<!-- Restore packages -->
137-
<Exec Command="$(NuGetCommand) restore %(CmdletSolutionsToBuild.FullPath) $(NuGetRestoreConfigSwitch)"
138+
<Exec Command="$(NuGetCommand) restore %(CmdletSolutionsToBuild.FullPath) $(NuGetRestoreConfigSwitch) -PackagesDirectory $(LibrarySourceFolder)\packages"
138139
ContinueOnError="false" />
139140

140141
<!--Restore the xunit runner needed to run unit tests-->
141-
<Exec Command="$(NuGetCommand) restore $(MSBuildProjectDirectory)\packages.config -PackagesDirectory $(MSBuildProjectDirectory)\packages" />
142+
<Exec Command="$(NuGetCommand) restore $(MSBuildProjectDirectory)\packages.config -PackagesDirectory -PackagesDirectory $(LibrarySourceFolder)\packages" />
142143

143144
<Delete Files="$(NuGetRestoreConfigFile)" />
144145
</Target>
@@ -292,7 +293,7 @@
292293
<Target Name="Publish">
293294
<Error Condition=" '$(NuGetKey)' == '' " Text="You must provide the NuGetKey parameter to the build: /p:NuGetKey=YOUR_PUBLISHING_KEY" />
294295
<Message Importance="high" Text="Publishing Cmdlets..." />
295-
<Exec Command="$(PowerShellCommand) -NonInteractive -NoLogo -NoProfile -Command &quot;. $(LibraryToolsFolder)\PublishModules.ps1 $(Configuration) $(Scope) $(NuGetKey) \&quot;$(NuGetPublishingSource)\&quot; &quot;"/>
296+
<Exec Command="$(PowerShellCommand) -NonInteractive -NoLogo -NoProfile -Command &quot;. $(LibraryToolsFolder)\PublishModules.ps1 $(Configuration) $(Scope) $(NuGetKey) \&quot;$(NuGetPublishingSource)\&quot; $(NuGetCommand) &quot;"/>
296297
</Target>
297298

298299
<PropertyGroup>

tools/NuGet.exe

23 KB
Binary file not shown.

tools/Nuget/NuGet_2.8.exe

1.59 MB
Binary file not shown.

tools/Nuget/NuGet_signed_344.exe

3.77 MB
Binary file not shown.

tools/PublishModules.ps1

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,36 @@ function Remove-ModuleDependencies
143143

144144
}
145145

146+
function Update-NugetPackage
147+
{
148+
[CmdletBinding()]
149+
param(
150+
[string]$BasePath,
151+
[string]$ModuleName,
152+
[string]$DirPath,
153+
[string]$NugetExe
154+
)
155+
156+
PROCESS
157+
{
158+
$regex = New-Object -Type System.Text.RegularExpressions.Regex -ArgumentList "([0-9\.]+)nupkg$"
159+
$regex2 = "<requireLicenseAcceptance>false</requireLicenseAcceptance>"
160+
161+
$relDir = Join-Path $DirPath -ChildPath "_rels"
162+
$contentPath = Join-Path $DirPath -ChildPath '`[Content_Types`].xml'
163+
$packPath = Join-Path $DirPath -ChildPath "package"
164+
$modulePath = Join-Path $DirPath -ChildPath ($ModuleName + ".nuspec")
165+
Remove-Item -Recurse -Path $relDir -Force
166+
Remove-Item -Recurse -Path $packPath -Force
167+
Remove-Item -Path $contentPath -Force
168+
$content = (Get-Content -Path $modulePath) -join "`r`n"
169+
$content = $content -replace $regex2, ("<licenseUrl>https://raw.githubusercontent.com/Azure/azure-powershell/dev/LICENSE.txt</licenseUrl>`r`n <projectUrl>https://github.com/Azure/azure-powershell</projectUrl>`r`n <requireLicenseAcceptance>true</requireLicenseAcceptance>")
170+
$content | Out-File -FilePath $modulePath -Force
171+
&$NugetExe pack $modulePath -OutputDirectory $BasePath
172+
}
173+
}
174+
175+
146176
function Change-RMModule
147177
{
148178
[CmdletBinding()]
@@ -183,11 +213,9 @@ function Change-RMModule
183213
Write-Output "Removing module manifest dependencies for $unzippedManifest"
184214
Remove-ModuleDependencies -Path $unzippedManifest
185215

186-
Remove-Item -Path $zipPath -Force
187-
Write-Output "Compressing $zipPath"
188-
Compress-Archive (Join-Path -Path $dirPath -ChildPath "*") -DestinationPath $zipPath
189-
Write-Output "Renaming package $zipPath to zip archive $nupkgPath"
190-
ren $zipPath $nupkgPath
216+
Remove-Item -Path $zipPath -Force
217+
Write-Output "Repackaging $dirPath"
218+
Update-NugetPackage -BasePath $TempRepoPath -ModuleName $moduleName -DirPath $dirPath -NugetExe $NugetExe
191219
}
192220
finally
193221
{
@@ -235,9 +263,14 @@ if ([string]::IsNullOrEmpty($buildConfig))
235263

236264
if ([string]::IsNullOrEmpty($repositoryLocation))
237265
{
238-
Write-Verbose "Setting repository location to 'https://dtlgalleryint.cloudapp.net/api/v2'"
266+
Write-Output "No repository location was provided, setting it to default"
267+
Write-Output "Setting repository location to 'https://dtlgalleryint.cloudapp.net/api/v2'"
239268
$repositoryLocation = "https://dtlgalleryint.cloudapp.net/api/v2"
240269
}
270+
else
271+
{
272+
Write-Output "Setting repository location to '$repositoryLocation'"
273+
}
241274

242275
if ([string]::IsNullOrEmpty($scope))
243276
{
@@ -256,20 +289,28 @@ Write-Host "Publishing $scope package(and its dependencies)"
256289
$packageFolder = "$PSScriptRoot\..\src\Package"
257290

258291
$repo = Get-PSRepository | where { $_.SourceLocation -eq $repositoryLocation }
259-
if ($repo -ne $null) {
292+
if ($repo -ne $null)
293+
{
260294
$repoName = $repo.Name
261-
} else {
295+
Write-Output "Existing PS Repository detected: $repo.Name"
296+
}
297+
else
298+
{
262299
$repoName = $(New-Guid).ToString()
263-
Register-PSRepository -Name $repoName -SourceLocation $repositoryLocation -PublishLocation $repositoryLocation/package -InstallationPolicy Trusted
300+
Write-Output "Setting up new PS Repository to: -Name $repoName -SourceLocation $repositoryLocation -PublishLocation $repositoryLocation/package -InstallationPolicy Trusted"
301+
Register-PSRepository -Name $repoName -SourceLocation $repositoryLocation -PublishLocation $repositoryLocation\package -InstallationPolicy Trusted
264302
}
265303

266304
$publishToLocal = test-path $repositoryLocation
267305
[string]$tempRepoPath = "$PSScriptRoot\..\src\package"
268306
if ($publishToLocal)
269307
{
308+
Write-Output "Publish to local is set to: $publishToLocal"
270309
$tempRepoPath = (Join-Path $repositoryLocation -ChildPath "package")
271310
}
311+
272312
$tempRepoName = ([System.Guid]::NewGuid()).ToString()
313+
Write-Output "Setting up TEMP PS Repository to: -Name $tempRepoName -SourceLocation $tempRepoPath -PublishLocation $tempRepoPath -InstallationPolicy Trusted -PackageManagementProvider NuGet"
273314
Register-PSRepository -Name $tempRepoName -SourceLocation $tempRepoPath -PublishLocation $tempRepoPath -InstallationPolicy Trusted -PackageManagementProvider NuGet
274315

275316
try {
@@ -298,5 +339,16 @@ try {
298339
}
299340
finally
300341
{
301-
Unregister-PSRepository -Name $tempRepoName
342+
if($tempRepoName -ne $null)
343+
{
344+
Write-Output "Unregistering Repository: $tempRepoName"
345+
Get-PSRepository -Name $tempRepoName | Unregister-PSRepository
346+
}
347+
348+
if($repoName -ne $null)
349+
{
350+
Write-Output "Unregistering Repository: $repoName"
351+
Get-PSRepository -Name $repoName | Unregister-PSRepository
352+
}
353+
302354
}

0 commit comments

Comments
 (0)