Skip to content

Commit

Permalink
Add tool to generate changelog for Azure SDK for Dotnet (#6033)
Browse files Browse the repository at this point in the history
* Initial check-in for ChangelogGen (Tool to generate changelog for Azure SDK for Dotnet Mgmt plane)

* add support of api-version tag

* Update test for api-version tag

* add a simple readme.md

* 1. Only list obsoleted API change
2. Change merge mode from group to line
3. for GA release, the previous GA release will be used as baseline

* Update code per PR comments.

* fix ci after moving to tools folder

* Update readme file for supporting DataPlane in the next step

* Update markdown format of readme.md

* Update markdown format of readme.md2

* Update markdig to signed version

* include static method/property/type in the api compare

* rename folder to changelog-gen-for-net under tools\

* remove breaking changes from preview version

* 1. rename folder name to net-changelog-gen-mgmt
2. improve log
3. support same version of last release as the given one to improve the re-run user experience

* 1. shortcut api comparison for preview version which is not needed
2. fix a bug in method default value check
  • Loading branch information
RodgeFu authored Jun 5, 2023
1 parent 1011a0e commit fbd523b
Show file tree
Hide file tree
Showing 38 changed files with 20,220 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Azure.SDK.Management.ChangelogGen\Azure.SDK.Management.ChangelogGen.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="apiFile1.cs.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="apiFile2.cs.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="autorest1.md">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="changelog1.md">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="mergedChangelog1.md">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="specReadme.md">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.SDK.ChangelogGen.Compare;
using Azure.SDK.ChangelogGen.Report;

namespace Azure.SDK.ChangelogGen.Tests
{
[TestClass]
public class TestApiComparer
{
[TestMethod]
public void TestCompareApiFile()
{
string content1 = File.ReadAllText("apiFile1.cs.txt");
string content2 = File.ReadAllText("apiFile2.cs.txt");
ChangeLogResult r = new ChangeLogResult();
r.ApiChange = Program.CompareApi(content2, content1);
Release release = r.GenerateReleaseNote("1.2.3", "2030.3.3", filter: new List<ChangeCatogory>() { ChangeCatogory.Obsoleted });

// we dont expect any breaking change in our release
// But in case any breaking changes detected, we will list them anyway so that people are able to notice these unexpected breaking changes when reviewing the changelog and fix them
string baseline =
@"## 1.2.3 (2030.3.3)
### Breaking Changes
- Removed method 'String MethodToBeDeleted()' in type Azure.ResourceManager.AppService.TestMethod
- Removed method 'String MethodChangeDefaultValue(Int32 param = 0)' in type Azure.ResourceManager.AppService.TestMethod
- Removed method 'String MethodToChangeReturnType()' in type Azure.ResourceManager.AppService.TestMethod
- Removed method 'String MethodToChangeParameter()' in type Azure.ResourceManager.AppService.TestMethod
- Removed property 'String PropertyToBeDeleted' in type Azure.ResourceManager.AppService.TestProperty
- Removed property method 'Get' for 'String PropertyToChangeToSet' in type Azure.ResourceManager.AppService.TestProperty
- Removed property method 'Set' for 'String PropertyToChangeToGet' in type Azure.ResourceManager.AppService.TestProperty
- Removed type 'Azure.ResourceManager.AppService.TypeToBeDeleted'
### Other Changes
- Obsoleted method 'Void StaticMethodToBeObsoleted()' in type Azure.ResourceManager.AppService.StaticTypeToBeObsoleted
- Obsoleted method 'String MethodToBeObsoleted(String name, Int32 count, Boolean isEnabled, CancellationToken cancellationToken)' in type Azure.ResourceManager.AppService.TestMethod
- Obsoleted property 'String StaticPropertyToBeObsoleted' in type Azure.ResourceManager.AppService.StaticTypeToBeObsoleted
- Obsoleted property 'String PropertyToBeObsoleted' in type Azure.ResourceManager.AppService.TestProperty
- Obsoleted type 'Azure.ResourceManager.AppService.TypeToBeObsoleted'
- Obsoleted type 'Azure.ResourceManager.AppService.StaticTypeToBeObsoleted'";
string actual = release.ToString();
Assert.AreEqual(baseline.Replace("\r\n", "\n"), actual.Replace("\r\n", "\n"));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Azure.SDK.ChangelogGen.Compare;

namespace Azure.SDK.ChangelogGen.Tests
{
[TestClass]
public class TestCompareVersion
{
[TestMethod]
public void TestVersionEqual()
{
StringValueChange? result = Program.CompareVersion("1.0.1", "1.0.1", "test version equal");
Assert.IsNull(result);
}

[TestMethod]
public void TestVersionNotEqual()
{
StringValueChange? result = Program.CompareVersion("1.0.2", "1.0.1", "test version equal");
Assert.IsNotNull(result);
Assert.AreEqual("1.0.2", result.NewValue);
Assert.AreEqual("1.0.1", result.OldValue);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Azure.SDK.ChangelogGen.Report;

namespace Azure.SDK.ChangelogGen.Tests
{
[TestClass]
public class TestGetReleaseVersion
{
[TestMethod]
public void TestReleasesFromChangelogMdFile()
{
string content = File.ReadAllText("changelog1.md");
List<Release> releases = Release.FromChangelog(content);
Assert.AreEqual(7, releases.Count);

Assert.AreEqual("1.1.0-beta.1", releases[0].Version);
Assert.AreEqual("Unreleased", releases[0].ReleaseDate);

Assert.AreEqual("1.0.1", releases[1].Version);
Assert.AreEqual("2023-02-20", releases[1].ReleaseDate);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Azure.SDK.ChangelogGen.Utilities;

namespace Azure.SDK.ChangelogGen.Tests
{
[TestClass]
public class TestGetSpecVersion
{
[TestMethod]
public void TestGetSpecVersionFromMd()
{
var content = File.ReadAllText("autorest1.md");
List<string> tags = SpecHelper.GetSpecVersionTags(content, out string src);

Assert.AreEqual("./specReadme.md", src);
Assert.AreEqual(1, tags.Count);
Assert.AreEqual("package-2021-02", tags[0]);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.SDK.ChangelogGen.Compare;
using Azure.SDK.ChangelogGen.Report;

namespace Azure.SDK.ChangelogGen.Tests
{
[TestClass]
public class TestMergeChangeLog
{
[TestMethod]
public void TestMergeWithExistingNote()
{
string content1 = File.ReadAllText("apiFile1.cs.txt");
string content2 = File.ReadAllText("apiFile2.cs.txt");
ChangeLogResult r = new ChangeLogResult
{
ApiChange = Program.CompareApi(content2, content1),
AzureCoreVersionChange = new StringValueChange("1.1.0", "1.0.1", "Azure Core upgraded"),
AzureResourceManagerVersionChange = new StringValueChange("1.2.0", "1.0.2", "Azure RM upgraded"),
SpecVersionChange = new StringValueChange("2020-01-01", "2030-01-01", "spec upgraded")
};

Release newRelease = r.GenerateReleaseNote("1.2.3", "2099-09-10", new List<ChangeCatogory>() { ChangeCatogory.Obsoleted });

var releases = Release.FromChangelog(File.ReadAllText("changelog1.md"));

newRelease.MergeTo(releases[0], MergeMode.Group);

var mergedChangelog = Release.ToChangeLog(releases);
var baseline = File.ReadAllText("mergedChangelog1.md");
Assert.AreEqual(baseline.Replace("\r\n", "\n").TrimEnd('\r', '\n'), mergedChangelog.Replace("\r\n", "\n"));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;
Loading

0 comments on commit fbd523b

Please sign in to comment.