mirror of
https://github.com/actions/setup-dotnet.git
synced 2024-11-22 11:31:07 +07:00
Refactor logic
This commit is contained in:
parent
5f570676c2
commit
34c30d0e81
10
.github/workflows/e2e-tests.yml
vendored
10
.github/workflows/e2e-tests.yml
vendored
@ -177,17 +177,17 @@ jobs:
|
|||||||
- name: Clear toolcache
|
- name: Clear toolcache
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
||||||
- name: Setup dotnet '3.1.1xx'
|
- name: Setup dotnet '5.0.1xx'
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
dotnet-version: '3.1.1xx'
|
dotnet-version: '5.0.1xx'
|
||||||
- name: Setup dotnet '6.0.3xx'
|
- name: Setup dotnet '7.0.1xx'
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
dotnet-version: '6.0.3xx'
|
dotnet-version: '7.0.1xx'
|
||||||
- name: Verify dotnet
|
- name: Verify dotnet
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: __tests__/verify-dotnet.ps1 3.1.1 6.0.3
|
run: __tests__/verify-dotnet.ps1 5.0.1 7.0.1
|
||||||
|
|
||||||
test-setup-global-json-specified-and-version:
|
test-setup-global-json-specified-and-version:
|
||||||
runs-on: ${{ matrix.operating-system }}
|
runs-on: ${{ matrix.operating-system }}
|
||||||
|
@ -201,7 +201,6 @@ describe('DotnetVersionResolver tests', () => {
|
|||||||
'.2.3',
|
'.2.3',
|
||||||
'.2.x',
|
'.2.x',
|
||||||
'*.',
|
'*.',
|
||||||
'*',
|
|
||||||
'1.2.',
|
'1.2.',
|
||||||
'1.2.-abc',
|
'1.2.-abc',
|
||||||
'a.b',
|
'a.b',
|
||||||
@ -222,7 +221,7 @@ describe('DotnetVersionResolver tests', () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
each(['3.1', '3.1.x', '3.1.*', '3.1.X', '3.1.1xx']).test(
|
each(['3.1', '3.1.x', '3.1.*', '3.1.X', '5.0.1xx']).test(
|
||||||
"if version: '%s' that can be resolved to 'channel' option is supplied, it should set type to 'channel' in version object",
|
"if version: '%s' that can be resolved to 'channel' option is supplied, it should set type to 'channel' in version object",
|
||||||
async version => {
|
async version => {
|
||||||
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
||||||
|
50
dist/index.js
vendored
50
dist/index.js
vendored
@ -250,33 +250,51 @@ class DotnetVersionResolver {
|
|||||||
}
|
}
|
||||||
resolveVersionInput() {
|
resolveVersionInput() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const isLatestPatchSyntax = /^\d+\.\d+\.\d{1}x{2}$/.test(this.inputVersion);
|
if (!semver_1.default.validRange(this.inputVersion) && !this.isLatestPatchSyntax()) {
|
||||||
if (!semver_1.default.validRange(this.inputVersion) && !isLatestPatchSyntax) {
|
|
||||||
throw new Error(`'dotnet-version' was supplied in invalid format: ${this.inputVersion}! Supported syntax: A.B.C, A.B, A.B.x, A, A.x, A.B.Cxx`);
|
throw new Error(`'dotnet-version' was supplied in invalid format: ${this.inputVersion}! Supported syntax: A.B.C, A.B, A.B.x, A, A.x, A.B.Cxx`);
|
||||||
}
|
}
|
||||||
if (semver_1.default.valid(this.inputVersion)) {
|
if (semver_1.default.valid(this.inputVersion)) {
|
||||||
this.resolvedArgument.type = 'version';
|
this.createVersionArgument();
|
||||||
this.resolvedArgument.value = this.inputVersion;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.resolvedArgument.type = 'channel';
|
yield this.createChannelArgument();
|
||||||
const [major, minor] = this.inputVersion.split('.');
|
|
||||||
if (isLatestPatchSyntax) {
|
|
||||||
this.resolvedArgument.value = this.inputVersion;
|
|
||||||
}
|
|
||||||
else if (this.isNumericTag(major) && this.isNumericTag(minor)) {
|
|
||||||
this.resolvedArgument.value = `${major}.${minor}`;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.resolvedArgument.value = yield this.getLatestByMajorTag(major);
|
|
||||||
}
|
|
||||||
this.resolvedArgument.qualityFlag = +major >= 6 ? true : false;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
isNumericTag(versionTag) {
|
isNumericTag(versionTag) {
|
||||||
return /^\d+$/.test(versionTag);
|
return /^\d+$/.test(versionTag);
|
||||||
}
|
}
|
||||||
|
isLatestPatchSyntax() {
|
||||||
|
var _b, _c;
|
||||||
|
const majorTag = (_c = (_b = this.inputVersion.match(/^(?<majorTag>\d+)\.\d+\.\d{1}x{2}$/)) === null || _b === void 0 ? void 0 : _b.groups) === null || _c === void 0 ? void 0 : _c.majorTag;
|
||||||
|
if (majorTag && parseInt(majorTag) < 5) {
|
||||||
|
throw new Error(`'dotnet-version' was supplied in invalid format: ${this.inputVersion}! The A.B.Cxx syntax is available since the .NET 5.0 release.`);
|
||||||
|
}
|
||||||
|
return majorTag ? true : false;
|
||||||
|
}
|
||||||
|
createVersionArgument() {
|
||||||
|
this.resolvedArgument.type = 'version';
|
||||||
|
this.resolvedArgument.value = this.inputVersion;
|
||||||
|
}
|
||||||
|
createChannelArgument() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
this.resolvedArgument.type = 'channel';
|
||||||
|
const [major, minor] = this.inputVersion.split('.');
|
||||||
|
if (this.isLatestPatchSyntax()) {
|
||||||
|
this.resolvedArgument.value = this.inputVersion;
|
||||||
|
}
|
||||||
|
else if (this.isNumericTag(major) && this.isNumericTag(minor)) {
|
||||||
|
this.resolvedArgument.value = `${major}.${minor}`;
|
||||||
|
}
|
||||||
|
else if (this.isNumericTag(major)) {
|
||||||
|
this.resolvedArgument.value = yield this.getLatestByMajorTag(major);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.resolvedArgument.value = 'LTS';
|
||||||
|
}
|
||||||
|
this.resolvedArgument.qualityFlag = +major >= 6 ? true : false;
|
||||||
|
});
|
||||||
|
}
|
||||||
createDotNetVersion() {
|
createDotNetVersion() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
yield this.resolveVersionInput();
|
yield this.resolveVersionInput();
|
||||||
|
@ -27,26 +27,15 @@ export class DotnetVersionResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async resolveVersionInput(): Promise<void> {
|
private async resolveVersionInput(): Promise<void> {
|
||||||
const isLatestPatchSyntax = /^\d+\.\d+\.\d{1}x{2}$/.test(this.inputVersion);
|
if (!semver.validRange(this.inputVersion) && !this.isLatestPatchSyntax()) {
|
||||||
if (!semver.validRange(this.inputVersion) && !isLatestPatchSyntax) {
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`'dotnet-version' was supplied in invalid format: ${this.inputVersion}! Supported syntax: A.B.C, A.B, A.B.x, A, A.x, A.B.Cxx`
|
`'dotnet-version' was supplied in invalid format: ${this.inputVersion}! Supported syntax: A.B.C, A.B, A.B.x, A, A.x, A.B.Cxx`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (semver.valid(this.inputVersion)) {
|
if (semver.valid(this.inputVersion)) {
|
||||||
this.resolvedArgument.type = 'version';
|
this.createVersionArgument();
|
||||||
this.resolvedArgument.value = this.inputVersion;
|
|
||||||
} else {
|
} else {
|
||||||
this.resolvedArgument.type = 'channel';
|
await this.createChannelArgument();
|
||||||
const [major, minor] = this.inputVersion.split('.');
|
|
||||||
if (isLatestPatchSyntax) {
|
|
||||||
this.resolvedArgument.value = this.inputVersion;
|
|
||||||
} else if (this.isNumericTag(major) && this.isNumericTag(minor)) {
|
|
||||||
this.resolvedArgument.value = `${major}.${minor}`;
|
|
||||||
} else {
|
|
||||||
this.resolvedArgument.value = await this.getLatestByMajorTag(major);
|
|
||||||
}
|
|
||||||
this.resolvedArgument.qualityFlag = +major >= 6 ? true : false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +43,38 @@ export class DotnetVersionResolver {
|
|||||||
return /^\d+$/.test(versionTag);
|
return /^\d+$/.test(versionTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isLatestPatchSyntax() {
|
||||||
|
const majorTag = this.inputVersion.match(
|
||||||
|
/^(?<majorTag>\d+)\.\d+\.\d{1}x{2}$/
|
||||||
|
)?.groups?.majorTag;
|
||||||
|
if (majorTag && parseInt(majorTag) < 5) {
|
||||||
|
throw new Error(
|
||||||
|
`'dotnet-version' was supplied in invalid format: ${this.inputVersion}! The A.B.Cxx syntax is available since the .NET 5.0 release.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return majorTag ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private createVersionArgument() {
|
||||||
|
this.resolvedArgument.type = 'version';
|
||||||
|
this.resolvedArgument.value = this.inputVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async createChannelArgument() {
|
||||||
|
this.resolvedArgument.type = 'channel';
|
||||||
|
const [major, minor] = this.inputVersion.split('.');
|
||||||
|
if (this.isLatestPatchSyntax()) {
|
||||||
|
this.resolvedArgument.value = this.inputVersion;
|
||||||
|
} else if (this.isNumericTag(major) && this.isNumericTag(minor)) {
|
||||||
|
this.resolvedArgument.value = `${major}.${minor}`;
|
||||||
|
} else if (this.isNumericTag(major)) {
|
||||||
|
this.resolvedArgument.value = await this.getLatestByMajorTag(major);
|
||||||
|
} else {
|
||||||
|
this.resolvedArgument.value = 'LTS';
|
||||||
|
}
|
||||||
|
this.resolvedArgument.qualityFlag = +major >= 6 ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
public async createDotNetVersion(): Promise<DotnetVersion> {
|
public async createDotNetVersion(): Promise<DotnetVersion> {
|
||||||
await this.resolveVersionInput();
|
await this.resolveVersionInput();
|
||||||
if (!this.resolvedArgument.type) {
|
if (!this.resolvedArgument.type) {
|
||||||
|
Loading…
Reference in New Issue
Block a user