@@ -239,6 +239,7 @@ function CreateStableVersionUpdatePullRequest {
239
239
[Parameter (Mandatory = $true )][string ]$gitRepository ,
240
240
[Parameter (Mandatory = $true )][string ]$tag ,
241
241
[Parameter ()][string ]$targetBranch = " main" ,
242
+ [Parameter ()][string ]$lineEnding = " `n " ,
242
243
[Parameter ()][string ]$gitUserName ,
243
244
[Parameter ()][string ]$gitUserEmail
244
245
)
@@ -249,7 +250,7 @@ function CreateStableVersionUpdatePullRequest {
249
250
throw ' Could not parse version from tag'
250
251
}
251
252
252
- $packageVersion = $match.Groups [1 ].Value
253
+ $version = $match.Groups [1 ].Value
253
254
254
255
$branch = " release/post-stable-${tag} -update"
255
256
@@ -268,17 +269,38 @@ function CreateStableVersionUpdatePullRequest {
268
269
throw ' git switch failure'
269
270
}
270
271
272
+ $projectsAndDependenciesBefore = GetCoreDependenciesForProjects
273
+
271
274
(Get-Content Directory.Packages.props) `
272
- -replace ' <OTelLatestStableVer>.*<\/OTelLatestStableVer>' , " <OTelLatestStableVer>$packageVersion </OTelLatestStableVer>" |
275
+ -replace ' <OTelLatestStableVer>.*<\/OTelLatestStableVer>' , " <OTelLatestStableVer>$version </OTelLatestStableVer>" |
273
276
Set-Content Directory.Packages.props
274
277
278
+ $projectsAndDependenciesAfter = GetCoreDependenciesForProjects
279
+
280
+ $changedProjects = @ {}
281
+
282
+ $projectsAndDependenciesBefore.GetEnumerator () | ForEach-Object {
283
+ $projectDir = $_.Key
284
+ $projectDependenciesBefore = $_.Value
285
+ $projectDependenciesAfter = $projectsAndDependenciesAfter [$projectDir ]
286
+
287
+ $projectDependenciesBefore.GetEnumerator () | ForEach-Object {
288
+ $packageName = $_.Key
289
+ $packageVersionBefore = $_.Value
290
+ if ($projectDependenciesAfter [$packageName ] -ne $packageVersionBefore )
291
+ {
292
+ $changedProjects [$projectDir ] = $true
293
+ }
294
+ }
295
+ }
296
+
275
297
git add Directory.Packages.props 2>&1 | % ToString
276
298
if ($LASTEXITCODE -gt 0 )
277
299
{
278
300
throw ' git add failure'
279
301
}
280
302
281
- git commit - m " Update OTelLatestStableVer in Directory.Packages.props to $packageVersion ." 2>&1 | % ToString
303
+ git commit - m " Update OTelLatestStableVer in Directory.Packages.props to $version ." 2>&1 | % ToString
282
304
if ($LASTEXITCODE -gt 0 )
283
305
{
284
306
throw ' git commit failure'
@@ -298,19 +320,177 @@ Merge once packages are available on NuGet and the build passes.
298
320
299
321
## Changes
300
322
301
- * Sets `` OTelLatestStableVer`` in `` Directory.Packages.props`` to `` $packageVersion `` .
323
+ * Sets `` OTelLatestStableVer`` in `` Directory.Packages.props`` to `` $version `` .
302
324
"@
303
325
304
- gh pr create `
305
- -- title " [release] Core stable release $packageVersion updates" `
326
+ $createPullRequestResponse = gh pr create `
327
+ -- title " [release] Core stable release $version updates" `
306
328
-- body $body `
307
329
-- base $targetBranch `
308
330
-- head $branch `
309
331
-- label release
332
+
333
+ Write-Host $createPullRequestResponse
334
+
335
+ $match = [regex ]::Match($createPullRequestResponse , " \/pull\/(.*)$" )
336
+ if ($match.Success -eq $false )
337
+ {
338
+ throw ' Could not parse pull request number from gh pr create response'
339
+ }
340
+
341
+ $pullRequestNumber = $match.Groups [1 ].Value
342
+
343
+ if ($changedProjects.Count -eq 0 )
344
+ {
345
+ Return
346
+ }
347
+
348
+ $entry = @"
349
+ * Updated OpenTelemetry core component version(s) to `` $version `` .
350
+ ([#$pullRequestNumber ](https://github.com/$gitRepository /pull/$pullRequestNumber ))
351
+
352
+
353
+ "@
354
+
355
+ $lastLineBlank = $true
356
+ $changelogFilesUpdated = 0
357
+
358
+ foreach ($projectDir in $changedProjects.Keys )
359
+ {
360
+ $path = Join-Path - Path $projectDir - ChildPath " CHANGELOG.md"
361
+
362
+ if ([System.IO.File ]::Exists($path ) -eq $false )
363
+ {
364
+ Write-Host " No CHANGELOG found in $projectDir "
365
+ continue
366
+ }
367
+
368
+ $changelogContent = Get-Content - Path $path
369
+
370
+ $started = $false
371
+ $isRemoving = $false
372
+ $content = " "
373
+
374
+ foreach ($line in $changelogContent )
375
+ {
376
+ if ($line -like " ## Unreleased" -and $started -ne $true )
377
+ {
378
+ $started = $true
379
+ }
380
+ elseif ($line -like " ## *" -and $started -eq $true )
381
+ {
382
+ if ($lastLineBlank -eq $false )
383
+ {
384
+ $content += $lineEnding
385
+ }
386
+ $content += $entry
387
+ $started = $false
388
+ $isRemoving = $false
389
+ }
390
+ elseif ($started -eq $true -and ($line -like ' *Update* OpenTelemetry SDK version to*' -or $line -like ' *Updated OpenTelemetry core component version(s) to*' ))
391
+ {
392
+ $isRemoving = $true
393
+ continue
394
+ }
395
+
396
+ if ($line.StartsWith (' * ' ))
397
+ {
398
+ if ($isRemoving -eq $true )
399
+ {
400
+ $isRemoving = $false
401
+ }
402
+
403
+ if ($lastLineBlank -eq $false )
404
+ {
405
+ $content += $lineEnding
406
+ }
407
+ }
408
+
409
+ if ($isRemoving -eq $true )
410
+ {
411
+ continue
412
+ }
413
+
414
+ $content += $line + $lineEnding
415
+
416
+ $lastLineBlank = [string ]::IsNullOrWhitespace($line )
417
+ }
418
+
419
+ if ($started -eq $true )
420
+ {
421
+ # Note: If we never wrote the entry it means the file ended in the unreleased section
422
+ if ($lastLineBlank -eq $false )
423
+ {
424
+ $content += $lineEnding
425
+ }
426
+ $content += $entry
427
+ }
428
+
429
+ Set-Content - Path $path - Value $content.TrimEnd ()
430
+
431
+ git add $path 2>&1 | % ToString
432
+ if ($LASTEXITCODE -gt 0 )
433
+ {
434
+ throw ' git add failure'
435
+ }
436
+
437
+ $changelogFilesUpdated ++
438
+ }
439
+
440
+ if ($changelogFilesUpdated -gt 0 )
441
+ {
442
+ git commit - m " Update CHANGELOGs for projects using OTelLatestStableVer." 2>&1 | % ToString
443
+ if ($LASTEXITCODE -gt 0 )
444
+ {
445
+ throw ' git commit failure'
446
+ }
447
+
448
+ git push - u origin $branch 2>&1 | % ToString
449
+ if ($LASTEXITCODE -gt 0 )
450
+ {
451
+ throw ' git push failure'
452
+ }
453
+ }
310
454
}
311
455
312
456
Export-ModuleMember - Function CreateStableVersionUpdatePullRequest
313
457
458
+ function GetCoreDependenciesForProjects {
459
+ $projects = @ (Get-ChildItem - Path ' src/*/*.csproj' )
460
+
461
+ $projectsAndDependencies = @ {}
462
+
463
+ foreach ($project in $projects )
464
+ {
465
+ # Note: dotnet restore may fail if the core packages aren't available yet but that is fine, we just want to generate project.assets.json for these projects.
466
+ $output = dotnet restore $project - p:RunningDotNetPack= true
467
+
468
+ $projectDir = $project | Split-Path - Parent
469
+
470
+ $content = (Get-Content " $projectDir /obj/project.assets.json" - Raw)
471
+
472
+ $projectDependencies = @ {}
473
+
474
+ $matches = [regex ]::Matches($content , ' "(OpenTelemetry(?:.*))?": {[\S\s]*?"target": "Package",[\S\s]*?"version": "(.*)"[\S\s]*?}' )
475
+ foreach ($match in $matches )
476
+ {
477
+ $packageName = $match.Groups [1 ].Value
478
+ $packageVersion = $match.Groups [2 ].Value
479
+ if ($packageName -eq ' OpenTelemetry' -or
480
+ $packageName -eq ' OpenTelemetry.Api' -or
481
+ $packageName -eq ' OpenTelemetry.Api.ProviderBuilderExtensions' -or
482
+ $packageName -eq ' OpenTelemetry.Extensions.Hosting' -or
483
+ $packageName -eq ' OpenTelemetry.Extensions.Propagators' )
484
+ {
485
+ $projectDependencies [$packageName.ToString ()] = $packageVersion.ToString ()
486
+ }
487
+ }
488
+ $projectsAndDependencies [$projectDir.ToString ()] = $projectDependencies
489
+ }
490
+
491
+ return $projectsAndDependencies
492
+ }
493
+
314
494
function InvokeCoreVersionUpdateWorkflowInRemoteRepository {
315
495
param (
316
496
[Parameter (Mandatory = $true )][string ]$remoteGitRepository ,
0 commit comments