Skip to content

Commit ee77c80

Browse files
authored
Change the changelog section header to Dependencies, overridable by changelog-section input (#19)
1 parent 8ced2bd commit ee77c80

File tree

10 files changed

+35
-27
lines changed

10 files changed

+35
-27
lines changed

.github/workflows/updater.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ on:
5454
type: string
5555
required: false
5656
default: ''
57+
changelog-section:
58+
description: Section header to attach the changelog entry to.
59+
type: string
60+
required: false
61+
default: Dependencies
5762
runs-on:
5863
description: GitHub Actions virtual environment name to run the udpater job on.
5964
type: string
@@ -259,7 +264,8 @@ jobs:
259264
-RepoUrl '${{ steps.target.outputs.url }}' `
260265
-MainBranch '${{ steps.target.outputs.mainBranch }}' `
261266
-OldTag '${{ steps.target.outputs.originalTag }}' `
262-
-NewTag '${{ steps.target.outputs.latestTag }}'
267+
-NewTag '${{ steps.target.outputs.latestTag }}' `
268+
-Section '${{ inputs.changelog-section }}'
263269
264270
- run: git --no-pager diff
265271
if: steps.target.outputs.latestTag != steps.target.outputs.originalTag

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
## Unreleased
55

6-
### Features
6+
### Dependencies
77

88
- n/a
99

scripts/update-changelog.ps1

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ param(
44
[Parameter(Mandatory = $true)][string] $RepoUrl,
55
[Parameter(Mandatory = $true)][string] $MainBranch,
66
[Parameter(Mandatory = $true)][string] $OldTag,
7-
[Parameter(Mandatory = $true)][string] $NewTag
7+
[Parameter(Mandatory = $true)][string] $NewTag,
8+
[Parameter(Mandatory = $true)][string] $Section
89
)
910

1011
Set-StrictMode -Version latest
@@ -48,7 +49,7 @@ for ($i = 0; $i -lt $lines.Count; $i++)
4849
break
4950
}
5051

51-
# Make sure that there's a `Features` header
52+
# Make sure that there's a the requested section header
5253
:outer for ($i = 0; $i -lt $lines.Count; $i++)
5354
{
5455
$line = $lines[$i]
@@ -62,12 +63,12 @@ for ($i = 0; $i -lt $lines.Count; $i++)
6263
# Next, we expect a header
6364
if (-not $line.StartsWith("#"))
6465
{
65-
throw "Unexpected changelog line - expecting a section header at this point, such as '### Features', but found: '$line'"
66+
throw "Unexpected changelog line - expecting a section header at this point, such as '### $Section', but found: '$line'"
6667
}
6768

68-
if (-not ($line -match "features"))
69+
if (-not ($line -match $Section))
6970
{
70-
# If it's a version-specific section header but not "Features", skip all the items in this section
71+
# If it's a version-specific section header but not the requested section header, skip all the items in this section
7172
if ($line.StartsWith("###"))
7273
{
7374
for ($i = $i + 1; $i -lt $lines.Count - 1; $i++)
@@ -79,29 +80,29 @@ for ($i = 0; $i -lt $lines.Count; $i++)
7980
}
8081
}
8182

82-
# add Features as the first sub-header
83-
Write-Host "Adding a new '### Features' section at line $i"
84-
$lines = $lines[0..($i - 1)] + @("### Features", "", "") + $lines[$i..($lines.Count - 1)]
83+
# add the section header as the first sub-header
84+
Write-Host "Adding a new '### $Section' section at line $i"
85+
$lines = $lines[0..($i - 1)] + @("### $Section", "", "") + $lines[$i..($lines.Count - 1)]
8586
}
8687
break
8788
}
8889

89-
# Find the last point in the first `Features` header
90+
# Find the last point in the first requested section header
9091
for ($i = 0; $i -lt $lines.Count; $i++)
9192
{
9293
$line = $lines[$i]
93-
if ($line -match "Features")
94+
if ($line -match $Section)
9495
{
95-
Write-Host "Found a Features header at $i"
96+
Write-Host "Found a $Section header at $i"
9697
# Find the next header and then go backward until we find a non-empty line
9798
for ($i++; $i -lt $lines.Count -and -not $lines[$i].StartsWith("#"); $i++) {}
9899
for ($i--; $i -gt 0 -and $lines[$i].Trim().Length -eq 0; $i--) {}
99-
$i += ($lines[$i] -match "Features") ? 2 : 1
100+
$i += ($lines[$i] -match $Section) ? 2 : 1
100101
break
101102
}
102103
}
103104

104-
# What line we want to insert at - the empty line at the end of the currently unreleased Features section.
105+
# What line we want to insert at - the empty line at the end of the currently unreleased section.
105106
$sectionEnd = $i
106107

107108
$tagAnchor = $NewTag.Replace('.', '')
@@ -110,7 +111,7 @@ $newTagNice = ($NewTag -match "^[0-9]") ? "v$NewTag" : $NewTag
110111

111112
$PullRequestMD = "[#$($PR | Split-Path -Leaf)]($PR)"
112113

113-
# First check if an existing entry for the same dependency exists among unreleased features - if so, update it instead of adding a new one.
114+
# First check if an existing entry for the same dependency exists among unreleased $Section - if so, update it instead of adding a new one.
114115
$updated = $false
115116
for ($i = 0; $i -lt $sectionEnd; $i++)
116117
{

tests/testdata/changelog/new-second-section/CHANGELOG.md.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* An existing
88
* Set of Fixes
99

10-
### Features
10+
### Dependencies
1111

1212
- Capture `Debug.LogError()` and `Debug.LogException()` also on background threads ([#673](https://github.com/getsentry/sentry-unity/pull/673))
1313
- Adding override for Sentry CLI URL ([#666](https://github.com/getsentry/sentry-unity/pull/666))

tests/testdata/changelog/new-second-section/CHANGELOG.md.original

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* An existing
88
* Set of Fixes
99

10-
### Features
10+
### Dependencies
1111

1212
- Capture `Debug.LogError()` and `Debug.LogException()` also on background threads ([#673](https://github.com/getsentry/sentry-unity/pull/673))
1313
- Adding override for Sentry CLI URL ([#666](https://github.com/getsentry/sentry-unity/pull/666))

tests/testdata/changelog/new/CHANGELOG.md.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
## Unreleased
44

5-
### Features
5+
### Dependencies
66

77
- Bump Dependency from v7.16.0 to v7.17.0 ([#123](https://github.com/getsentry/dependant/pulls/123))
88
- [changelog](https://github.com/getsentry/dependency/blob/main/CHANGELOG.md#7170)
99
- [diff](https://github.com/getsentry/dependency/compare/7.16.0...7.17.0)
1010

1111
## 0.14.0
1212

13-
### Features
13+
### Dependencies
1414

1515
- Capture `Debug.LogError()` and `Debug.LogException()` also on background threads ([#673](https://github.com/getsentry/sentry-unity/pull/673))
1616
- Adding override for Sentry CLI URL ([#666](https://github.com/getsentry/sentry-unity/pull/666))

tests/testdata/changelog/new/CHANGELOG.md.original

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 0.14.0
44

5-
### Features
5+
### Dependencies
66

77
- Capture `Debug.LogError()` and `Debug.LogException()` also on background threads ([#673](https://github.com/getsentry/sentry-unity/pull/673))
88
- Adding override for Sentry CLI URL ([#666](https://github.com/getsentry/sentry-unity/pull/666))

tests/testdata/changelog/update/CHANGELOG.md.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
## Unreleased
44

5-
### Features
5+
### Dependencies
66

77
- Bump Dependency to v7.17.0 ([#100](https://github.com/getsentry/dependant/pulls/100), [#123](https://github.com/getsentry/dependant/pulls/123))
88
- [changelog](https://github.com/getsentry/dependency/blob/main/CHANGELOG.md#7170)
99
- [diff](https://github.com/getsentry/dependency/compare/5.0.0...7.17.0)
1010

1111
## 0.14.0
1212

13-
### Features
13+
### Dependencies
1414

1515
- Capture `Debug.LogError()` and `Debug.LogException()` also on background threads ([#673](https://github.com/getsentry/sentry-unity/pull/673))
1616
- Adding override for Sentry CLI URL ([#666](https://github.com/getsentry/sentry-unity/pull/666))

tests/testdata/changelog/update/CHANGELOG.md.original

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
## Unreleased
44

5-
### Features
5+
### Dependencies
66

77
- Bump Dependency to v6.0.0 ([#100](https://github.com/getsentry/dependant/pulls/100))
88
- [changelog](https://github.com/getsentry/dependency/blob/main/CHANGELOG.md#600)
99
- [diff](https://github.com/getsentry/dependency/compare/5.0.0...6.0.0)
1010

1111
## 0.14.0
1212

13-
### Features
13+
### Dependencies
1414

1515
- Capture `Debug.LogError()` and `Debug.LogException()` also on background threads ([#673](https://github.com/getsentry/sentry-unity/pull/673))
1616
- Adding override for Sentry CLI URL ([#666](https://github.com/getsentry/sentry-unity/pull/666))

tests/update-changelog.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ $testCases = Get-ChildItem "$PSScriptRoot/testdata/changelog/"
77
foreach ($testCase in $testCases)
88
{
99
RunTest $testCase {
10-
cp "$testCase/CHANGELOG.md.original" "$testCase/CHANGELOG.md"
10+
Copy-Item "$testCase/CHANGELOG.md.original" "$testCase/CHANGELOG.md"
1111

1212
pwsh -WorkingDirectory $testCase -File "$PSScriptRoot/../scripts/update-changelog.ps1" `
1313
-Name 'Dependency' `
1414
-PR 'https://github.com/getsentry/dependant/pulls/123' `
1515
-RepoUrl 'https://github.com/getsentry/dependency' `
1616
-MainBranch 'main' `
1717
-OldTag '7.16.0' `
18-
-NewTag '7.17.0'
18+
-NewTag '7.17.0' `
19+
-Section 'Dependencies'
1920

2021
AssertEqual (Get-Content "$testCase/CHANGELOG.md.expected") (Get-Content "$testCase/CHANGELOG.md")
2122
}

0 commit comments

Comments
 (0)