Skip to content

Commit dbb2476

Browse files
committed
Cleanup
1 parent 7c672dd commit dbb2476

8 files changed

+62
-51
lines changed

Sdk/CatalogService/CatalogServiceFactory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class CatalogServiceFactory
1515
/// <returns>An instance of <see cref="ICatalogService"/> to communicate with the Skyline DataMiner Catalog (https://catalog.dataminer.services/).</returns>
1616
public static ICatalogService CreateWithHttp(HttpClient httpClient)
1717
{
18-
var environment = Environment.GetEnvironmentVariable("Skyline-deploy-action-namespace");
18+
var environment = Environment.GetEnvironmentVariable("override-api-dataminer-services");
1919

2020
string apiBaseUrl;
2121
if (environment != null)

Sdk/CatalogService/HttpCatalogService.cs

+5-10
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private sealed class CatalogUploadResult
3131
/// <summary>
3232
/// Artifact information returned from registering an artifact to the catalog.
3333
/// </summary>
34-
private sealed class CatalolRegisterResult
34+
private sealed class CatalogRegisterResult
3535
{
3636
[JsonProperty("catalogId")]
3737
public string CatalogId { get; set; }
@@ -107,7 +107,6 @@ public async Task<ArtifactUploadResult> RegisterCatalogAsync(byte[] catalogDetai
107107
ms.Position = 0;
108108
formData.Add(new StreamContent(ms), "file", "catalogDetails.zip");
109109

110-
111110
// Make PUT request
112111
var response = await _httpClient.PutAsync(RegistrationPath, formData, cancellationToken).ConfigureAwait(false);
113112

@@ -116,8 +115,8 @@ public async Task<ArtifactUploadResult> RegisterCatalogAsync(byte[] catalogDetai
116115

117116
if (response.IsSuccessStatusCode)
118117
{
119-
var returnedResult = JsonConvert.DeserializeObject<CatalolRegisterResult>(await response.Content.ReadAsStringAsync().ConfigureAwait(false));
120-
return new ArtifactUploadResult() { ArtifactId = returnedResult.CatalogId };
118+
var returnedResult = JsonConvert.DeserializeObject<CatalogRegisterResult>(await response.Content.ReadAsStringAsync().ConfigureAwait(false));
119+
return new ArtifactUploadResult { ArtifactId = returnedResult.CatalogId };
121120
}
122121

123122
if (response.StatusCode is HttpStatusCode.Forbidden || response.StatusCode is HttpStatusCode.Unauthorized)
@@ -154,14 +153,10 @@ public async Task<ArtifactUploadResult> UploadVersionAsync(byte[] package, strin
154153
};
155154
formData.Add(fileContent);
156155

157-
158156
// Add version information to the form data
159157
formData.Add(new StringContent(version), "versionNumber");
160158
formData.Add(new StringContent(description), "versionDescription");
161159

162-
// Log the info for debugging
163-
string logInfo = $"name {fileName} --versionNumber {version} --versionDescription {description}";
164-
165160
// Make the HTTP POST request
166161
var response = await _httpClient.PostAsync(versionUploadPath, formData, cancellationToken).ConfigureAwait(false);
167162

@@ -171,15 +166,15 @@ public async Task<ArtifactUploadResult> UploadVersionAsync(byte[] package, strin
171166
if (response.IsSuccessStatusCode)
172167
{
173168
var returnedResult = JsonConvert.DeserializeObject<CatalogUploadResult>(await response.Content.ReadAsStringAsync().ConfigureAwait(false));
174-
return new ArtifactUploadResult() { ArtifactId = returnedResult.AzureStorageId };
169+
return new ArtifactUploadResult { ArtifactId = returnedResult.AzureStorageId };
175170
}
176171

177172
if (response.StatusCode is HttpStatusCode.Forbidden || response.StatusCode is HttpStatusCode.Unauthorized)
178173
{
179174
throw new AuthenticationException($"The version upload api returned a {response.StatusCode} response. Body: {body}");
180175
}
181176

182-
if(response.StatusCode is HttpStatusCode.Conflict && body.Contains("already exists."))
177+
if (response.StatusCode is HttpStatusCode.Conflict && body.Contains("already exists."))
183178
{
184179
throw new VersionAlreadyExistsException(version);
185180
}

Sdk/Helpers/ProjectReferencesHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private static List<string> ResolveProjectReferences(string xmlFilePath, string
7373
JsonDocument jsonFilter = JsonDocument.Parse(json);
7474

7575
if (jsonFilter.RootElement.TryGetProperty("solution", out JsonElement solution) && solution.TryGetProperty("projects", out JsonElement projects)
76-
&& projects.ValueKind== JsonValueKind.Array)
76+
&& projects.ValueKind == JsonValueKind.Array)
7777
{
7878
foreach (JsonElement project in projects.EnumerateArray())
7979
{

Sdk/Sdk.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<BuildOutputTargetFolder>Sdk</BuildOutputTargetFolder>
2424
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
2525
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
26-
<PackageVersion>0.2.8</PackageVersion>
26+
<PackageVersion>0.1.0</PackageVersion>
2727
</PropertyGroup>
2828

2929
<ItemGroup>
@@ -42,7 +42,7 @@
4242
<PackageReference Include="Skyline.DataMiner.CICD.Common" Version="1.0.5-alpha" PrivateAssets="all" />
4343
<PackageReference Include="Skyline.DataMiner.CICD.Parsers.Common" Version="1.0.13-foxtrot" PrivateAssets="all" />
4444
<PackageReference Include="Skyline.DataMiner.CICD.Assemblers.Automation" Version="1.0.16-alpha" PrivateAssets="all" />
45-
<PackageReference Include="Skyline.DataMiner.Core.AppPackageCreator" Version="2.0.0-alpha2" PrivateAssets="all" />
45+
<PackageReference Include="Skyline.DataMiner.Core.AppPackageCreator" Version="2.0.0-alpha3" PrivateAssets="all" />
4646
<PackageReference Include="System.Text.Json" Version="9.0.0" PrivateAssets="all" />
4747
</ItemGroup>
4848

Sdk/Tasks/CatalogInformation.cs

+22-18
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class CatalogInformation : Task, ICancelableTask
3131
#endregion Properties set from targets file
3232

3333
/// <summary>
34-
/// Cancel the ongoing task
34+
/// Cancel the ongoing task.
3535
/// </summary>
3636
public void Cancel()
3737
{
@@ -49,28 +49,32 @@ public override bool Execute()
4949
// Early cancel if necessary
5050
return true;
5151
}
52-
// zip the CatalogInformation if it exists.
52+
53+
// Zip the CatalogInformation if it exists.
5354
var fs = FileSystem.Instance;
5455
var catalogInformationFolder = fs.Path.Combine(ProjectDirectory, "CatalogInformation");
5556

56-
if (fs.Directory.Exists(catalogInformationFolder))
57+
if (!fs.Directory.Exists(catalogInformationFolder))
5758
{
58-
// Store zip in bin\{Debug/Release} folder, similar like nupkg files.
59-
string baseLocation = BaseOutputPath;
60-
if (!fs.Path.IsPathRooted(BaseOutputPath))
61-
{
62-
// Relative path (starting from project directory
63-
baseLocation = fs.Path.GetFullPath(fs.Path.Combine(ProjectDirectory, BaseOutputPath));
64-
}
59+
// No CatalogInformation folder found, nothing to zip.
60+
return true;
61+
}
6562

66-
string destinationFilePath = fs.Path.Combine(baseLocation, Configuration, $"{PackageId}.{PackageVersion}.CatalogInformation.zip");
67-
fs.Directory.CreateDirectory(fs.Path.GetDirectoryName(destinationFilePath));
63+
// Store zip in bin\{Debug/Release} folder, similar like nupkg files.
64+
string baseLocation = BaseOutputPath;
65+
if (!fs.Path.IsPathRooted(BaseOutputPath))
66+
{
67+
// Relative path (starting from project directory
68+
baseLocation = fs.Path.GetFullPath(fs.Path.Combine(ProjectDirectory, BaseOutputPath));
69+
}
6870

69-
fs.File.DeleteFile(destinationFilePath);
70-
ZipFile.CreateFromDirectory(catalogInformationFolder, destinationFilePath, CompressionLevel.Optimal, includeBaseDirectory: false);
71+
string destinationFilePath = fs.Path.Combine(baseLocation, Configuration, $"{PackageId}.{PackageVersion}.CatalogInformation.zip");
72+
fs.Directory.CreateDirectory(fs.Path.GetDirectoryName(destinationFilePath));
7173

72-
Log.LogMessage(MessageImportance.Low, $"CatalogInformation zipped to {destinationFilePath}");
73-
}
74+
fs.File.DeleteFile(destinationFilePath);
75+
ZipFile.CreateFromDirectory(catalogInformationFolder, destinationFilePath, CompressionLevel.Optimal, includeBaseDirectory: false);
76+
77+
Log.LogMessage(MessageImportance.High, $"Successfully created zip '{destinationFilePath}'.");
7478

7579
if (cancel)
7680
{
@@ -81,13 +85,13 @@ public override bool Execute()
8185
}
8286
catch (Exception e)
8387
{
84-
Log.LogError($"Unexpected exception occurred during catalog information creation: {e}");
88+
Log.LogError($"Unexpected exception occurred during catalog information creation for '{PackageId}': {e}");
8589
return false;
8690
}
8791
finally
8892
{
8993
timer.Stop();
90-
Log.LogMessage(MessageImportance.High, $"Catalog information creation took {timer.ElapsedMilliseconds} ms.");
94+
Log.LogMessage(MessageImportance.High, $"Catalog information creation for '{PackageId}' took {timer.ElapsedMilliseconds} ms.");
9195
}
9296
}
9397
}

Sdk/Tasks/DmappCreation.cs

+12-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@ public class DmappCreation : Task, ICancelableTask
3535
#region Properties set from targets file
3636

3737
public string ProjectFile { get; set; }
38+
3839
public string ProjectType { get; set; }
40+
3941
public string BaseOutputPath { get; set; }
42+
4043
public string Configuration { get; set; } // Release or Debug
44+
4145
public string PackageId { get; set; } // If not specified, defaults to AssemblyName, which defaults to ProjectName
46+
4247
public string PackageVersion { get; set; } // If not specified, defaults to Version, which defaults to VersionPrefix, which defaults to '1.0.0'
48+
4349
public string MinimumRequiredDmVersion { get; set; }
4450

4551
#endregion
@@ -113,19 +119,21 @@ public override bool Execute()
113119
string about = package.CreatePackage(destinationFilePath);
114120
Log.LogMessage(MessageImportance.Low, $"About created package:{Environment.NewLine}{about}");
115121

122+
Log.LogMessage(MessageImportance.High, $"Successfully created package '{destinationFilePath}'.");
123+
116124
return !Log.HasLoggedErrors;
117125
}
118126
catch (Exception e)
119127
{
120-
Log.LogError($"Unexpected exception occurred during package creation: {e}");
128+
Log.LogError($"Unexpected exception occurred during package creation for '{PackageId}': {e}");
121129
return false;
122130
}
123131
finally
124132
{
125133
FileSystem.Instance.Directory.DeleteDirectory(preparedData.TemporaryDirectory);
126134

127135
timer.Stop();
128-
Log.LogMessage(MessageImportance.High, $"Package creation took {timer.ElapsedMilliseconds} ms.");
136+
Log.LogMessage(MessageImportance.High, $"Package creation for '{PackageId}' took {timer.ElapsedMilliseconds} ms.");
129137
}
130138
}
131139

@@ -243,7 +251,6 @@ private void IncludeFromPackageContent(AppPackage.AppPackageBuilder appPackageBu
243251
foreach (string zipFile in FileSystem.Instance.Directory.GetFiles(directory, "*.zip"))
244252
{
245253
appPackageBuilder.WithZip(zipFile, contentType);
246-
Log.LogMessage($"Added {contentType}: {zipFile}");
247254
}
248255
}
249256

@@ -272,15 +279,15 @@ private bool TryCreateAppPackageBuilder(PackageCreationData preparedData, DataMi
272279
}
273280

274281
/// <summary>
275-
/// Cancel the ongoing task
282+
/// Cancel the ongoing task.
276283
/// </summary>
277284
public void Cancel()
278285
{
279286
cancel = true;
280287
}
281288

282289
/// <summary>
283-
/// Prepare incoming data, so it is more usable for 'subtasks'
290+
/// Prepare incoming data, so it is more usable for 'subtasks'.
284291
/// </summary>
285292
/// <returns></returns>
286293
private PackageCreationData PrepareData()

Sdk/Tasks/PublishToCatalog.cs

+19-14
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class PublishToCatalog : Task, ICancelableTask
4343
#endregion Properties set from targets file
4444

4545
/// <summary>
46-
/// Cancel the ongoing task
46+
/// Cancel the ongoing task.
4747
/// </summary>
4848
public void Cancel()
4949
{
@@ -61,7 +61,8 @@ public override bool Execute()
6161
// Early cancel if necessary
6262
return true;
6363
}
64-
// zip the CatalogInformation if it exists.
64+
65+
// Zip the CatalogInformation if it exists.
6566
var fs = FileSystem.Instance;
6667

6768
// Store zip in bin\{Debug/Release} folder, similar like nupkg files.
@@ -75,8 +76,8 @@ public override bool Execute()
7576
string packagePath = FileSystem.Instance.Path.Combine(baseLocation, Configuration, $"{PackageId}.{PackageVersion}.dmapp");
7677
string catalogInfoPath = fs.Path.Combine(baseLocation, Configuration, $"{PackageId}.{PackageVersion}.CatalogInformation.zip");
7778

78-
Log.LogMessage(MessageImportance.High, $"Found Package: {packagePath}.");
79-
Log.LogMessage(MessageImportance.High, $"Found Catalog Information: {catalogInfoPath}.");
79+
Log.LogMessage($"Found Package: {packagePath}.");
80+
Log.LogMessage($"Found Catalog Information: {catalogInfoPath}.");
8081

8182
var builder = new ConfigurationBuilder();
8283

@@ -91,7 +92,7 @@ public override bool Execute()
9192

9293
if (String.IsNullOrWhiteSpace(CatalogPublishKeyName))
9394
{
94-
Log.LogError($"Unable to publish. Missing the property CatalogPublishKeyName that defines the name of a user-secret holding the datminer.services organization key.'");
95+
Log.LogError($"Unable to publish for '{PackageId}'. Missing the property CatalogPublishKeyName that defines the name of a user-secret holding the dataminer.services organization key.'");
9596
return false;
9697
}
9798

@@ -100,11 +101,11 @@ public override bool Execute()
100101
if (String.IsNullOrWhiteSpace(organizationKey))
101102
{
102103
string expectedEnvironmentVariable = CatalogPublishKeyName.Replace(":", "__");
103-
Log.LogError($"Unable to publish. Missing a project User Secret {CatalogPublishKeyName} or environment variable {expectedEnvironmentVariable} holding the dataminer.services organization key.");
104+
Log.LogError($"Unable to publish for '{PackageId}'. Missing a project User Secret {CatalogPublishKeyName} or environment variable {expectedEnvironmentVariable} holding the dataminer.services organization key.");
104105
return false;
105106
}
106107

107-
Log.LogMessage(MessageImportance.Low, $"Catalog Organization Identified.");
108+
Log.LogMessage(MessageImportance.Low, $"Catalog organization identified for '{PackageId}'.");
108109

109110
// Publish only changes to ReadMe or a new version?
110111
// Request if Version already exists? If not, then release a new version?
@@ -114,22 +115,25 @@ public override bool Execute()
114115
{
115116
var catalogService = CatalogServiceFactory.CreateWithHttp(new System.Net.Http.HttpClient());
116117
byte[] catalogData = fs.File.ReadAllBytes(catalogInfoPath);
117-
Log.LogMessage(MessageImportance.High, $"Registering Catalog Metadata...");
118+
119+
Log.LogMessage($"Registering Catalog Metadata for '{PackageId}'...");
118120
var catalogResult = catalogService.RegisterCatalogAsync(catalogData, organizationKey, cts.Token).WaitAndUnwrapException();
119-
Log.LogMessage(MessageImportance.High, $"Done");
121+
122+
Log.LogMessage(MessageImportance.High, $"Successfully registered Catalog Metadata for '{PackageId}'.");
120123

121124
try
122125
{
123-
Log.LogMessage(MessageImportance.High, $"Uploading new version to {catalogResult.ArtifactId}...");
126+
Log.LogMessage($"Uploading new version to {catalogResult.ArtifactId} for '{PackageId}'...");
124127
byte[] packageData = fs.File.ReadAllBytes(packagePath);
125128
catalogService.UploadVersionAsync(packageData, fs.Path.GetFileName(packagePath), organizationKey, catalogResult.ArtifactId, PackageVersion, VersionComment, cts.Token).WaitAndUnwrapException();
126-
Log.LogMessage(MessageImportance.High, $"Done");
129+
Log.LogMessage(MessageImportance.High, $"Successfully uploaded version '{PackageVersion}' to Catalog for '{PackageId}' ({catalogResult.ArtifactId}).");
127130
}
128131
catch (VersionAlreadyExistsException)
129132
{
130-
Log.LogWarning("Version already exists! Only catalog details were updated.");
133+
Log.LogWarning($"Version '{PackageVersion}' already exists for '{PackageId}'! Only catalog details were updated.");
131134
}
132135
}
136+
133137
if (cancel)
134138
{
135139
return false;
@@ -139,13 +143,14 @@ public override bool Execute()
139143
}
140144
catch (Exception e)
141145
{
142-
Log.LogError($"Unexpected exception occurred during Catalog Publish: {e}");
146+
Log.LogError($"Unexpected exception occurred during Catalog Publish for '{PackageId}': {e}");
143147
return false;
144148
}
145149
finally
146150
{
147151
timer.Stop();
148-
Log.LogMessage(MessageImportance.High, $"Catalog Publish took {timer.ElapsedMilliseconds} ms.");
152+
153+
Log.LogMessage(MessageImportance.High, $"Catalog Publish for '{PackageId}' took {timer.ElapsedMilliseconds} ms.");
149154
}
150155
}
151156
}

0 commit comments

Comments
 (0)