Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tool to generate changelog for Azure SDK for Dotnet #6033

Merged
merged 18 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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