@@ -56,15 +56,9 @@ public async Task ProcessCatalogYamlAsync(string repoName, string catalogIdentif
56
56
. Build ( ) ;
57
57
58
58
CatalogYaml catalogYaml = CreateCatalogYaml ( deserializer , out string filePath ) ;
59
+ CatalogYaml autoGeneratedCatalogYaml = CreateAutoGeneratedCatalogYaml ( deserializer , out string autoGenFilePath ) ;
59
60
60
- if ( String . IsNullOrWhiteSpace ( catalogIdentifier ) )
61
- {
62
- await CheckId ( catalogYaml ) ;
63
- }
64
- else
65
- {
66
- catalogYaml . Id = catalogIdentifier ;
67
- }
61
+ await CheckId ( catalogYaml , autoGeneratedCatalogYaml , catalogIdentifier ) ;
68
62
69
63
await CheckShortDescription ( catalogYaml ) ;
70
64
@@ -76,8 +70,13 @@ public async Task ProcessCatalogYamlAsync(string repoName, string catalogIdentif
76
70
CheckType ( catalogYaml , parsedRepoName ) ;
77
71
78
72
string outputPath = filePath ?? fs . Path . Combine ( workspace , "catalog.yml" ) ;
73
+ string autoGeneratedOutputPath = autoGenFilePath ?? fs . Path . Combine ( workspace , ".githubtocatalog" , "auto-generated-catalog.yml" ) ;
79
74
75
+ // Save both the catalog.yml and the auto-generated-catalog.yml
76
+ // The auto-generated-catalog.yml will be committed & pushed by the pipeline when changed.
80
77
SaveFile ( catalogYaml , serializer , outputPath ) ;
78
+ SaveFile ( catalogYaml , serializer , autoGeneratedOutputPath ) ;
79
+ logger . LogInformation ( $ "Finished. Updated or Created auto-generated file with path: { outputPath } ") ;
81
80
logger . LogInformation ( $ "Finished. Updated or Created file with path: { outputPath } ") ;
82
81
}
83
82
@@ -86,18 +85,25 @@ public async Task ProcessCatalogYamlAsync(string repoName, string catalogIdentif
86
85
/// </summary>
87
86
/// <param name="catalogYaml">The catalog YAML object to check and update.</param>
88
87
/// <returns>A task that represents the asynchronous operation.</returns>
89
- private async Task CheckId ( CatalogYaml catalogYaml )
88
+ private async Task CheckId ( CatalogYaml catalogYaml , CatalogYaml autoGeneratedCatalogYaml , string catalogIdentifier )
90
89
{
91
- logger . LogDebug ( "Checking if ID exists , otherwise retrieve or create it..." ) ;
90
+ logger . LogDebug ( "Checking if ID was user provided , otherwise retrieve or create it..." ) ;
92
91
if ( String . IsNullOrWhiteSpace ( catalogYaml . Id ) )
93
92
{
94
- var catalogId = await service . GetCatalogIdentifierAsync ( ) ;
93
+ var catalogId = catalogIdentifier ;
95
94
if ( String . IsNullOrWhiteSpace ( catalogId ) )
96
95
{
97
- logger . LogDebug ( "Creating new ID..." ) ;
98
- catalogId = Guid . NewGuid ( ) . ToString ( ) ;
99
- await service . CreateCatalogIdentifierAsync ( catalogId ) ;
100
- logger . LogDebug ( "New Catalog ID created and stored in GitHub Variable." ) ;
96
+ if ( String . IsNullOrWhiteSpace ( autoGeneratedCatalogYaml . Id ) )
97
+ {
98
+ logger . LogDebug ( "Creating new ID..." ) ;
99
+ catalogId = Guid . NewGuid ( ) . ToString ( ) ;
100
+ logger . LogDebug ( "New Catalog ID created." ) ;
101
+ }
102
+ else
103
+ {
104
+ logger . LogDebug ( "ID was previously generated and retrieved from auto-generated-catalog.yml." ) ;
105
+ catalogId = autoGeneratedCatalogYaml . Id ;
106
+ }
101
107
}
102
108
103
109
catalogYaml . Id = catalogId ;
@@ -249,6 +255,40 @@ private CatalogYaml CreateCatalogYaml(IDeserializer deserializer, out string fou
249
255
return deserializer . Deserialize < CatalogYaml > ( yamlContent ) ?? new CatalogYaml ( ) ;
250
256
}
251
257
258
+ /// <summary>
259
+ /// Creates a new catalog YAML object by reading the existing catalog.yml or manifest.yml file in the workspace.
260
+ /// If no file is found, it creates an empty catalog YAML object.
261
+ /// </summary>
262
+ /// <param name="deserializer">The YAML deserializer to parse the existing YAML file.</param>
263
+ /// <param name="foundFile">The path to the found YAML file, or null if no file is found.</param>
264
+ /// <returns>The deserialized <see cref="CatalogYaml"/> object, or a new object if no file is found.</returns>
265
+ private CatalogYaml CreateAutoGeneratedCatalogYaml ( IDeserializer deserializer , out string foundFile )
266
+ {
267
+ logger . LogDebug ( "Checking if " ) ;
268
+ foundFile = null ;
269
+
270
+ string filePath = fs . Path . Combine ( workspace , ".githubtocatalog" , "auto-generated-catalog.yml" ) ;
271
+ if ( ! fs . File . Exists ( filePath ) )
272
+ {
273
+ logger . LogDebug ( "No existing auto-generated configuration file found." ) ;
274
+ }
275
+ else
276
+ {
277
+ foundFile = filePath ;
278
+ logger . LogDebug ( $ "Found auto-generated file at: { filePath } ") ;
279
+ }
280
+
281
+ if ( String . IsNullOrWhiteSpace ( foundFile ) )
282
+ {
283
+ return new CatalogYaml ( ) ;
284
+ }
285
+
286
+ var yamlContent = fs . File . ReadAllText ( filePath ) ;
287
+ logger . LogDebug ( "Existing Configuration File Parsed." ) ;
288
+ return deserializer . Deserialize < CatalogYaml > ( yamlContent ) ?? new CatalogYaml ( ) ;
289
+ }
290
+
291
+
252
292
/// <summary>
253
293
/// Infers the artifact content type based on the provided keyword. It checks if the keyword is in the artifact type map and returns the corresponding content type.
254
294
/// </summary>
@@ -262,7 +302,7 @@ private static string InferArtifactContentType(string keyword)
262
302
return contentType ;
263
303
}
264
304
265
- return Constants . ArtifactTypeMap . FirstOrDefault ( pair => pair . Value . Equals ( keyword , StringComparison . OrdinalIgnoreCase ) ) . Key ??
305
+ return Constants . ArtifactTypeMap . FirstOrDefault ( pair => pair . Value . Equals ( keyword , StringComparison . OrdinalIgnoreCase ) ) . Value ??
266
306
String . Empty ;
267
307
}
268
308
0 commit comments