Skip to content

Commit

Permalink
initial publish latest skeleton code
Browse files Browse the repository at this point in the history
  • Loading branch information
anamnavi committed Jan 24, 2025
1 parent 28d241e commit 580bbac
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
19 changes: 15 additions & 4 deletions src/code/ContainerRegistryServerAPICalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,12 +1129,13 @@ internal bool PushNupkgContainerRegistry(
Hashtable dependencies,
bool isNupkgPathSpecified,
string originalNupkgPath,
string latestTag,
out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In ContainerRegistryServerAPICalls::PushNupkgContainerRegistry()");

// if isNupkgPathSpecified, then we need to publish the original .nupkg file, as it may be signed
string fullNupkgFile = isNupkgPathSpecified ? originalNupkgPath : System.IO.Path.Combine(outputNupkgDir, packageName + "." + packageVersion.ToNormalizedString() + ".nupkg");
string fullNupkgFile = isNupkgPathSpecified ? originalNupkgPath : System.IO.Path.Combine(outputNupkgDir, packageName + "." + packageVersion.ToNormalizedString() + ".nupkg");

string pkgNameForUpload = string.IsNullOrEmpty(modulePrefix) ? packageName : modulePrefix + "/" + packageName;
string packageNameLowercase = pkgNameForUpload.ToLower();
Expand Down Expand Up @@ -1180,7 +1181,7 @@ internal bool PushNupkgContainerRegistry(
}

// Create and upload manifest
TryCreateAndUploadManifest(fullNupkgFile, nupkgDigest, configDigest, packageName, modulePrefix, resourceType, metadataJson, configFilePath, packageVersion, containerRegistryAccessToken, out errRecord);
TryCreateAndUploadManifest(fullNupkgFile, nupkgDigest, configDigest, packageName, modulePrefix, resourceType, metadataJson, configFilePath, packageVersion, latestTag, containerRegistryAccessToken, out errRecord);
if (errRecord != null)
{
return false;
Expand Down Expand Up @@ -1354,6 +1355,7 @@ private bool TryCreateAndUploadManifest(string fullNupkgFile,
string metadataJson,
string configFilePath,
NuGetVersion pkgVersion,
string latestTag,
string containerRegistryAccessToken,
out ErrorRecord errRecord)
{
Expand All @@ -1371,15 +1373,24 @@ private bool TryCreateAndUploadManifest(string fullNupkgFile,

_cmdletPassedIn.WriteVerbose("Create the manifest layer");
bool manifestCreated = false;
string currentTag = pkgVersion.OriginalVersion;
try
{
HttpResponseMessage manifestResponse = UploadManifest(packageNameLowercase, pkgVersion.OriginalVersion, configFilePath, true, containerRegistryAccessToken).Result;
HttpResponseMessage manifestResponse = UploadManifest(packageNameLowercase, currentTag, configFilePath, true, containerRegistryAccessToken).Result;
manifestCreated = manifestResponse.IsSuccessStatusCode;

if (!String.IsNullOrEmpty(latestTag))
{
// we also want to publish this pkg version with latest/preview tag pointing to it
currentTag = latestTag;
HttpResponseMessage tagManifestResponse = UploadManifest(packageNameLowercase, latestTag, configFilePath, true, containerRegistryAccessToken).Result;
manifestCreated = manifestResponse.IsSuccessStatusCode;
}
}
catch (Exception e)
{
errRecord = new ErrorRecord(
new UploadBlobException($"Error occured while uploading package manifest to ContainerRegistry: {e.GetType()} '{e.Message}'", e),
new UploadBlobException($"Error occured while uploading package manifest with tag '{currentTag}' to ContainerRegistry: {e.GetType()} '{e.Message}'", e),
"PackageManifestUploadError",
ErrorCategory.InvalidResult,
_cmdletPassedIn);
Expand Down
16 changes: 14 additions & 2 deletions src/code/PublishHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ internal enum CallerCmdlet
private NetworkCredential _networkCredential;
string userAgentString = UserAgentInfo.UserAgentString();
private bool _isNupkgPathSpecified = false;
private bool _isContainerRegistryLatest = false;
private bool _isContainerRegistryLatestPreview = false;
private Hashtable dependencies;
private Hashtable parsedMetadata;
private PSCredential Credential;
Expand Down Expand Up @@ -88,7 +90,9 @@ internal PublishHelper(PSCmdlet cmdlet,
string destinationPath,
bool skipModuleManifestValidate,
CancellationToken cancellationToken,
bool isNupkgPathSpecified)
bool isNupkgPathSpecified,
bool isContainerRegistryLatest,
bool isContainerRegistryLatestPreview)
{
_callerCmdlet = CallerCmdlet.PublishPSResource;
_cmdOperation = "Publish";
Expand All @@ -100,6 +104,8 @@ internal PublishHelper(PSCmdlet cmdlet,
SkipModuleManifestValidate = skipModuleManifestValidate;
_cancellationToken = cancellationToken;
_isNupkgPathSpecified = isNupkgPathSpecified;
_isContainerRegistryLatest = isContainerRegistryLatest;
_isContainerRegistryLatestPreview = isContainerRegistryLatestPreview;
outputDir = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString());
outputNupkgDir = System.IO.Path.Combine(outputDir, "nupkg");
}
Expand Down Expand Up @@ -460,7 +466,13 @@ internal void PushResource(string Repository, string modulePrefix, bool SkipDepe
}
}

if (!containerRegistryServer.PushNupkgContainerRegistry(outputNupkgDir, _pkgName, modulePrefix, _pkgVersion, resourceType, parsedMetadata, dependencies, _isNupkgPathSpecified, Path, out ErrorRecord pushNupkgContainerRegistryError))
string latestTag = String.Empty;
if (_isContainerRegistryLatest || _isContainerRegistryLatestPreview)
{
latestTag = _isContainerRegistryLatest ? "latest" : "preview";
}

if (!containerRegistryServer.PushNupkgContainerRegistry(outputNupkgDir, _pkgName, modulePrefix, _pkgVersion, resourceType, parsedMetadata, dependencies, _isNupkgPathSpecified, Path, latestTag, out ErrorRecord pushNupkgContainerRegistryError))
{
_cmdletPassedIn.WriteError(pushNupkgContainerRegistryError);
return;
Expand Down
11 changes: 10 additions & 1 deletion src/code/PublishPSResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Microsoft.PowerShell.PSResourceGet.UtilClasses;
using System;
using System.Diagnostics;
using System.Linq;
using System.Management.Automation;
using System.Net;
Expand Down Expand Up @@ -117,6 +118,12 @@ public PSCredential ProxyCredential {
[ValidateNotNullOrEmpty]
public string NupkgPath { get; set; }

[Parameter]
public SwitchParameter Latest { get; set; }

[Parameter]
public SwitchParameter LatestPreview { get; set; }

#endregion

#region DynamicParameters
Expand Down Expand Up @@ -169,7 +176,9 @@ protected override void BeginProcessing()
DestinationPath,
SkipModuleManifestValidate,
_cancellationToken,
_isNupkgPathSpecified);
_isNupkgPathSpecified,
Latest,
LatestPreview);

_publishHelper.CheckAllParameterPaths();
}
Expand Down

0 comments on commit 580bbac

Please sign in to comment.