Skip to content

Commit b1116d0

Browse files
committed
Merge branch 'master' of https://github.com/powershell/PSResourceGet into release/v1.1.0-RC2
2 parents 7cf5caa + de278b4 commit b1116d0

18 files changed

+234
-94
lines changed

.ci/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
- ${{ parameters.powershellExecutable }}: |
4949
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
5050
Write-Verbose -Verbose "Install Microsoft.PowerShell.PSResourceGet to temp module path"
51-
Save-Module -Name Microsoft.PowerShell.PSResourceGet -MinimumVersion 0.9.0-rc1 -Path $modulePath -AllowPrerelease -Force
51+
Save-Module -Name Microsoft.PowerShell.PSResourceGet -Path $modulePath -Force -Verbose
5252
Write-Verbose -Verbose "Install Pester 4.X to temp module path"
5353
Save-Module -Name "Pester" -MaximumVersion 4.99 -Path $modulePath -Force
5454
displayName: Install Microsoft.PowerShell.PSResourceGet and Pester
@@ -59,7 +59,7 @@ jobs:
5959
Write-Verbose -Verbose "Importing build utilities (buildtools.psd1)"
6060
Import-Module -Name (Join-Path -Path '${{ parameters.buildDirectory }}' -ChildPath 'buildtools.psd1') -Force
6161
#
62-
Install-ModulePackageForTest -PackagePath "$(System.ArtifactsDirectory)"
62+
Install-ModulePackageForTest -PackagePath "$(System.ArtifactsDirectory)" -ErrorAction stop -Verbose
6363
displayName: Install module for test from downloaded artifact
6464
workingDirectory: ${{ parameters.buildDirectory }}
6565

CHANGELOG/1.0.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
## [1.0.5](https://github.com/PowerShell/PSResourceGet/compare/v1.0.4.1...v1.0.5) - 2024-05-13
88

99
### Bug Fixes
10+
1011
- Update `nuget.config` to use PowerShell packages feed (#1649)
1112
- Refactor V2ServerAPICalls and NuGetServerAPICalls to use object-oriented query/filter builder (#1645 Thanks @sean-r-williams!)
1213
- Fix unnecessary `and` for version globbing in V2ServerAPICalls (#1644 Thanks again @sean-r-williams!)
@@ -422,7 +423,7 @@ All tests have been reviewed and rewritten as needed.
422423

423424
## 3.0.0-beta8
424425

425-
### New Features
426+
### New Features
426427

427428
- Add `-Type` parameter to `Install-PSResource`
428429
- Add 'sudo' check for admin privileges in Unix in `Install-PSResource`
@@ -436,7 +437,7 @@ All tests have been reviewed and rewritten as needed.
436437

437438
## 3.0.0-beta7
438439

439-
### New Features
440+
### New Features
440441

441442
- Completed functionality for `Update-PSResource`
442443
- `Input-Object` parameter for `Install-PSResource`
@@ -499,4 +500,5 @@ All tests have been reviewed and rewritten as needed.
499500
## 3.0.0-beta1
500501

501502
### BREAKING CHANGE
502-
- Preview version of PowerShellGet. Many features are not fully implemented yet. Please see https://devblogs.microsoft.com/powershell/powershellget-3-0-preview1 for more details.
503+
504+
- Preview version of PowerShellGet. Many features are not fully implemented yet. Please see <https://devblogs.microsoft.com/powershell/powershellget-3-0-preview1> for more details.

CHANGELOG/preview.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
- Bug fixes for finding and installing from local repositories on Linux machines (#1738)
1010
- Bug fix for finding package name with 4 part version from local repositories (#1739)
1111

12+
# Preview Changelog
13+
1214
## [1.1.0-RC1](https://github.com/PowerShell/PSResourceGet/compare/v1.1.0-preview2...v1.1.0-RC1) - 2024-10-22
1315

1416
### New Features
@@ -19,9 +21,9 @@
1921

2022
- Fix packaging name matching when searching in local repositories (#1731)
2123
- `Compress-PSResource` `-PassThru` now passes `FileInfo` instead of string (#1720)
22-
- Fix for `Compress-PSResource` not properly compressing scripts (#1719)
24+
- Fix for `Compress-PSResource` not properly compressing scripts (#1719)
2325
- Add `AcceptLicense` to Save-PSResource (#1718 Thanks @o-l-a-v!)
24-
- Better support for NuGet v2 feeds (#1713 Thanks @o-l-a-v!)
26+
- Better support for Azure DevOps Artifacts NuGet v2 feeds (#1713 Thanks @o-l-a-v!)
2527
- Better handling of `-WhatIf` support in `Install-PSResource` (#1531 Thanks @o-l-a-v!)
2628
- Fix for some nupkgs failing to extract due to empty directories (#1707 Thanks @o-l-a-v!)
2729
- Fix for searching for `-Name *` in `Find-PSResource` (#1706 Thanks @o-l-a-v!)
@@ -45,8 +47,7 @@
4547

4648
### New Features
4749

48-
- Support for Azure Container Registries (#1495, #1497-#1499, #1501, #1502, #1505, #1522, #1545, #1548, #1550, #1554, #1560, #1567,
49-
#1573, #1576, #1587, #1588, #1589, #1594, #1598, #1600, #1602, #1604, #1615)
50+
- Support for Azure Container Registries (#1495, #1497-#1499, #1501, #1502, #1505, #1522, #1545, #1548, #1550, #1554, #1560, #1567, #1573, #1576, #1587, #1588, #1589, #1594, #1598, #1600, #1602, #1604, #1615)
5051

5152
### Bug Fixes
5253

buildtools.psm1

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,23 @@ function Install-ModulePackageForTest {
120120
}
121121

122122
Write-Verbose -Verbose -Message "Installing module $($config.ModuleName) to build output path $installationPath"
123-
Save-PSResource -Name $config.ModuleName -Repository $localRepoName -Path $installationPath -SkipDependencyCheck -Prerelease -Confirm:$false -TrustRepository
123+
$psgetModuleBase = (get-command save-psresource).Module.ModuleBase
124+
$psgetVersion = (get-command save-psresource).Module.Version.ToString()
125+
$psgetPrerelease = (get-command find-psresource).module.PrivateData.PSData.Prerelease
126+
Write-Verbose -Verbose -Message "PSResourceGet module base imported: $psgetModuleBase"
127+
Write-Verbose -Verbose -Message "PSResourceGet version base imported: $psgetVersion"
128+
Write-Verbose -Verbose -Message "PSResourceGet prerelease base imported: $psgetPrerelease"
129+
#Save-PSResource -Name $config.ModuleName -Repository $localRepoName -Path $installationPath -SkipDependencyCheck -Prerelease -Confirm:$false -TrustRepository
130+
131+
Register-PSRepository -Name $localRepoName -SourceLocation $packagePathWithNupkg -InstallationPolicy Trusted -Verbose
132+
$psgetv2ModuleBase = (get-command save-module).Module.ModuleBase
133+
$psgetv2Version = (get-command save-module).Module.Version.ToString()
134+
$psgetv2Prerelease = (get-command save-module).module.PrivateData.PSData.Prerelease
135+
Write-Verbose -Verbose -Message "PowerShellGet module base imported: $psgetv2ModuleBase"
136+
Write-Verbose -Verbose -Message "PowerShellGet version base imported: $psgetv2Version"
137+
Write-Verbose -Verbose -Message "PowerShellGet prerelease base imported: $psgetv2Prerelease"
138+
Save-Module -Name $config.ModuleName -Repository $localRepoName -Path $installationPath -Force -Verbose -AllowPrerelease -Confirm:$false
139+
Unregister-PSRepository -Name $localRepoName
124140

125141
Write-Verbose -Verbose -Message "Unregistering local package repo: $localRepoName"
126142
Unregister-PSResourceRepository -Name $localRepoName -Confirm:$false

src/code/ContainerRegistryServerAPICalls.cs

Lines changed: 54 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ internal class ContainerRegistryServerAPICalls : ServerApiCall
4343
const string containerRegistryOAuthTokenUrlTemplate = "https://{0}/oauth2/token"; // 0 - registry
4444
const string containerRegistryManifestUrlTemplate = "https://{0}/v2/{1}/manifests/{2}"; // 0 - registry, 1 - repo(modulename), 2 - tag(version)
4545
const string containerRegistryBlobDownloadUrlTemplate = "https://{0}/v2/{1}/blobs/{2}"; // 0 - registry, 1 - repo(modulename), 2 - layer digest
46-
const string containerRegistryFindImageVersionUrlTemplate = "https://{0}/acr/v1/{1}/_tags{2}"; // 0 - registry, 1 - repo(modulename), 2 - /tag(version)
46+
const string containerRegistryFindImageVersionUrlTemplate = "https://{0}/v2/{1}/tags/list"; // 0 - registry, 1 - repo(modulename)
4747
const string containerRegistryStartUploadTemplate = "https://{0}/v2/{1}/blobs/uploads/"; // 0 - registry, 1 - packagename
4848
const string containerRegistryEndUploadTemplate = "https://{0}{1}&digest=sha256:{2}"; // 0 - registry, 1 - location, 2 - digest
4949

@@ -286,7 +286,8 @@ public override Stream InstallPackage(string packageName, string packageVersion,
286286
return results;
287287
}
288288

289-
results = InstallVersion(packageName, packageVersion, out errRecord);
289+
string packageNameForInstall = PrependMARPrefix(packageName);
290+
results = InstallVersion(packageNameForInstall, packageVersion, out errRecord);
290291
return results;
291292
}
292293

@@ -413,6 +414,7 @@ internal string GetContainerRegistryAccessToken(out ErrorRecord errRecord)
413414
else
414415
{
415416
_cmdletPassedIn.WriteVerbose("Repository is unauthenticated");
417+
return null;
416418
}
417419
}
418420

@@ -572,27 +574,19 @@ internal async Task<HttpContent> GetContainerRegistryBlobAsync(string packageNam
572574
/// </summary>
573575
internal JObject FindContainerRegistryImageTags(string packageName, string version, string containerRegistryAccessToken, out ErrorRecord errRecord)
574576
{
575-
/* response returned looks something like:
576-
* "registry": "myregistry.azurecr.io"
577-
* "imageName": "hello-world"
578-
* "tags": [
579-
* {
580-
* ""name"": ""1.0.0"",
581-
* ""digest"": ""sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a"",
582-
* ""createdTime"": ""2023-12-23T18:06:48.9975733Z"",
583-
* ""lastUpdateTime"": ""2023-12-23T18:06:48.9975733Z"",
584-
* ""signed"": false,
585-
* ""changeableAttributes"": {
586-
* ""deleteEnabled"": true,
587-
* ""writeEnabled"": true,
588-
* ""readEnabled"": true,
589-
* ""listEnabled"": true
590-
* }
591-
* }]
592-
*/
577+
/*
578+
{
579+
"name": "<name>",
580+
"tags": [
581+
"<tag1>",
582+
"<tag2>",
583+
"<tag3>"
584+
]
585+
}
586+
*/
593587
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::FindContainerRegistryImageTags()");
594588
string resolvedVersion = string.Equals(version, "*", StringComparison.OrdinalIgnoreCase) ? null : $"/{version}";
595-
string findImageUrl = string.Format(containerRegistryFindImageVersionUrlTemplate, Registry, packageName, resolvedVersion);
589+
string findImageUrl = string.Format(containerRegistryFindImageVersionUrlTemplate, Registry, packageName);
596590
var defaultHeaders = GetDefaultHeaders(containerRegistryAccessToken);
597591
return GetHttpResponseJObjectUsingDefaultHeaders(findImageUrl, HttpMethod.Get, defaultHeaders, out errRecord);
598592
}
@@ -1608,13 +1602,14 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
16081602
string registryUrl = Repository.Uri.ToString();
16091603
string packageNameLowercase = packageName.ToLower();
16101604

1605+
string packageNameForFind = PrependMARPrefix(packageNameLowercase);
16111606
string containerRegistryAccessToken = GetContainerRegistryAccessToken(out errRecord);
16121607
if (errRecord != null)
16131608
{
16141609
return emptyHashResponses;
16151610
}
16161611

1617-
var foundTags = FindContainerRegistryImageTags(packageNameLowercase, "*", containerRegistryAccessToken, out errRecord);
1612+
var foundTags = FindContainerRegistryImageTags(packageNameForFind, "*", containerRegistryAccessToken, out errRecord);
16181613
if (errRecord != null || foundTags == null)
16191614
{
16201615
return emptyHashResponses;
@@ -1623,7 +1618,7 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
16231618
List<Hashtable> latestVersionResponse = new List<Hashtable>();
16241619
List<JToken> allVersionsList = foundTags["tags"].ToList();
16251620

1626-
SortedDictionary<NuGet.Versioning.SemanticVersion, string> sortedQualifyingPkgs = GetPackagesWithRequiredVersion(allVersionsList, versionType, versionRange, requiredVersion, packageNameLowercase, includePrerelease, out errRecord);
1621+
SortedDictionary<NuGet.Versioning.SemanticVersion, string> sortedQualifyingPkgs = GetPackagesWithRequiredVersion(allVersionsList, versionType, versionRange, requiredVersion, packageNameForFind, includePrerelease, out errRecord);
16271622
if (errRecord != null)
16281623
{
16291624
return emptyHashResponses;
@@ -1634,7 +1629,7 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
16341629
foreach (var pkgVersionTag in pkgsInDescendingOrder)
16351630
{
16361631
string exactTagVersion = pkgVersionTag.Value.ToString();
1637-
Hashtable metadata = GetContainerRegistryMetadata(packageNameLowercase, exactTagVersion, containerRegistryAccessToken, out errRecord);
1632+
Hashtable metadata = GetContainerRegistryMetadata(packageNameForFind, exactTagVersion, containerRegistryAccessToken, out errRecord);
16381633
if (errRecord != null || metadata.Count == 0)
16391634
{
16401635
return emptyHashResponses;
@@ -1664,58 +1659,55 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
16641659

16651660
foreach (var pkgVersionTagInfo in allPkgVersions)
16661661
{
1667-
using (JsonDocument pkgVersionEntry = JsonDocument.Parse(pkgVersionTagInfo.ToString()))
1662+
string pkgVersionString = pkgVersionTagInfo.ToString();
1663+
// determine if the package version that is a repository tag is a valid NuGetVersion
1664+
if (!NuGetVersion.TryParse(pkgVersionString, out NuGetVersion pkgVersion))
16681665
{
1669-
JsonElement rootDom = pkgVersionEntry.RootElement;
1670-
if (!rootDom.TryGetProperty("name", out JsonElement pkgVersionElement))
1671-
{
1672-
errRecord = new ErrorRecord(
1673-
new InvalidOrEmptyResponse($"Response does not contain version element ('name') for package '{packageName}' in '{Repository.Name}'."),
1674-
"FindNameFailure",
1675-
ErrorCategory.InvalidResult,
1676-
this);
1677-
1678-
return null;
1679-
}
1680-
1681-
string pkgVersionString = pkgVersionElement.ToString();
1682-
// determine if the package version that is a repository tag is a valid NuGetVersion
1683-
if (!NuGetVersion.TryParse(pkgVersionString, out NuGetVersion pkgVersion))
1684-
{
1685-
errRecord = new ErrorRecord(
1686-
new ArgumentException($"Version {pkgVersionString} to be parsed from metadata is not a valid NuGet version."),
1687-
"FindNameFailure",
1688-
ErrorCategory.InvalidArgument,
1689-
this);
1666+
errRecord = new ErrorRecord(
1667+
new ArgumentException($"Version {pkgVersionString} to be parsed from metadata is not a valid NuGet version."),
1668+
"FindNameFailure",
1669+
ErrorCategory.InvalidArgument,
1670+
this);
16901671

1691-
return null;
1692-
}
1672+
return null;
1673+
}
16931674

1694-
_cmdletPassedIn.WriteDebug($"'{packageName}' version parsed as '{pkgVersion}'");
1675+
_cmdletPassedIn.WriteDebug($"'{packageName}' version parsed as '{pkgVersion}'");
16951676

1696-
if (isSpecificVersionSearch)
1677+
if (isSpecificVersionSearch)
1678+
{
1679+
if (pkgVersion.ToNormalizedString() == specificVersion.ToNormalizedString())
16971680
{
1698-
if (pkgVersion.ToNormalizedString() == specificVersion.ToNormalizedString())
1699-
{
1700-
// accounts for FindVersion() scenario
1701-
sortedPkgs.Add(pkgVersion, pkgVersionString);
1702-
break;
1703-
}
1681+
// accounts for FindVersion() scenario
1682+
sortedPkgs.Add(pkgVersion, pkgVersionString);
1683+
break;
17041684
}
1705-
else
1685+
}
1686+
else
1687+
{
1688+
if (versionRange.Satisfies(pkgVersion) && (!pkgVersion.IsPrerelease || includePrerelease))
17061689
{
1707-
if (versionRange.Satisfies(pkgVersion) && (!pkgVersion.IsPrerelease || includePrerelease))
1708-
{
1709-
// accounts for FindVersionGlobbing() and FindName() scenario
1710-
sortedPkgs.Add(pkgVersion, pkgVersionString);
1711-
}
1690+
// accounts for FindVersionGlobbing() and FindName() scenario
1691+
sortedPkgs.Add(pkgVersion, pkgVersionString);
17121692
}
17131693
}
17141694
}
17151695

17161696
return sortedPkgs;
17171697
}
17181698

1699+
private string PrependMARPrefix(string packageName)
1700+
{
1701+
string prefix = string.IsNullOrEmpty(InternalHooks.MARPrefix) ? PSRepositoryInfo.MARPrefix : InternalHooks.MARPrefix;
1702+
1703+
// If the repostitory is MAR and its not a wildcard search, we need to prefix the package name with MAR prefix.
1704+
string updatedPackageName = Repository.IsMARRepository() && packageName.Trim() != "*"
1705+
? string.Concat(prefix, packageName)
1706+
: packageName;
1707+
1708+
return updatedPackageName;
1709+
}
1710+
17191711
#endregion
17201712
}
17211713
}

src/code/InternalHooks.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class InternalHooks
1515

1616
internal static string AllowedUri;
1717

18+
internal static string MARPrefix;
19+
1820
public static void SetTestHook(string property, object value)
1921
{
2022
var fieldInfo = typeof(InternalHooks).GetField(property, BindingFlags.Static | BindingFlags.NonPublic);

0 commit comments

Comments
 (0)