Skip to content

Commit

Permalink
Change the changelog section header to Dependencies, overridable by `…
Browse files Browse the repository at this point in the history
…changelog-section` input
  • Loading branch information
vaind committed Aug 21, 2022
1 parent 8ced2bd commit 7f315ad
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 26 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ on:
type: string
required: false
default: ''
changelog-section:
description: Section header to attach the changelog entry to.
type: string
required: false
default: Dependencies
runs-on:
description: GitHub Actions virtual environment name to run the udpater job on.
type: string
Expand Down Expand Up @@ -260,6 +265,7 @@ jobs:
-MainBranch '${{ steps.target.outputs.mainBranch }}' `
-OldTag '${{ steps.target.outputs.originalTag }}' `
-NewTag '${{ steps.target.outputs.latestTag }}'
-Section '${{ inputs.changelog-section }}'
- run: git --no-pager diff
if: steps.target.outputs.latestTag != steps.target.outputs.originalTag
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## Unreleased

### Features
### Dependencies

- n/a

29 changes: 15 additions & 14 deletions scripts/update-changelog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ param(
[Parameter(Mandatory = $true)][string] $RepoUrl,
[Parameter(Mandatory = $true)][string] $MainBranch,
[Parameter(Mandatory = $true)][string] $OldTag,
[Parameter(Mandatory = $true)][string] $NewTag
[Parameter(Mandatory = $true)][string] $NewTag,
[Parameter(Mandatory = $true)][string] $Section
)

Set-StrictMode -Version latest
Expand Down Expand Up @@ -48,7 +49,7 @@ for ($i = 0; $i -lt $lines.Count; $i++)
break
}

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

if (-not ($line -match "features"))
if (-not ($line -match $Section))
{
# If it's a version-specific section header but not "Features", skip all the items in this section
# If it's a version-specific section header but not the requested section header, skip all the items in this section
if ($line.StartsWith("###"))
{
for ($i = $i + 1; $i -lt $lines.Count - 1; $i++)
Expand All @@ -79,29 +80,29 @@ for ($i = 0; $i -lt $lines.Count; $i++)
}
}

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

# Find the last point in the first `Features` header
# Find the last point in the first requested section header
for ($i = 0; $i -lt $lines.Count; $i++)
{
$line = $lines[$i]
if ($line -match "Features")
if ($line -match $Section)
{
Write-Host "Found a Features header at $i"
Write-Host "Found a $Section header at $i"
# Find the next header and then go backward until we find a non-empty line
for ($i++; $i -lt $lines.Count -and -not $lines[$i].StartsWith("#"); $i++) {}
for ($i--; $i -gt 0 -and $lines[$i].Trim().Length -eq 0; $i--) {}
$i += ($lines[$i] -match "Features") ? 2 : 1
$i += ($lines[$i] -match $Section) ? 2 : 1
break
}
}

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

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

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

# First check if an existing entry for the same dependency exists among unreleased features - if so, update it instead of adding a new one.
# First check if an existing entry for the same dependency exists among unreleased $Section - if so, update it instead of adding a new one.
$updated = $false
for ($i = 0; $i -lt $sectionEnd; $i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* An existing
* Set of Fixes

### Features
### Dependencies

- Capture `Debug.LogError()` and `Debug.LogException()` also on background threads ([#673](https://github.com/getsentry/sentry-unity/pull/673))
- Adding override for Sentry CLI URL ([#666](https://github.com/getsentry/sentry-unity/pull/666))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* An existing
* Set of Fixes

### Features
### Dependencies

- Capture `Debug.LogError()` and `Debug.LogException()` also on background threads ([#673](https://github.com/getsentry/sentry-unity/pull/673))
- Adding override for Sentry CLI URL ([#666](https://github.com/getsentry/sentry-unity/pull/666))
Expand Down
4 changes: 2 additions & 2 deletions tests/testdata/changelog/new/CHANGELOG.md.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

## Unreleased

### Features
### Dependencies

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

## 0.14.0

### Features
### Dependencies

- Capture `Debug.LogError()` and `Debug.LogException()` also on background threads ([#673](https://github.com/getsentry/sentry-unity/pull/673))
- Adding override for Sentry CLI URL ([#666](https://github.com/getsentry/sentry-unity/pull/666))
2 changes: 1 addition & 1 deletion tests/testdata/changelog/new/CHANGELOG.md.original
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 0.14.0

### Features
### Dependencies

- Capture `Debug.LogError()` and `Debug.LogException()` also on background threads ([#673](https://github.com/getsentry/sentry-unity/pull/673))
- Adding override for Sentry CLI URL ([#666](https://github.com/getsentry/sentry-unity/pull/666))
4 changes: 2 additions & 2 deletions tests/testdata/changelog/update/CHANGELOG.md.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

## Unreleased

### Features
### Dependencies

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

## 0.14.0

### Features
### Dependencies

- Capture `Debug.LogError()` and `Debug.LogException()` also on background threads ([#673](https://github.com/getsentry/sentry-unity/pull/673))
- Adding override for Sentry CLI URL ([#666](https://github.com/getsentry/sentry-unity/pull/666))
4 changes: 2 additions & 2 deletions tests/testdata/changelog/update/CHANGELOG.md.original
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

## Unreleased

### Features
### Dependencies

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

## 0.14.0

### Features
### Dependencies

- Capture `Debug.LogError()` and `Debug.LogException()` also on background threads ([#673](https://github.com/getsentry/sentry-unity/pull/673))
- Adding override for Sentry CLI URL ([#666](https://github.com/getsentry/sentry-unity/pull/666))
5 changes: 3 additions & 2 deletions tests/update-changelog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ $testCases = Get-ChildItem "$PSScriptRoot/testdata/changelog/"
foreach ($testCase in $testCases)
{
RunTest $testCase {
cp "$testCase/CHANGELOG.md.original" "$testCase/CHANGELOG.md"
Copy-Item "$testCase/CHANGELOG.md.original" "$testCase/CHANGELOG.md"

pwsh -WorkingDirectory $testCase -File "$PSScriptRoot/../scripts/update-changelog.ps1" `
-Name 'Dependency' `
-PR 'https://github.com/getsentry/dependant/pulls/123' `
-RepoUrl 'https://github.com/getsentry/dependency' `
-MainBranch 'main' `
-OldTag '7.16.0' `
-NewTag '7.17.0'
-NewTag '7.17.0' `
-Section 'Dependencies'

AssertEqual (Get-Content "$testCase/CHANGELOG.md.expected") (Get-Content "$testCase/CHANGELOG.md")
}
Expand Down

0 comments on commit 7f315ad

Please sign in to comment.