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

[IDP-2068] Automerge official dependency from microsoft #12

Merged
merged 19 commits into from
Sep 10, 2024
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
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
pull_request:
branches: ["main"]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
main:
runs-on: ubuntu-latest
Expand All @@ -18,4 +22,4 @@ jobs:
- name: Test with the dotnet CLI
run: dotnet test tests
env:
TEST_GITHUB_TOKEN: ${{secrets.TEST_GITHUB_TOKEN}}
GH_TOKEN: ${{secrets.TEST_GITHUB_MG}}
PrincessMadMath marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ This repository contains the shared renovate configurations.

The shared configurations are baselines. Each project is free to set their own rules on top of this configuration.

# Usage
## Usage

## GitHub projects
### GitHub projects

````json
{
Expand All @@ -17,7 +17,17 @@ The shared configurations are baselines. Each project is free to set their own r
}
````

# Azure DevOps
#### Enabling Auto-Merge Functionality for GitHub

Auto-merge has been set up using the [branch approach](https://docs.renovatebot.com/key-concepts/automerge/#branch-vs-pr-automerging), chosen to minimize noise and allow for the bypassing of PR review requirements.

For those utilizing branch protection rules on the default branch, specific adjustments are necessary to facilitate auto-merge capabilities for GitHub:

1. **Update Branch Policies**: Modify your branch protection settings to permit the account or service running Renovate to bypass pull request review requirements.

2. **Handling Status Checks**: If your repository enforces "Require status checks to pass before merging", be aware that Renovate will be unable to merge changes into the target branch if any of these checks fail. It will fallback to create a pull request.

### Azure DevOps

````json
{
Expand Down Expand Up @@ -63,4 +73,4 @@ steps:
- template: steps/renovate/renovate-template.yml@templates
parameters:
githubToken: $(GITHUB_COM_TOKEN)
````
````
15 changes: 15 additions & 0 deletions default.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@
}
],
"packageRules": [
{
"description": "Automatically merge minor and patch updates for Microsoft dependencies",
"matchUpdateTypes": ["minor", "patch"],
"automerge": true,
"automergeType": "branch",
"matchPackageNames": [
"dotnet-sdk",
"mcr.microsoft.com/dotnet/sdk",
"mcr.microsoft.com/dotnet/aspnet",
"mcr.microsoft.com/dotnet/runtime",
"mcr.microsoft.com/dotnet/runtime-deps",
"/^[mM]icrosoft\\./",
"/^[sS]ystem\\./"
]
},
{
"groupName": "gitversion-msbuild",
"description": "Disable major updates as their are breaking changes. The documentation is not complete, so it would require time to figure out the new configuration",
Expand Down
7 changes: 5 additions & 2 deletions tests/PullrequestsInfos.cs → tests/GitInfos.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace renovate_config.tests;

internal sealed record PullRequestInfos(string Title, IEnumerable<string> Labels, IEnumerable<PackageUpdateInfos> PackageUpdatesInfos);
internal sealed record PullRequestInfos(string Title, IEnumerable<string> Labels, IEnumerable<PackageUpdateInfos> PackageUpdatesInfos, bool isAutoMergeEnabled);

internal sealed record PackageUpdateInfos(string Package, string Type, string Update);

internal sealed record CommitInfo(string Message);

internal sealed record PackageUpdateInfos(string Package, string Type, string Update);
121 changes: 96 additions & 25 deletions tests/SystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,24 @@ public async Task RenovateDotnetSdkDependencies()
{
await using var testContext = await TestContext.CreateAsync(testOutputHelper);

testContext.AddCiFile();
testContext.AddFile("global.json", /*lang=json*/"""{"sdk": {"version": "6.0.100"}}""");
testContext.AddFile("Dockerfile",
"""
FROM mcr.microsoft.com/dotnet/sdk:6.0.100
FROM mcr.microsoft.com/dotnet/aspnet:6.0.0
""");

await testContext.PushFilesOnDefaultBranch();
await testContext.RunRenovate();

await testContext.WaitForLatestCommitChecksToSucceed();

// Need to run renovate a second time so that branch get merged
await testContext.RunRenovate();

await testContext.AssertPullRequests(
"""
- Title: chore(deps): update dotnet-sdk
Labels:
- renovate
PackageUpdatesInfos:
- Package: dotnet-sdk
Type: dotnet-sdk
Update: patch
- Package: mcr.microsoft.com/dotnet/aspnet
Type: final
Update: patch
- Package: mcr.microsoft.com/dotnet/sdk
Type: stage
Update: patch
- Title: chore(deps): update dotnet-sdk to redacted(major)
Labels:
- renovate
Expand All @@ -47,6 +41,11 @@ await testContext.AssertPullRequests(
Type: stage
Update: major
""");

await testContext.AssertCommits("""
- Message: chore(deps): update dotnet-sdk
- Message: IDP ScaffoldIt automated test
""");
}

[Fact]
Expand All @@ -68,6 +67,7 @@ public async Task RenovateHangfireDependencies()
</Project>
""");

await testContext.PushFilesOnDefaultBranch();
await testContext.RunRenovate();

await testContext.AssertPullRequests(
Expand Down Expand Up @@ -107,6 +107,7 @@ public async Task RenovatePackageJsonDependencies()
}
""");

await testContext.PushFilesOnDefaultBranch();
await testContext.RunRenovate();

await testContext.AssertPullRequests(
Expand All @@ -131,10 +132,10 @@ await testContext.AssertPullRequests(
}

[Fact]
public async Task RenovateMicrosoftDependencies()
public async Task Given_Microsoft_Major_Dependencies_Updates_Then_Open_PR()
{
await using var testContext = await TestContext.CreateAsync(testOutputHelper);

testContext.AddFile("project.csproj",
"""
<Project Sdk="Microsoft.NET.Sdk">
Expand All @@ -151,6 +152,7 @@ public async Task RenovateMicrosoftDependencies()
</Project>
""");

await testContext.PushFilesOnDefaultBranch();
await testContext.RunRenovate();

await testContext.AssertPullRequests(
Expand All @@ -162,16 +164,6 @@ await testContext.AssertPullRequests(
- Package: System.Text.Json
Type: nuget
Update: major
- Title: chore(deps): update microsoft
Labels:
- renovate
PackageUpdatesInfos:
- Package: microsoft.AspNetCore.Authentication.OpenIdConnect
Type: nuget
Update: patch
- Package: Microsoft.Azure.AppConfiguration.AspNetCore
Type: nuget
Update: minor
- Title: chore(deps): update microsoft (major)
Labels:
- renovate
Expand All @@ -184,6 +176,84 @@ await testContext.AssertPullRequests(
Update: major
""");
}

[Fact]
public async Task Given_Microsoft_Minor_Dependencies_Update_When_CI_Succeed_Then_AutoMerge_By_Pushing_On_Main()
{
await using var testContext = await TestContext.CreateAsync(testOutputHelper);

testContext.AddCiFile();

testContext.AddFile("CODEOWNERS",
"""
* @gsoft-inc/internal-developer-platform
""");

testContext.AddFile("project.csproj",
"""
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="8.0.0" />
</ItemGroup>
</Project>
""");

await testContext.PushFilesOnDefaultBranch();
await testContext.RunRenovate();

// Need to run renovate a second time so that branch is merged
// Need to pull commit status to see is check is completed
await testContext.WaitForLatestCommitChecksToSucceed();
await testContext.RunRenovate();

await testContext.AssertCommits("""
- Message: chore(deps): update dependency system.text.json to redacted[security]
- Message: IDP ScaffoldIt automated test
""");
}

[Fact]
public async Task Given_Microsoft_Minor_Dependencies_Update_When_CI_Fail_Then_Abort_AutoMerge_And_Fallback_To_Create_PR()
{
await using var testContext = await TestContext.CreateAsync(testOutputHelper);

testContext.AddFaillingCiFile();

testContext.AddFile("CODEOWNERS",
"""
* @gsoft-inc/internal-developer-platform
""");

testContext.AddFile("project.csproj",
"""
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="8.0.0" />
</ItemGroup>
</Project>
""");

await testContext.PushFilesOnDefaultBranch();


await testContext.RunRenovate();
await testContext.WaitForLatestCommitChecksToSucceed();

// Need to run renovate a second time to create PR on CI failures
await testContext.RunRenovate();

await testContext.AssertPullRequests(
"""
- Title: chore(deps): update dependency system.text.json to redacted[security]
Labels:
- security
PackageUpdatesInfos:
- Package: System.Text.Json
Type: nuget
Update: patch
isAutoMergeEnabled: true
""");
}

[Fact]
public async Task DisableGitVersionMsBuildPackage()
Expand All @@ -199,6 +269,7 @@ public async Task DisableGitVersionMsBuildPackage()
</Project>
""");

await testContext.PushFilesOnDefaultBranch();
await testContext.RunRenovate();

await testContext.AssertPullRequests("[]");
Expand Down
Loading