Skip to content

Commit

Permalink
Update daily build version retrieval
Browse files Browse the repository at this point in the history
Handle the installer being merged into the dotnet/sdk repository as of .NET 9 preview 6.
  • Loading branch information
martincostello committed Jun 1, 2024
1 parent da4fc46 commit e5c44fc
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 85 deletions.
114 changes: 57 additions & 57 deletions dist/main.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/main.js.map

Large diffs are not rendered by default.

66 changes: 42 additions & 24 deletions src/DotNetSdkUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class DotNetSdkUpdater {
quality: string | undefined,
releaseChannel: ReleaseChannel | null
): Promise<SdkVersions> {
const { sdkVersion, runtimeVersion, installerCommit } = await DotNetSdkUpdater.getDotNetDailyVersion(channel, quality);
const { sdkVersion, runtimeVersion, installerCommit, sdkCommit } = await DotNetSdkUpdater.getDotNetDailyVersion(channel, quality);

const security = false;
const securityIssues = [];
Expand All @@ -47,8 +47,17 @@ export class DotNetSdkUpdater {
return new Date(Date.UTC(year, month - 1, day));
};

const getReleaseNotes = (commit: string): string => {
return `https://github.com/dotnet/installer/commits/${commit}`;
const getReleaseNotes = (installerCommitSha: string | null, sdkCommitSha: string): string => {
let repo: string;
let commit: string;
if (installerCommitSha) {
repo = 'installer';
commit = installerCommitSha;
} else {
repo = 'sdk';
commit = sdkCommitSha;
}
return `https://github.com/dotnet/${repo}/commits/${commit}`;
};

let current: ReleaseInfo | null = null;
Expand All @@ -62,14 +71,11 @@ export class DotNetSdkUpdater {
}

if (!current) {
const {
installer: { commit: currentInstallerCommit },
runtime: { version: currentRuntimeVersion },
} = await DotNetSdkUpdater.getSdkProductCommits(currentSdkVersion);
const currentVersions = await DotNetSdkUpdater.getSdkProductCommits(currentSdkVersion);
current = {
releaseDate: getReleaseDate(currentSdkVersion),
releaseNotes: getReleaseNotes(currentInstallerCommit),
runtimeVersion: currentRuntimeVersion,
releaseNotes: getReleaseNotes(currentVersions.installer?.commit || null, currentVersions.sdk.commit),
runtimeVersion: currentVersions.runtime.version,
sdkVersion: currentSdkVersion,
security,
securityIssues,
Expand All @@ -78,7 +84,7 @@ export class DotNetSdkUpdater {

const latest: ReleaseInfo = {
releaseDate: getReleaseDate(sdkVersion),
releaseNotes: getReleaseNotes(installerCommit),
releaseNotes: getReleaseNotes(installerCommit, sdkCommit),
runtimeVersion,
sdkVersion,
security,
Expand Down Expand Up @@ -511,7 +517,8 @@ export class DotNetSdkUpdater {
channel: string,
quality: string | undefined
): Promise<{
installerCommit: string;
installerCommit: string | null;
sdkCommit: string;
runtimeVersion: string;
sdkVersion: string;
}> {
Expand Down Expand Up @@ -541,9 +548,10 @@ export class DotNetSdkUpdater {
const versions = await DotNetSdkUpdater.getSdkProductCommits(sdkVersion);

return {
installerCommit: versions.installer.commit,
installerCommit: versions.installer?.commit || null,
sdkCommit: versions.sdk.commit,
runtimeVersion: versions.runtime.version,
sdkVersion: versions.installer.version,
sdkVersion: versions.installer?.version || versions.sdk.version,
};
}

Expand Down Expand Up @@ -595,28 +603,38 @@ export class DotNetSdkUpdater {

const commits = await response.text();

const getValue = (component: string, property: string): string => {
const getValue = (component: string, property: string): string | null => {
const regex = new RegExp(`${component}_${property}="([^"]+)"`);
const match = commits.match(regex);
if (!match) {
throw new Error(`Failed to get ${component} ${property} for .NET SDK version ${sdkVersion}.`);
return null;
}
return match[1];
};

const getProduct = (component: string): ProductCommit => {
const getProduct = (component: string, optional = false): ProductCommit | null => {
const commit = getValue(component, 'commit');
const version = getValue(component, 'version');
if (!commit || !version) {
if (optional) {
return null;
}
throw new Error(`Failed to get product information for ${component} for .NET SDK version ${sdkVersion}.`);
}
return {
commit: getValue(component, 'commit'),
version: getValue(component, 'version'),
commit,
version,
};
};

return {
installer: getProduct('installer'),
runtime: getProduct('runtime'),
aspnetcore: getProduct('aspnetcore'),
windowsdesktop: getProduct('windowsdesktop'),
sdk: getProduct('sdk'),
installer: getProduct('installer', true),
/* eslint-disable @typescript-eslint/no-non-null-assertion */
runtime: getProduct('runtime')!,
aspnetcore: getProduct('aspnetcore')!,
windowsdesktop: getProduct('windowsdesktop')!,
sdk: getProduct('sdk')!,
/* eslint-enable @typescript-eslint/no-non-null-assertion */
};
}

Expand Down Expand Up @@ -882,7 +900,7 @@ interface ProductCommit {
}

interface SdkProductCommits {
installer: ProductCommit;
installer: ProductCommit | null; // See https://github.com/dotnet/sdk/pull/41316
runtime: ProductCommit;
aspnetcore: ProductCommit;
windowsdesktop: ProductCommit;
Expand Down
43 changes: 43 additions & 0 deletions tests/__snapshots__/main.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,49 @@ exports[`update-dotnet-sdk daily builds for channel "9.0" running the action the
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 daily builds for channel "9.0.1xx" running the action generates the expected Git commit history 1`] = `
[
"Update .NET SDK",
"",
"Update .NET SDK to version 9.0.100-preview.6.24281.7.",
"",
"---",
"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.1xx" running the action generates the expected GitHub step summary 1`] = `
"<h1>.NET SDK 9.0.100-preview.6.24281.7</h1>
An update from version 9.0.100-preview.5.24281.15 to 9.0.100-preview.6.24281.7 of the .NET SDK is available.<br>
<br>
This version of the .NET SDK was released on 2024-05-31 (-280 days ago).<br>
<br>
<a href="https://github.com/dotnet/sdk/commits/b0e9af0530394fff1237038efcdcdc2590bb9772">Release notes</a>
"
`;
exports[`update-dotnet-sdk daily builds for channel "9.0.1xx" running the action the branch-name output is correct 1`] = `"update-dotnet-sdk-9.0.100-preview.6.24281.7"`;
exports[`update-dotnet-sdk daily builds for channel "9.0.1xx" 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.1xx" running the action the pull-request-number output is correct 1`] = `"42"`;
exports[`update-dotnet-sdk daily builds for channel "9.0.1xx" running the action the pull-requests-closed output is correct 1`] = `"[]"`;
exports[`update-dotnet-sdk daily builds for channel "9.0.1xx" running the action the sdk-updated output is correct 1`] = `"true"`;
exports[`update-dotnet-sdk daily builds for channel "9.0.1xx" running the action the sdk-version output is correct 1`] = `"9.0.100-preview.6.24281.7"`;
exports[`update-dotnet-sdk daily builds for channel "9.0.1xx" running the action the security output is correct 1`] = `"false"`;
exports[`update-dotnet-sdk daily builds for channel "9.0.1xx" running the action updates the SDK version in global.json 1`] = `"9.0.100-preview.6.24281.7"`;
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",
Expand Down
125 changes: 125 additions & 0 deletions tests/fixtures/daily-9.0.1xx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"scenarios": [
{
"basePath": "https://aka.ms",
"path": "/dotnet/9.0.1xx/daily/sdk-productVersion.txt",
"response": "9.0.100-preview.6.24281.7\n",
"responseHeaders": {
"content-type": "text/plain"
}
},
{
"basePath": "https://dotnetbuilds.azureedge.net",
"path": "/public/Sdk/9.0.100-preview.6.24281.7/productCommit-win-x64.json",
"response": {
"runtime": {
"commit": "9fca0c3dbd3874ed0245b1bdb10547d0ba769d66",
"version": "9.0.0-preview.6.24280.11"
},
"aspnetcore": {
"commit": "5f8f891f8849d21efc5306f3053397203d4b7656",
"version": "9.0.0-preview.6.24280.8"
},
"windowsdesktop": {
"commit": "f778f53d3a473d811614cb817d9aa6b5eed43d05",
"version": "9.0.0-preview.6.24281.1"
},
"sdk": {
"commit": "b0e9af0530394fff1237038efcdcdc2590bb9772",
"version": "9.0.100-preview.6.24281.7"
}
}
},
{
"basePath": "https://dotnetbuilds.azureedge.net",
"path": "/public/Sdk/9.0.100-preview.5.24281.15/productCommit-win-x64.json",
"response": {
"installer": {
"commit": "b6a8831c576a14ba60799a59ae8ec4c7c114f3f8",
"version": "9.0.100-preview.5.24281.15"
},
"runtime": {
"commit": "de6897b3b71c1628329ab586ea3e4ecc6a5a2ab3",
"version": "9.0.0-preview.5.24280.5"
},
"aspnetcore": {
"commit": "1be2ad87ffe9cac0697eeaebc06f74a86a86a0f1",
"version": "9.0.0-preview.5.24280.2"
},
"windowsdesktop": {
"commit": "4b985fd0f9794ca084e5d0ced977dccad4a31436",
"version": "9.0.0-preview.5.24280.3"
},
"sdk": {
"commit": "b6a8831c576a14ba60799a59ae8ec4c7c114f3f8",
"version": "9.0.100-preview.5.24281.15"
}
}
},
{
"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-preview.6.24281.7",
"head": "update-dotnet-sdk-9.0.100-preview.6.24281.7",
"base": "main",
"body": "Updates the .NET SDK to version `9.0.100-preview.6.24281.7`, which also updates the .NET runtime from version [``9.0.0-preview.5.24280.5``](https://github.com/dotnet/installer/commits/b6a8831c576a14ba60799a59ae8ec4c7c114f3f8) to version [``9.0.0-preview.6.24280.11``](https://github.com/dotnet/sdk/commits/b0e9af0530394fff1237038efcdcdc2590bb9772).\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-preview.6.24281.7",
"html_url": "https://github.local/martincostello/update-dotnet-sdk/pull/42",
"user": {
"login": "github-actions[bot]"
},
"head": {
"ref": "update-dotnet-sdk-9.0.100-preview.6.24281.7"
},
"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&per_page=100&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-preview.6.24281.7",
"user": {
"login": "github-actions[bot]"
},
"head": {
"ref": "update-dotnet-sdk-9.0.100-preview.6.24281.7"
}
}
]
}
]
}
1 change: 1 addition & 0 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ describe('update-dotnet-sdk', () => {
['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'],
['daily', '9.0.1xx', '9.0.100-preview.5.24281.15'],
])('%s builds for channel "%s"', (quality: string, channel: string, sdkVersion: string) => {
let fixture: ActionFixture;

Expand Down

0 comments on commit e5c44fc

Please sign in to comment.