generated from credfeto/cs-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from credfeto/feat/fix-read-me
Checking changelog insert positions
- Loading branch information
Showing
11 changed files
with
233 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,13 +19,32 @@ jobs: | |
include-changelog-entry: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/[email protected] | ||
with: | ||
fetch-depth: 0 | ||
- if: ${{ github.actor != 'dependabot-preview[bot]' }} | ||
uses: Zomzog/[email protected] | ||
with: | ||
fileName: CHANGELOG.md | ||
noChangelogLabel: Changelog Not Required | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: actions/[email protected] | ||
with: | ||
fetch-depth: 0 | ||
- if: ${{ github.actor != 'dependabot[bot]' }} | ||
uses: Zomzog/[email protected] | ||
with: | ||
fileName: CHANGELOG.md | ||
noChangelogLabel: Changelog Not Required | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
change-log-entry-is-in-unreleased: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/[email protected] | ||
with: | ||
fetch-depth: 0 | ||
- uses: credfeto/[email protected] | ||
- uses: actions/setup-dotnet@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
dotnet-version: ${{ env.DOTNET_VERSION }} | ||
- name: Enable dotnet tools | ||
run: dotnet new tool-manifest | ||
- name: Install Changelog tool | ||
run: dotnet tool install --local Credfeto.ChangeLog.Cmd | ||
- name: Check Changelog | ||
run: dotnet changelog -changelog D:\Work\changelog-manager\CHANGELOG.md -check-insert ${{ github.base_ref}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,20 @@ | ||
# cs-template | ||
C# Template | ||
# Changelog manager .net tool | ||
|
||
## Installation | ||
|
||
```shell | ||
dotnet tool install Credfeto.ChangeLog.Cmd | ||
``` | ||
|
||
## Usage | ||
|
||
Extract the release notes for a pre-release build | ||
```shell | ||
dotnet changelog -changelog CHANGELOG.md -extract RELEASE_NOTES.md -version 1.0.1.27-master | ||
``` | ||
|
||
Extract the release notes for a release build | ||
```shell | ||
dotnet changelog -changelog CHANGELOG.md -extract RELEASE_NOTES.md -version 1.0.2.77 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
|
||
namespace Credfeto.ChangeLog.Management | ||
{ | ||
public sealed class BranchMissingException : Exception | ||
{ | ||
public BranchMissingException() | ||
: this("Could not find branch") | ||
{ | ||
} | ||
|
||
public BranchMissingException(string message) | ||
: base(message) | ||
{ | ||
} | ||
|
||
public BranchMissingException(string message, Exception innerException) | ||
: base(message: message, innerException: innerException) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
using LibGit2Sharp; | ||
|
||
namespace Credfeto.ChangeLog.Management | ||
{ | ||
public static class ChangeLogChecker | ||
{ | ||
private static readonly Regex HunkPositionRegex = | ||
new Regex(pattern: @"^@@\s*\-(?<OriginalFileStart>\d*)(,(?<OriginalFileEnd>\d*))?\s*\+(?<CurrentFileStart>\d*)(,(?<CurrentFileChangeLength>\d*))?\s*@@", | ||
RegexOptions.Compiled | RegexOptions.Multiline); | ||
|
||
public static async Task<bool> ChangeLogModifiedInReleaseSectionAsync(string changeLogFileName, string originBranchName) | ||
{ | ||
int? position = await ChangeLogReader.FindFirstReleaseVersionPositionAsync(changeLogFileName); | ||
|
||
if (position == null) | ||
{ | ||
return false; | ||
} | ||
|
||
string changelogDir = Path.GetDirectoryName(changeLogFileName)!; | ||
|
||
using (Repository repo = OpenRepository(changelogDir)) | ||
{ | ||
string? sha = repo.Head.Tip.Sha; | ||
|
||
Branch? originBranch = repo.Branches.FirstOrDefault(b => b.FriendlyName == originBranchName); | ||
|
||
if (originBranch == null) | ||
{ | ||
throw new BranchMissingException($"Could not find branch {originBranchName}"); | ||
} | ||
|
||
if (originBranch.Tip.Sha == sha) | ||
{ | ||
// same branch/commit | ||
return false; | ||
} | ||
|
||
string changeLogInRepoPath = FindChangeLogPositionInRepo(repo: repo, changeLogFileName: changeLogFileName); | ||
|
||
int firstReleaseVersionIndex = position.Value; | ||
|
||
Patch changes = repo.Diff.Compare<Patch>(oldTree: originBranch.Tip.Tree, | ||
newTree: repo.Head.Tip.Tree, | ||
new CompareOptions {ContextLines = 0, InterhunkLines = 0, IncludeUnmodified = false}); | ||
|
||
foreach (var change in changes) | ||
{ | ||
if (change.Path == changeLogInRepoPath) | ||
{ | ||
string patchDetails = change.Patch; | ||
Console.WriteLine(patchDetails); | ||
|
||
MatchCollection matches = HunkPositionRegex.Matches(patchDetails); | ||
|
||
foreach (Match? match in matches) | ||
{ | ||
if (match == null) | ||
{ | ||
continue; | ||
} | ||
|
||
int changeStart = Convert.ToInt32(match.Groups["CurrentFileStart"] | ||
.Value); | ||
|
||
if (!int.TryParse(s: match.Groups["CurrentFileChangeLength"] | ||
.Value, | ||
out int changeLength)) | ||
{ | ||
changeLength = 1; | ||
} | ||
|
||
int changeEnd = changeStart + changeLength; | ||
|
||
if (changeEnd >= firstReleaseVersionIndex) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private static string FindChangeLogPositionInRepo(Repository repo, string changeLogFileName) | ||
{ | ||
return changeLogFileName.Substring(repo.Info.WorkingDirectory.Length) | ||
.Replace(oldValue: "\\", newValue: "/"); | ||
} | ||
|
||
private static Repository OpenRepository(string workDir) | ||
{ | ||
string found = Repository.Discover(workDir); | ||
|
||
return new Repository(found); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters