Skip to content

Commit

Permalink
Merge branch 'dev' into 1147-TheChangelogBiggus
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Aug 20, 2023
2 parents fc6bb1b + d42e30e commit ec3bb8a
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 47 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ jobs:
echo -e "\nPROJECT_NUMBER = $VERSION\nINPUT = .\nOUTPUT_DIRECTORY = ./doxout\nPROJECT_LOGO = ./build/tgs.ico\nHAVE_DOT=YES" >> "docs/Doxyfile"
- name: Doxygen Build
uses: mattnotmitt/doxygen-action@v1
uses: mattnotmitt/doxygen-action@411df0c62acb5b96b8a93d93a7bf4b753c47ea05 # v1.9.5
with:
doxyfile-path: 'docs/Doxyfile'

Expand Down Expand Up @@ -1254,7 +1254,7 @@ jobs:
name: Deploy HTTP API
needs: deployment-gate
runs-on: windows-latest
if: (!(cancelled() || failure()) && needs.deployment-gate.result == 'success' && github.event_name == 'push' && contains(github.event.head_commit.message, '[APIDeploy]'))
if: (!(cancelled() || failure()) && needs.deployment-gate.result == 'success' && contains(github.event.head_commit.message, '[APIDeploy]'))
steps:
- name: Setup dotnet
uses: actions/setup-dotnet@v2
Expand Down Expand Up @@ -1319,7 +1319,7 @@ jobs:
name: Deploy DreamMaker API
needs: deployment-gate
runs-on: windows-latest
if: (!(cancelled() || failure()) && needs.deployment-gate.result == 'success' && github.event_name == 'push' && contains(github.event.head_commit.message, '[DMDeploy]'))
if: (!(cancelled() || failure()) && needs.deployment-gate.result == 'success' && contains(github.event.head_commit.message, '[DMDeploy]'))
steps:
- name: Setup dotnet
uses: actions/setup-dotnet@v2
Expand Down Expand Up @@ -1383,7 +1383,7 @@ jobs:
name: Deploy Nuget Packages
needs: deployment-gate
runs-on: ubuntu-latest
if: (!(cancelled() || failure()) && needs.upload-code-coverage.result == 'success' && needs.validate-openapi-spec.result == 'success' && github.event_name == 'push' && contains(github.event.head_commit.message, '[NugetDeploy]'))
if: (!(cancelled() || failure()) && needs.deployment-gate.result == 'success' && contains(github.event.head_commit.message, '[NugetDeploy]'))
steps:
- name: Setup dotnet
uses: actions/setup-dotnet@v2
Expand Down
7 changes: 7 additions & 0 deletions tools/Tgstation.Server.ReleaseNotes/Changelist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;

namespace Tgstation.Server.ReleaseNotes
{
Expand Down Expand Up @@ -42,5 +43,11 @@ public void DeduplicateChanges()
})
.ToList();
}

public void StripConfigVersionMessage()
{
foreach (var change in Changes)
change.Descriptions.RemoveAll(desc => Regex.IsMatch(desc, "The new config.* version is"));
}
}
}
6 changes: 3 additions & 3 deletions tools/Tgstation.Server.ReleaseNotes/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
{
enum Component
{
Configuration,
Core,
HostWatchdog,
WebControlPanel,
HttpApi,
Configuration,
DreamMakerApi,
InteropApi,
WebControlPanel,
HostWatchdog,
NugetCommon,
NugetApi,
NugetClient,
Expand Down
132 changes: 92 additions & 40 deletions tools/Tgstation.Server.ReleaseNotes/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,18 @@ static async Task<int> Main(string[] args)
{
newNotes.Append(Environment.NewLine);
newNotes.Append("#### ");
string componentName = GetComponentDisplayName(I.Key);
string componentName = GetComponentDisplayName(I.Key, false);
newNotes.Append(componentName);

if (I.Key == Component.Configuration)
{
I.Value.StripConfigVersionMessage();
newNotes.AppendLine();
newNotes.Append("- **The new configuration version is `");
newNotes.Append(I.Value.Version);
newNotes.Append("`. Please update your `General:ConfigVersion` setting appropriately.**");
}

PrintChanges(newNotes, I.Value);

newNotes.Append(Environment.NewLine);
Expand Down Expand Up @@ -481,15 +490,15 @@ static async Task<int> Main(string[] args)
}
}

static string GetComponentDisplayName(Component component) => component switch
static string GetComponentDisplayName(Component component, bool debian) => component switch
{
Component.HttpApi => "HTTP API",
Component.InteropApi => "Interop API",
Component.Configuration => "**Configuration**",
Component.DreamMakerApi => "DreamMaker API",
Component.HostWatchdog => "Host Watchdog",
Component.Core => "Core",
Component.WebControlPanel => "Web Control Panel",
Component.HttpApi => debian ? "the HTTP API" : "HTTP API",
Component.InteropApi => debian ? "the Interop API" : "Interop API",
Component.Configuration => debian ? "the TGS configuration" : "**Configuration**",
Component.DreamMakerApi => debian ? "the DreamMaker API" : "DreamMaker API",
Component.HostWatchdog => debian ? "the Host Watchdog" : "Host Watchdog",
Component.Core => debian ? "the main server" : "Core",
Component.WebControlPanel => debian ? "the Web Control Panel" : "Web Control Panel",
_ => throw new Exception($"Unnamed Component: {component}"),
};

Expand Down Expand Up @@ -539,6 +548,14 @@ async Task<bool> ShouldGetExtendedComponentVersions()
|| fullPR.Number == 966
|| fullPR.Number == 1048
|| fullPR.Number == 1435
|| fullPR.Number == 1263
|| fullPR.Number == 1087
|| fullPR.Number == 1441
|| fullPR.Number == 1437
|| fullPR.Number == 1443
|| fullPR.Number == 1311
|| fullPR.Number == 1598
|| fullPR.Number == 1463
|| fullPR.Number == 1209; // some special tactics from before we were more stingent

return isReleasePR;
Expand Down Expand Up @@ -708,7 +725,7 @@ async Task CommitNotes(Component component, List<string> notes)

await previousTask;

Debug.Assert(!(await needExtendedComponentVersions) || changelists.Where(x => x.Key == Component.Core).All(x => x.Value.ComponentVersions != null && x.Value.ComponentVersions.Count > 0));
Debug.Assert(!(await needExtendedComponentVersions) || changelists.Where(x => x.Key == Component.Core).All(x => x.Value.ComponentVersions != null && x.Value.ComponentVersions.Count > 3));

return Tuple.Create(changelists.ToDictionary(kvp => kvp.Key, kvp => kvp.Value), await componentVersions, isReleasePR);
}
Expand Down Expand Up @@ -839,7 +856,7 @@ static async Task<T> RLR<T>(Func<Task<T>> func)
}
}

static async Task<List<T>> TripleCheckGitHubPagination<T>(Func<ApiOptions, Task<IReadOnlyList<T>>> apiCall, Func<T, long> idSelector)
static async Task<List<T>> TripleCheckGitHubPagination<T>(Func<ApiOptions, Task<IReadOnlyList<T>>> apiCall, Func<T, object> idSelector)
{
// I've seen GitHub pagination return incomplete result sets in the past
// It has an in-built pagination limit of 100
Expand All @@ -848,19 +865,19 @@ static async Task<List<T>> TripleCheckGitHubPagination<T>(Func<ApiOptions, Task<
PageSize = 100
};
var results = await RLR(() => apiCall(apiOptions));
var distinctEntries = new Dictionary<long, T>(results.Count);
var distinctEntries = new Dictionary<string, T>(results.Count);
foreach (var result in results)
distinctEntries.Add(idSelector(result), result);
distinctEntries.Add(idSelector(result).ToString(), result);

if (results.Count > 100)
{
results = await RLR(() => apiCall(apiOptions));
foreach (var result in results)
distinctEntries.TryAdd(idSelector(result), result);
distinctEntries.TryAdd(idSelector(result).ToString(), result);

results = await RLR(() => apiCall(apiOptions));
foreach (var result in results)
distinctEntries.TryAdd(idSelector(result), result);
distinctEntries.TryAdd(idSelector(result).ToString(), result);
}

return distinctEntries.Values.ToList();
Expand Down Expand Up @@ -1021,7 +1038,7 @@ async Task<ReleaseNotes> RunPRs()
});
}
else
Debug.Assert(finalResults[Component.Core].All(x => x.Version == milestoneVersion && x.ComponentVersions != null && x.ComponentVersions.Count > 0));
Debug.Assert(finalResults[Component.Core].All(x => x.Version == milestoneVersion && x.ComponentVersions != null && x.ComponentVersions.Count > 3));

var notes = new ReleaseNotes
{
Expand Down Expand Up @@ -1260,7 +1277,12 @@ static async Task<ReleaseNotes> GenerateNotes(IGitHubClient client, Dictionary<C
Debug.Assert(distinctCount == kvp.Value.Count);

foreach (var cl in kvp.Value)
{
cl.DeduplicateChanges();

if (kvp.Key == Component.Configuration)
cl.StripConfigVersionMessage();
}
}

return releaseNotes;
Expand Down Expand Up @@ -1361,6 +1383,10 @@ static async Task<int> ReleaseNuget(IGitHubClient client)

static async Task<int> GenDebianChangelog(IGitHubClient client, Version version, string outputPath, string currentSha)
{
var tagsTask = RLR(() => TripleCheckGitHubPagination<RepositoryTag>(
apiOptions => client.Repository.GetAllTags(RepoOwner, RepoName, apiOptions),
x => x.Name));
var currentRefTask = client.Repository.Commit.Get(RepoOwner, RepoName, currentSha);
var releaseNotes = await GenerateNotes(client);

// https://www.debian.org/doc/manuals/maint-guide/dreq.en.html#changelog
Expand All @@ -1382,15 +1408,15 @@ static async Task<int> GenDebianChangelog(IGitHubClient client, Version version,

var coreChangelists = releaseNotes
.Components[Component.Core]
.Where(x => x.Version >= debianPackageFirstRelease && !x.Unreleased)
.Where(x => x.Version >= debianPackageFirstRelease && (!x.Unreleased || x.Version == version))
.OrderByDescending(x => x.Version)
.ToList();

var currentReleaseChangelists = new List<Dictionary<Component, Changelist>>();
var currentReleaseChangelists = new List<SortedDictionary<Component, Changelist>>();

for (var i = 0; i < coreChangelists.Count; ++i)
{
var currentDic = new Dictionary<Component, Changelist>();
var currentDic = new SortedDictionary<Component, Changelist>();
currentReleaseChangelists.Insert(0, currentDic);
var nowRelease = coreChangelists[i];
var previousRelease = (i + 1) < coreChangelists.Count
Expand All @@ -1402,20 +1428,34 @@ static async Task<int> GenDebianChangelog(IGitHubClient client, Version version,
currentDic.Add(Component.Core, nowRelease);
foreach (var componentKvp in nowRelease.ComponentVersions)
{
var takeNotesFrom = previousRelease.ComponentVersions[componentKvp.Key];
var changesEnumerator = releaseNotes
.Components[componentKvp.Key]
.Where(changelist => changelist.Version > takeNotesFrom && changelist.Version <= componentKvp.Value)
.SelectMany(x => x.Changes)
.OrderBy(x => x.PullRequest);
var changelist = new Changelist
try
{
Version = componentKvp.Value,
Changes = changesEnumerator
.ToList(),
};
var component = componentKvp.Key;
if (component == Component.Core
|| component == Component.NugetClient
|| component == Component.NugetApi
|| component == Component.NugetCommon)
continue;

var takeNotesFrom = previousRelease.ComponentVersions[componentKvp.Key];
var changesEnumerator = releaseNotes
.Components[component]
.Where(changelist => changelist.Version > takeNotesFrom && changelist.Version <= componentKvp.Value)
.SelectMany(x => x.Changes)
.OrderBy(x => x.PullRequest);
var changelist = new Changelist
{
Version = componentKvp.Value,
Changes = changesEnumerator
.ToList(),
};

currentDic.Add(componentKvp.Key, changelist);
currentDic.Add(component, changelist);
}
catch when (Debugger.IsAttached)
{
Debugger.Break();
}
}
}

Expand All @@ -1427,8 +1467,6 @@ static async Task<int> GenDebianChangelog(IGitHubClient client, Version version,
.Select(x => GetPR(client, x))
.ToList();

var currentRefTask = client.Repository.Commit.Get(RepoOwner, RepoName, currentSha);

await Task.WhenAll(allPrTasks);

var prDict = allPrTasks.ToDictionary(x => x.Result.Number, x => x.Result);
Expand All @@ -1449,28 +1487,42 @@ static async Task<int> GenDebianChangelog(IGitHubClient client, Version version,

builder.Append($"tgstation-server (");

builder.Append(version);
builder.Append(releaseDictionary[Component.Core].Version);
builder.Append("-1) unstable; urgency=");
builder.Append(urgency);

foreach (var kvp in releaseDictionary)
{
builder.AppendLine();
if (kvp.Key != Component.Core)
builder.AppendLine();
builder.Append(" * The following changes are for ");
builder.Append(GetComponentDisplayName(kvp.Key, true));
if(kvp.Key == Component.Configuration)
{
builder.AppendLine();
builder.Append(" * The following changes are for the ");
builder.Append(GetComponentDisplayName(kvp.Key));
builder.Append(':');
builder.Append(". You ");
if (kvp.Value.Version.Minor == 0 && kvp.Value.Version.Build == 0)
builder.Append("will need to");
else
builder.Append("should");
builder.Append(" update your `General:ConfigVersion` setting in `/etc/tgstation-server/appsettings.Production.yml` to this new version");
}

builder.Append(':');

PrintChanges(builder, kvp.Value, true);
}

builder.AppendLine();
builder.Append(" -- ");

var currentRef = await currentRefTask;
GitHubCommit currentRef;
var tags = await tagsTask;
var releaseTag = tags.FirstOrDefault(x => x.Name == $"tgstation-server-v{releaseDictionary[Component.Core].Version}");

if (releaseTag != null)
currentRef = await client.Repository.Commit.Get(RepoOwner, RepoName, releaseTag.Commit.Sha);
else
currentRef = await currentRefTask;

var committer = currentRef.Commit.Committer;
if (committer.Name == "GitHub" && committer.Email == "noreply@github.com")
Expand Down

0 comments on commit ec3bb8a

Please sign in to comment.