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

Update multiple SDK version properties #706

Merged
merged 3 commits into from
Jan 16, 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
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/DotNetSdkUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,12 @@ export class DotNetSdkUpdater {
// Apply the update to the file system.
// A simple string replace is used to avoid accidentally changing line endings
// in a way that might conflict with git config or .gitattributes settings.
const json = globalJson.replace(`"${versions.current.sdkVersion}"`, `"${versions.latest.sdkVersion}"`);
// A regular expression is used so that all matches are updated, not just the first;
// see https://github.com/dotnet/aspnetcore/pull/53424/files#r1454015608.
const parts = versions.current.sdkVersion.split('.');
const escapedVersion = parts.join('\\.');
const searchValue = new RegExp(`\\"${escapedVersion}\\"`, 'g');
const json = globalJson.replace(searchValue, `"${versions.latest.sdkVersion}"`);

await fs.promises.writeFile(this.options.globalJsonPath, json, { encoding: 'utf8' });
core.info(`Updated SDK version in '${this.options.globalJsonPath}' to ${versions.latest.sdkVersion}`);
Expand Down
121 changes: 121 additions & 0 deletions tests/__snapshots__/main.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1016,3 +1016,124 @@ exports[`update-dotnet-sdk daily builds for channel "8.0.1xx-preview7" running t
exports[`update-dotnet-sdk daily builds for channel "8.0.1xx-preview7" running the action the security output is correct 1`] = `"false"`;

exports[`update-dotnet-sdk daily builds for channel "8.0.1xx-preview7" running the action updates the SDK version in global.json 1`] = `"8.0.100-preview.7.23376.3"`;

exports[`update-dotnet-sdk daily builds for channel "9.0" running the action generates the expected Git commit history 1`] = `
[
"Update .NET SDK",
"",
"Update .NET SDK to version 9.0.100-alpha.1.24066.6.",
"",
"---",
"updated-dependencies:",
"- dependency-name: Microsoft.NET.Sdk",
" dependency-type: direct:production",
" update-type: version-update:semver-patch",
"...",
"",
"Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>",
]
`;

exports[`update-dotnet-sdk daily builds for channel "9.0" running the action generates the expected GitHub step summary 1`] = `
"<h1>.NET SDK 9.0.100-alpha.1.24066.6</h1>
An update from version 9.0.100-alpha.1.24058.9 to 9.0.100-alpha.1.24066.6 of the .NET SDK is available.<br>
<br>
This version of the .NET SDK was released on 2024-01-16 (-144 days ago).<br>
<br>
<a href="https://github.com/dotnet/installer/commits/aa5f136790068f7c993e52801e7bd4477d228691">Release notes</a>
"
`;

exports[`update-dotnet-sdk daily builds for channel "9.0" running the action the branch-name output is correct 1`] = `"update-dotnet-sdk-9.0.100-alpha.1.24066.6"`;

exports[`update-dotnet-sdk daily builds for channel "9.0" running the action the pull-request-html-url output is correct 1`] = `"https://github.local/martincostello/update-dotnet-sdk/pull/42"`;

exports[`update-dotnet-sdk daily builds for channel "9.0" running the action the pull-request-number output is correct 1`] = `"42"`;

exports[`update-dotnet-sdk daily builds for channel "9.0" running the action the pull-requests-closed output is correct 1`] = `"[]"`;

exports[`update-dotnet-sdk daily builds for channel "9.0" running the action the sdk-updated output is correct 1`] = `"true"`;

exports[`update-dotnet-sdk daily builds for channel "9.0" running the action the sdk-version output is correct 1`] = `"9.0.100-alpha.1.24066.6"`;

exports[`update-dotnet-sdk daily builds for channel "9.0" running the action the security output is correct 1`] = `"false"`;

exports[`update-dotnet-sdk daily builds for channel "9.0" running the action updates the SDK version in global.json 1`] = `"9.0.100-alpha.1.24066.6"`;

exports[`update-dotnet-sdk when global.json contains multiple .NET SDK versions running the action generates the expected Git commit history 1`] = `
[
"Update .NET SDK",
"",
"Update .NET SDK to version 9.0.100-alpha.1.24066.6.",
"",
"---",
"updated-dependencies:",
"- dependency-name: Microsoft.NET.Sdk",
" dependency-type: direct:production",
" update-type: version-update:semver-patch",
"...",
"",
"Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>",
]
`;

exports[`update-dotnet-sdk when global.json contains multiple .NET SDK versions running the action generates the expected GitHub step summary 1`] = `
"<h1>.NET SDK 9.0.100-alpha.1.24066.6</h1>
An update from version 9.0.100-alpha.1.24058.9 to 9.0.100-alpha.1.24066.6 of the .NET SDK is available.<br>
<br>
This version of the .NET SDK was released on 2024-01-16 (-144 days ago).<br>
<br>
<a href="https://github.com/dotnet/installer/commits/aa5f136790068f7c993e52801e7bd4477d228691">Release notes</a>
"
`;

exports[`update-dotnet-sdk when global.json contains multiple .NET SDK versions running the action the branch-name output is correct 1`] = `"update-dotnet-sdk-9.0.100-alpha.1.24066.6"`;

exports[`update-dotnet-sdk when global.json contains multiple .NET SDK versions running the action the pull-request-html-url output is correct 1`] = `"https://github.local/martincostello/update-dotnet-sdk/pull/42"`;

exports[`update-dotnet-sdk when global.json contains multiple .NET SDK versions running the action the pull-request-number output is correct 1`] = `"42"`;

exports[`update-dotnet-sdk when global.json contains multiple .NET SDK versions running the action the pull-requests-closed output is correct 1`] = `"[]"`;

exports[`update-dotnet-sdk when global.json contains multiple .NET SDK versions running the action the sdk-updated output is correct 1`] = `"true"`;

exports[`update-dotnet-sdk when global.json contains multiple .NET SDK versions running the action the sdk-version output is correct 1`] = `"9.0.100-alpha.1.24066.6"`;

exports[`update-dotnet-sdk when global.json contains multiple .NET SDK versions running the action the security output is correct 1`] = `"false"`;

exports[`update-dotnet-sdk when global.json contains multiple .NET SDK versions running the action updates the SDK version in global.json 1`] = `"9.0.100-alpha.1.24066.6"`;

exports[`update-dotnet-sdk when global.json contains multiple .NET SDK versions running the action updates the global.json file correctly 1`] = `
"{
"sdk": {
"version": "9.0.100-alpha.1.24066.6"
},
"tools": {
"dotnet": "9.0.100-alpha.1.24066.6",
"runtimes": {
"dotnet/x86": [
"$(MicrosoftNETCoreBrowserDebugHostTransportVersion)"
],
"dotnet": [
"$(MicrosoftNETCoreBrowserDebugHostTransportVersion)"
]
},
"Git": "2.22.0",
"jdk": "11.0.3",
"vs": {
"version": "17.2",
"components": [
"Microsoft.VisualStudio.Component.VC.ATL",
"Microsoft.VisualStudio.Component.VC.ATL.ARM64",
"Microsoft.VisualStudio.Component.VC.Tools.ARM64",
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
]
},
"xcopy-msbuild": "17.1.0"
},
"msbuild-sdks": {
"Microsoft.DotNet.Arcade.Sdk": "9.0.0-beta.24062.5",
"Microsoft.DotNet.Helix.Sdk": "9.0.0-beta.24062.5"
}
}"
`;
129 changes: 129 additions & 0 deletions tests/fixtures/daily-9.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
"scenarios": [
{
"basePath": "https://aka.ms",
"path": "/dotnet/9.0/daily/sdk-productVersion.txt",
"response": "9.0.100-alpha.1.24066.6\n",
"responseHeaders": {
"content-type": "text/plain"
}
},
{
"basePath": "https://dotnetbuilds.azureedge.net",
"path": "/public/Sdk/9.0.100-alpha.1.24058.9/productCommit-win-x64.json",
"response": {
"installer": {
"commit": "de96ee60b3aaa290c817df7e21ee7cb38c1cf2dd",
"version": "9.0.100-alpha.1.24058.9"
},
"runtime": {
"commit": "21b4a8585362c1bc12d545b63e62a0d9dd4e8673",
"version": "9.0.0-alpha.1.24057.2"
},
"aspnetcore": {
"commit": "e1758535a7f9922a61a919ebbc26be06f70fa5a1",
"version": "9.0.0-alpha.1.24058.4"
},
"windowsdesktop": {
"commit": "cd813382efc14c011d79679a654d77f5743d7769",
"version": "9.0.0-alpha.1.24056.2"
},
"sdk": {
"commit": "4b6d1c2371ee0296df15c72dff4c7ea64315bfe6",
"version": "9.0.100-alpha.1.24058.9"
}
}
},
{
"basePath": "https://dotnetbuilds.azureedge.net",
"path": "/public/Sdk/9.0.100-alpha.1.24066.6/productCommit-win-x64.json",
"response": {
"installer": {
"commit": "aa5f136790068f7c993e52801e7bd4477d228691",
"version": "9.0.100-alpha.1.24066.6"
},
"runtime": {
"commit": "22ba7d607bb1d9caa0db9afcdc47eb5cef641fcb",
"version": "9.0.0-alpha.1.24061.26"
},
"aspnetcore": {
"commit": "a19c70eba3f89c7cbe9447f029b4c63322f47846",
"version": "9.0.0-alpha.1.24061.8"
},
"windowsdesktop": {
"commit": "35043947917c50e301196493f952d08600e3fd4d",
"version": "9.0.0-alpha.1.24061.5"
},
"sdk": {
"commit": "231e921dd53cb4f57acfae42b5984e4103d6b557",
"version": "9.0.100-alpha.1.24062.7"
}
}
},
{
"basePath": "https://github.local",
"path": "/api/v3/repos/martincostello/update-dotnet-sdk/pulls",
"method": "POST",
"headers": {
"authorization": "token my-token"
},
"body": {
"title": "Update .NET SDK to 9.0.100-alpha.1.24066.6",
"head": "update-dotnet-sdk-9.0.100-alpha.1.24066.6",
"base": "main",
"body": "Updates the .NET SDK to version `9.0.100-alpha.1.24066.6`, which also updates the .NET runtime from version [``9.0.0-alpha.1.24057.2``](https://github.com/dotnet/installer/commits/de96ee60b3aaa290c817df7e21ee7cb38c1cf2dd) to version [``9.0.0-alpha.1.24061.26``](https://github.com/dotnet/installer/commits/aa5f136790068f7c993e52801e7bd4477d228691).\n\nThis pull request was auto-generated by [GitHub Actions](https://github.local/martincostello/update-dotnet-sdk/actions/runs/123).",
"maintainer_can_modify": true,
"draft": false
},
"status": 201,
"response": {
"number": 42,
"title": "Update .NET SDK to 9.0.100-alpha.1.24066.6",
"html_url": "https://github.local/martincostello/update-dotnet-sdk/pull/42",
"user": {
"login": "github-actions[bot]"
},
"head": {
"ref": "update-dotnet-sdk-9.0.100-alpha.1.24066.6"
},
"base": {
"ref": "main"
}
}
},
{
"basePath": "https://github.local",
"path": "/api/v3/repos/martincostello/update-dotnet-sdk/issues/42/labels",
"method": "POST",
"headers": {
"authorization": "token my-token"
},
"body": {
"labels": [
"foo",
"bar"
]
},
"status": 201,
"response": []
},
{
"basePath": "https://github.local",
"path": "/api/v3/repos/martincostello/update-dotnet-sdk/pulls?base=main&direction=desc&state=open",
"response": [
{
"url": "https://github.local/api/v3/repos/martincostello/update-dotnet-sdk/pulls/42",
"number": 42,
"state": "open",
"title": "Update .NET SDK to 9.0.100-alpha.1.24066.6",
"user": {
"login": "github-actions[bot]"
},
"head": {
"ref": "update-dotnet-sdk-9.0.100-alpha.1.24066.6"
}
}
]
}
]
}
96 changes: 90 additions & 6 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,11 @@ describe('update-dotnet-sdk', () => {
});

describe.each([
['daily', '8.0'],
['daily', '8.0.1xx'],
['daily', '8.0.1xx-preview7'],
])('%s builds for channel "%s"', (quality: string, channel: string) => {
const sdkVersion = '8.0.100-preview.6.23330.14';

['daily', '8.0', '8.0.100-preview.6.23330.14'],
['daily', '8.0.1xx', '8.0.100-preview.6.23330.14'],
['daily', '8.0.1xx-preview7', '8.0.100-preview.6.23330.14'],
['daily', '9.0', '9.0.100-alpha.1.24058.9'],
])('%s builds for channel "%s"', (quality: string, channel: string, sdkVersion: string) => {
let fixture: ActionFixture;

beforeAll(async () => {
Expand Down Expand Up @@ -254,4 +253,89 @@ describe('update-dotnet-sdk', () => {
});
});
});

describe('when global.json contains multiple .NET SDK versions', () => {
let fixture: ActionFixture;

beforeAll(async () => {
const content = `{
"sdk": {
"version": "9.0.100-alpha.1.24058.9"
},
"tools": {
"dotnet": "9.0.100-alpha.1.24058.9",
"runtimes": {
"dotnet/x86": [
"$(MicrosoftNETCoreBrowserDebugHostTransportVersion)"
],
"dotnet": [
"$(MicrosoftNETCoreBrowserDebugHostTransportVersion)"
]
},
"Git": "2.22.0",
"jdk": "11.0.3",
"vs": {
"version": "17.2",
"components": [
"Microsoft.VisualStudio.Component.VC.ATL",
"Microsoft.VisualStudio.Component.VC.ATL.ARM64",
"Microsoft.VisualStudio.Component.VC.Tools.ARM64",
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
]
},
"xcopy-msbuild": "17.1.0"
},
"msbuild-sdks": {
"Microsoft.DotNet.Arcade.Sdk": "9.0.0-beta.24062.5",
"Microsoft.DotNet.Helix.Sdk": "9.0.0-beta.24062.5"
}
}`;

fixture = new ActionFixture(undefined, content);

fixture.channel = '9.0';
fixture.quality = 'daily';

await fixture.initialize('daily-9.0');
});

afterAll(async () => {
await fixture?.destroy();
});

describe('running the action', () => {
beforeAll(async () => {
await fixture.run();
}, timeout);

test('generates no errors', () => {
expect(core.error).toHaveBeenCalledTimes(0);
expect(core.setFailed).toHaveBeenCalledTimes(0);
});

test('updates the global.json file correctly', async () => {
const content = await fixture.sdkContent();
const globalJson = JSON.parse(content);
expect(globalJson.sdk.version).toBe('9.0.100-alpha.1.24066.6');
expect(globalJson.tools.dotnet).toBe('9.0.100-alpha.1.24066.6');
expect(content).toMatchSnapshot();
});

test('updates the SDK version in global.json', async () => {
expect(await fixture.sdkVersion()).toMatchSnapshot();
});

test('generates the expected Git commit history', async () => {
expect(await fixture.commitHistory(1)).toMatchSnapshot();
});

test('generates the expected GitHub step summary', async () => {
expect(fixture.stepSummary).toMatchSnapshot();
});

test.each(inputs)('the %s output is correct', (name: string) => {
expect(fixture.getOutput(name)).toMatchSnapshot();
});
});
});
});