Skip to content

Commit

Permalink
Update resolveVersionInput()
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanZosimov committed Apr 11, 2023
1 parent f199d27 commit 0318091
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
19 changes: 8 additions & 11 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,7 @@ class DotnetVersionResolver {
this.resolvedArgument.value = `${major}.${minor}`;
}
else {
const httpClient = new hc.HttpClient('actions/setup-dotnet', [], {
allowRetries: true,
maxRetries: 3
});
this.resolvedArgument.value = yield this.getLatestVersion(httpClient, [
major,
minor
]);
this.resolvedArgument.value = yield this.getLatestByMajorTag(major);
}
this.resolvedArgument.qualityFlag = +major >= 6 ? true : false;
}
Expand All @@ -301,17 +294,21 @@ class DotnetVersionResolver {
return this.resolvedArgument;
});
}
getLatestVersion(httpClient, versionParts) {
getLatestByMajorTag(majorTag) {
return __awaiter(this, void 0, void 0, function* () {
const httpClient = new hc.HttpClient('actions/setup-dotnet', [], {
allowRetries: true,
maxRetries: 3
});
const response = yield httpClient.getJson(DotnetVersionResolver.DotNetCoreIndexUrl);
const result = response.result || {};
const releasesInfo = result['releases-index'];
const releaseInfo = releasesInfo.find(info => {
const sdkParts = info['channel-version'].split('.');
return sdkParts[0] === versionParts[0];
return sdkParts[0] === majorTag;
});
if (!releaseInfo) {
throw new Error(`Could not find info for version ${versionParts.join('.')} at ${DotnetVersionResolver.DotNetCoreIndexUrl}`);
throw new Error(`Could not find info for version with major tag: v${majorTag} at ${DotnetVersionResolver.DotNetCoreIndexUrl}`);
}
return releaseInfo['channel-version'];
});
Expand Down
24 changes: 8 additions & 16 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,7 @@ export class DotnetVersionResolver {
} else if (this.isNumericTag(major) && this.isNumericTag(minor)) {
this.resolvedArgument.value = `${major}.${minor}`;
} else {
const httpClient = new hc.HttpClient('actions/setup-dotnet', [], {
allowRetries: true,
maxRetries: 3
});
this.resolvedArgument.value = await this.getLatestVersion(httpClient, [
major,
minor
]);
this.resolvedArgument.value = await this.getLatestByMajorTag(major);
}
this.resolvedArgument.qualityFlag = +major >= 6 ? true : false;
}
Expand All @@ -76,10 +69,11 @@ export class DotnetVersionResolver {
return this.resolvedArgument;
}

private async getLatestVersion(
httpClient: hc.HttpClient,
versionParts: string[]
): Promise<string> {
private async getLatestByMajorTag(majorTag: string): Promise<string> {
const httpClient = new hc.HttpClient('actions/setup-dotnet', [], {
allowRetries: true,
maxRetries: 3
});
const response = await httpClient.getJson<any>(
DotnetVersionResolver.DotNetCoreIndexUrl
);
Expand All @@ -88,14 +82,12 @@ export class DotnetVersionResolver {

const releaseInfo = releasesInfo.find(info => {
const sdkParts: string[] = info['channel-version'].split('.');
return sdkParts[0] === versionParts[0];
return sdkParts[0] === majorTag;
});

if (!releaseInfo) {
throw new Error(
`Could not find info for version ${versionParts.join('.')} at ${
DotnetVersionResolver.DotNetCoreIndexUrl
}`
`Could not find info for version with major tag: v${majorTag} at ${DotnetVersionResolver.DotNetCoreIndexUrl}`
);
}

Expand Down

0 comments on commit 0318091

Please sign in to comment.