You've already forked setup-dotnet
mirror of
https://github.com/actions/setup-dotnet.git
synced 2025-07-14 02:50:31 +07:00
Compare commits
37 Commits
v-malob/up
...
v1.8.0
Author | SHA1 | Date | |
---|---|---|---|
a71d1eb2c8 | |||
b50d70502b | |||
d8cff32ae5 | |||
7b2009794e | |||
53d6483af8 | |||
34c59b7d0b | |||
bd485b6bd1 | |||
23fa2c1473 | |||
291588df6a | |||
87189a16c7 | |||
cde58ab948 | |||
20e68089c2 | |||
7790315509 | |||
c47e26f841 | |||
3edf2e9363 | |||
a8c97016ef | |||
07b4a80293 | |||
d08d2193f9 | |||
632ccbdfb9 | |||
b81836a248 | |||
3b539379a8 | |||
596753d72c | |||
f9d7f16c00 | |||
56d96e897e | |||
5a201f5e82 | |||
13ccc115f4 | |||
f2eb44dadd | |||
8dcf1ee9bc | |||
3707a44789 | |||
385512c5e5 | |||
083d63a2ff | |||
6930747f7f | |||
20afff9c90 | |||
36fa9877a9 | |||
77a48bbb85 | |||
768b4eb7db | |||
ba7e1e2155 |
21
README.md
21
README.md
@ -13,7 +13,7 @@ This action sets up a [dotnet core cli](https://github.com/dotnet/cli) environme
|
|||||||
Please Note: GitHub hosted runners have some versions of the .NET SDK
|
Please Note: GitHub hosted runners have some versions of the .NET SDK
|
||||||
preinstalled. Installed versions are subject to change. Please refer to the
|
preinstalled. Installed versions are subject to change. Please refer to the
|
||||||
documentation
|
documentation
|
||||||
[software installed on github hosted runners](https://help.github.com/en/actions/reference/software-installed-on-github-hosted-runners)
|
[software installed on github hosted runners](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-software)
|
||||||
for .NET SDK versions that are currently available.
|
for .NET SDK versions that are currently available.
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
@ -23,13 +23,24 @@ See [action.yml](action.yml)
|
|||||||
Basic:
|
Basic:
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@main
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-dotnet@v1
|
- uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: '3.1.x' # SDK Version to use; x will use the latest version of the 3.1 channel
|
dotnet-version: '3.1.x' # SDK Version to use; x will use the latest version of the 3.1 channel
|
||||||
- run: dotnet build <my project>
|
- run: dotnet build <my project>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Preview version:
|
||||||
|
```yml
|
||||||
|
steps:
|
||||||
|
- uses: actions@checkout@v2
|
||||||
|
- uses: actions/setup-dotnet@v1
|
||||||
|
with:
|
||||||
|
dotnet-version: '6.0.x'
|
||||||
|
include-prerelease: true
|
||||||
|
- run: dotnet build <my project>
|
||||||
|
```
|
||||||
|
|
||||||
Matrix Testing:
|
Matrix Testing:
|
||||||
```yaml
|
```yaml
|
||||||
jobs:
|
jobs:
|
||||||
@ -37,7 +48,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
dotnet: [ '2.2.103', '3.0', '3.1.x' ]
|
dotnet: [ '2.1.x', '3.1.x', '5.0.x' ]
|
||||||
name: Dotnet ${{ matrix.dotnet }} sample
|
name: Dotnet ${{ matrix.dotnet }} sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
@ -59,7 +70,7 @@ jobs:
|
|||||||
- name: Setup dotnet
|
- name: Setup dotnet
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: '2.2.103'
|
dotnet-version: '2.1.x'
|
||||||
- name: Setup dotnet
|
- name: Setup dotnet
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
@ -113,7 +124,7 @@ build:
|
|||||||
- uses: actions/checkout@main
|
- uses: actions/checkout@main
|
||||||
- uses: actions/setup-dotnet@v1
|
- uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: '3.1.100' # SDK Version to use.
|
dotnet-version: '3.1.x' # SDK Version to use.
|
||||||
```
|
```
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
@ -13,6 +13,8 @@ describe('version tests', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
each([
|
each([
|
||||||
|
['3.x', '3.x'],
|
||||||
|
['3.*', '3.*'],
|
||||||
['3.1.x', '3.1'],
|
['3.1.x', '3.1'],
|
||||||
['1.1.*', '1.1'],
|
['1.1.*', '1.1'],
|
||||||
['2.0', '2.0']
|
['2.0', '2.0']
|
||||||
@ -42,7 +44,6 @@ describe('version tests', () => {
|
|||||||
'.2.3',
|
'.2.3',
|
||||||
'.2.x',
|
'.2.x',
|
||||||
'1',
|
'1',
|
||||||
'2.x',
|
|
||||||
'*.*.1',
|
'*.*.1',
|
||||||
'*.1',
|
'*.1',
|
||||||
'*.',
|
'*.',
|
||||||
|
@ -13,6 +13,9 @@ inputs:
|
|||||||
description: 'Optional OWNER for using packages from GitHub Package Registry organizations/users other than the current repository''s owner. Only used if a GPR URL is also provided in source-url'
|
description: 'Optional OWNER for using packages from GitHub Package Registry organizations/users other than the current repository''s owner. Only used if a GPR URL is also provided in source-url'
|
||||||
config-file:
|
config-file:
|
||||||
description: 'Optional NuGet.config location, if your NuGet.config isn''t located in the root of the repo.'
|
description: 'Optional NuGet.config location, if your NuGet.config isn''t located in the root of the repo.'
|
||||||
|
include-prerelease:
|
||||||
|
description: 'Whether prerelease versions should be matched with non-exact versions (for example 5.0.0-preview.6 being matched by 5, 5.0, 5.x or 5.0.x). Defaults to false if not provided.'
|
||||||
|
required: False
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
|
65
dist/index.js
vendored
65
dist/index.js
vendored
@ -4840,11 +4840,26 @@ const github = __importStar(__webpack_require__(469));
|
|||||||
const xmlbuilder = __importStar(__webpack_require__(312));
|
const xmlbuilder = __importStar(__webpack_require__(312));
|
||||||
const xmlParser = __importStar(__webpack_require__(989));
|
const xmlParser = __importStar(__webpack_require__(989));
|
||||||
function configAuthentication(feedUrl, existingFileLocation = '', processRoot = process.cwd()) {
|
function configAuthentication(feedUrl, existingFileLocation = '', processRoot = process.cwd()) {
|
||||||
const existingNuGetConfig = path.resolve(processRoot, existingFileLocation == '' ? 'nuget.config' : existingFileLocation);
|
const existingNuGetConfig = path.resolve(processRoot, existingFileLocation === ''
|
||||||
|
? getExistingNugetConfig(processRoot)
|
||||||
|
: existingFileLocation);
|
||||||
const tempNuGetConfig = path.resolve(processRoot, '../', 'nuget.config');
|
const tempNuGetConfig = path.resolve(processRoot, '../', 'nuget.config');
|
||||||
writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig);
|
writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig);
|
||||||
}
|
}
|
||||||
exports.configAuthentication = configAuthentication;
|
exports.configAuthentication = configAuthentication;
|
||||||
|
function isValidKey(key) {
|
||||||
|
return /^[\w\-\.]+$/i.test(key);
|
||||||
|
}
|
||||||
|
function getExistingNugetConfig(processRoot) {
|
||||||
|
const defaultConfigName = 'nuget.config';
|
||||||
|
const configFileNames = fs
|
||||||
|
.readdirSync(processRoot)
|
||||||
|
.filter(filename => filename.toLowerCase() === defaultConfigName);
|
||||||
|
if (configFileNames.length) {
|
||||||
|
return configFileNames[0];
|
||||||
|
}
|
||||||
|
return defaultConfigName;
|
||||||
|
}
|
||||||
function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) {
|
function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) {
|
||||||
console.log(`dotnet-auth: Finding any source references in ${existingFileLocation}, writing a new temporary configuration file with credentials to ${tempFileLocation}`);
|
console.log(`dotnet-auth: Finding any source references in ${existingFileLocation}, writing a new temporary configuration file with credentials to ${tempFileLocation}`);
|
||||||
let xml;
|
let xml;
|
||||||
@ -4910,8 +4925,8 @@ function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) {
|
|||||||
}
|
}
|
||||||
xml = xml.ele('packageSourceCredentials');
|
xml = xml.ele('packageSourceCredentials');
|
||||||
sourceKeys.forEach(key => {
|
sourceKeys.forEach(key => {
|
||||||
if (key.indexOf(' ') > -1) {
|
if (!isValidKey(key)) {
|
||||||
throw new Error("This action currently can't handle source names with spaces. Remove the space from your repo's NuGet.config and try again.");
|
throw new Error("Source name can contain letters, numbers, and '-', '_', '.' symbols only. Please, fix source name in NuGet.config and try again.");
|
||||||
}
|
}
|
||||||
xml = xml
|
xml = xml
|
||||||
.ele(key)
|
.ele(key)
|
||||||
@ -7814,14 +7829,18 @@ function run() {
|
|||||||
core.debug('No version found, trying to find version from global.json');
|
core.debug('No version found, trying to find version from global.json');
|
||||||
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
||||||
if (fs.existsSync(globalJsonPath)) {
|
if (fs.existsSync(globalJsonPath)) {
|
||||||
const globalJson = JSON.parse(fs.readFileSync(globalJsonPath, { encoding: 'utf8' }));
|
const globalJson = JSON.parse(
|
||||||
|
// .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649
|
||||||
|
fs.readFileSync(globalJsonPath, { encoding: 'utf8' }).trim());
|
||||||
if (globalJson.sdk && globalJson.sdk.version) {
|
if (globalJson.sdk && globalJson.sdk.version) {
|
||||||
version = globalJson.sdk.version;
|
version = globalJson.sdk.version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (version) {
|
if (version) {
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(version);
|
const includePrerelease = (core.getInput('include-prerelease') || 'false').toLowerCase() ===
|
||||||
|
'true';
|
||||||
|
const dotnetInstaller = new installer.DotnetCoreInstaller(version, includePrerelease);
|
||||||
yield dotnetInstaller.installDotnet();
|
yield dotnetInstaller.installDotnet();
|
||||||
}
|
}
|
||||||
const sourceUrl = core.getInput('source-url');
|
const sourceUrl = core.getInput('source-url');
|
||||||
@ -16868,15 +16887,16 @@ class DotNetVersionInfo {
|
|||||||
this.isExactVersionSet = true;
|
this.isExactVersionSet = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//Note: No support for previews when using generic
|
const parts = version.split('.');
|
||||||
let parts = version.split('.');
|
|
||||||
if (parts.length < 2 || parts.length > 3)
|
if (parts.length < 2 || parts.length > 3)
|
||||||
this.throwInvalidVersionFormat();
|
this.throwInvalidVersionFormat();
|
||||||
if (parts.length == 3 && parts[2] !== 'x' && parts[2] !== '*') {
|
if (parts.length == 3 && parts[2] !== 'x' && parts[2] !== '*') {
|
||||||
this.throwInvalidVersionFormat();
|
this.throwInvalidVersionFormat();
|
||||||
}
|
}
|
||||||
let major = this.getVersionNumberOrThrow(parts[0]);
|
const major = this.getVersionNumberOrThrow(parts[0]);
|
||||||
let minor = this.getVersionNumberOrThrow(parts[1]);
|
const minor = ['x', '*'].includes(parts[1])
|
||||||
|
? parts[1]
|
||||||
|
: this.getVersionNumberOrThrow(parts[1]);
|
||||||
this.fullversion = major + '.' + minor;
|
this.fullversion = major + '.' + minor;
|
||||||
}
|
}
|
||||||
getVersionNumberOrThrow(input) {
|
getVersionNumberOrThrow(input) {
|
||||||
@ -16894,7 +16914,7 @@ class DotNetVersionInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
throwInvalidVersionFormat() {
|
throwInvalidVersionFormat() {
|
||||||
throw 'Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*';
|
throw new Error('Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* If true exacatly one version should be resolved
|
* If true exacatly one version should be resolved
|
||||||
@ -16908,8 +16928,9 @@ class DotNetVersionInfo {
|
|||||||
}
|
}
|
||||||
exports.DotNetVersionInfo = DotNetVersionInfo;
|
exports.DotNetVersionInfo = DotNetVersionInfo;
|
||||||
class DotnetCoreInstaller {
|
class DotnetCoreInstaller {
|
||||||
constructor(version) {
|
constructor(version, includePrerelease = false) {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
|
this.includePrerelease = includePrerelease;
|
||||||
}
|
}
|
||||||
installDotnet() {
|
installDotnet() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
@ -16997,7 +17018,7 @@ class DotnetCoreInstaller {
|
|||||||
}
|
}
|
||||||
console.log(process.env['PATH']);
|
console.log(process.env['PATH']);
|
||||||
if (resultCode != 0) {
|
if (resultCode != 0) {
|
||||||
throw `Failed to install dotnet ${resultCode}. ${output}`;
|
throw new Error(`Failed to install dotnet ${resultCode}. ${output}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -17016,16 +17037,24 @@ class DotnetCoreInstaller {
|
|||||||
const releasesResult = releasesResponse.result || {};
|
const releasesResult = releasesResponse.result || {};
|
||||||
let releasesInfo = releasesResult['releases'];
|
let releasesInfo = releasesResult['releases'];
|
||||||
releasesInfo = releasesInfo.filter((releaseInfo) => {
|
releasesInfo = releasesInfo.filter((releaseInfo) => {
|
||||||
return (semver.satisfies(releaseInfo['sdk']['version'], versionInfo.version()) ||
|
return (semver.satisfies(releaseInfo['sdk']['version'], versionInfo.version(), {
|
||||||
semver.satisfies(releaseInfo['sdk']['version-display'], versionInfo.version()));
|
includePrerelease: this.includePrerelease
|
||||||
|
}) ||
|
||||||
|
semver.satisfies(releaseInfo['sdk']['version-display'], versionInfo.version(), {
|
||||||
|
includePrerelease: this.includePrerelease
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
// Exclude versions that are newer than the latest if using not exact
|
// Exclude versions that are newer than the latest if using not exact
|
||||||
let latestSdk = releasesResult['latest-sdk'];
|
let latestSdk = releasesResult['latest-sdk'];
|
||||||
releasesInfo = releasesInfo.filter((releaseInfo) => semver.lte(releaseInfo['sdk']['version'], latestSdk));
|
releasesInfo = releasesInfo.filter((releaseInfo) => semver.lte(releaseInfo['sdk']['version'], latestSdk, {
|
||||||
|
includePrerelease: this.includePrerelease
|
||||||
|
}));
|
||||||
// Sort for latest version
|
// Sort for latest version
|
||||||
releasesInfo = releasesInfo.sort((a, b) => semver.rcompare(a['sdk']['version'], b['sdk']['version']));
|
releasesInfo = releasesInfo.sort((a, b) => semver.rcompare(a['sdk']['version'], b['sdk']['version'], {
|
||||||
|
includePrerelease: this.includePrerelease
|
||||||
|
}));
|
||||||
if (releasesInfo.length == 0) {
|
if (releasesInfo.length == 0) {
|
||||||
throw `Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`;
|
throw new Error(`Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`);
|
||||||
}
|
}
|
||||||
let release = releasesInfo[0];
|
let release = releasesInfo[0];
|
||||||
return release['sdk']['version'];
|
return release['sdk']['version'];
|
||||||
@ -17046,7 +17075,7 @@ class DotnetCoreInstaller {
|
|||||||
return versionParts[0] == sdkParts[0];
|
return versionParts[0] == sdkParts[0];
|
||||||
});
|
});
|
||||||
if (releasesInfo.length === 0) {
|
if (releasesInfo.length === 0) {
|
||||||
throw `Could not find info for version ${versionParts.join('.')} at ${DotNetCoreIndexUrl}`;
|
throw new Error(`Could not find info for version ${versionParts.join('.')} at ${DotNetCoreIndexUrl}`);
|
||||||
}
|
}
|
||||||
return releasesInfo[0]['releases.json'];
|
return releasesInfo[0]['releases.json'];
|
||||||
});
|
});
|
||||||
|
6
package-lock.json
generated
6
package-lock.json
generated
@ -5342,9 +5342,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"y18n": {
|
"y18n": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.1.tgz",
|
||||||
"integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==",
|
"integrity": "sha512-wNcy4NvjMYL8gogWWYAO7ZFWFfHcbdbE57tZO8e4cbpj8tfUcwrwqSl3ad8HxpYWCdXcJUCeKKZS62Av1affwQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"yaml": {
|
"yaml": {
|
||||||
|
@ -13,7 +13,9 @@ export function configAuthentication(
|
|||||||
) {
|
) {
|
||||||
const existingNuGetConfig: string = path.resolve(
|
const existingNuGetConfig: string = path.resolve(
|
||||||
processRoot,
|
processRoot,
|
||||||
existingFileLocation == '' ? 'nuget.config' : existingFileLocation
|
existingFileLocation === ''
|
||||||
|
? getExistingNugetConfig(processRoot)
|
||||||
|
: existingFileLocation
|
||||||
);
|
);
|
||||||
|
|
||||||
const tempNuGetConfig: string = path.resolve(
|
const tempNuGetConfig: string = path.resolve(
|
||||||
@ -25,6 +27,21 @@ export function configAuthentication(
|
|||||||
writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig);
|
writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isValidKey(key: string): boolean {
|
||||||
|
return /^[\w\-\.]+$/i.test(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getExistingNugetConfig(processRoot: string) {
|
||||||
|
const defaultConfigName = 'nuget.config';
|
||||||
|
const configFileNames = fs
|
||||||
|
.readdirSync(processRoot)
|
||||||
|
.filter(filename => filename.toLowerCase() === defaultConfigName);
|
||||||
|
if (configFileNames.length) {
|
||||||
|
return configFileNames[0];
|
||||||
|
}
|
||||||
|
return defaultConfigName;
|
||||||
|
}
|
||||||
|
|
||||||
function writeFeedToFile(
|
function writeFeedToFile(
|
||||||
feedUrl: string,
|
feedUrl: string,
|
||||||
existingFileLocation: string,
|
existingFileLocation: string,
|
||||||
@ -109,9 +126,9 @@ function writeFeedToFile(
|
|||||||
xml = xml.ele('packageSourceCredentials');
|
xml = xml.ele('packageSourceCredentials');
|
||||||
|
|
||||||
sourceKeys.forEach(key => {
|
sourceKeys.forEach(key => {
|
||||||
if (key.indexOf(' ') > -1) {
|
if (!isValidKey(key)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"This action currently can't handle source names with spaces. Remove the space from your repo's NuGet.config and try again."
|
"Source name can contain letters, numbers, and '-', '_', '.' symbols only. Please, fix source name in NuGet.config and try again."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +29,7 @@ export class DotNetVersionInfo {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Note: No support for previews when using generic
|
const parts: string[] = version.split('.');
|
||||||
let parts: string[] = version.split('.');
|
|
||||||
|
|
||||||
if (parts.length < 2 || parts.length > 3) this.throwInvalidVersionFormat();
|
if (parts.length < 2 || parts.length > 3) this.throwInvalidVersionFormat();
|
||||||
|
|
||||||
@ -38,8 +37,10 @@ export class DotNetVersionInfo {
|
|||||||
this.throwInvalidVersionFormat();
|
this.throwInvalidVersionFormat();
|
||||||
}
|
}
|
||||||
|
|
||||||
let major = this.getVersionNumberOrThrow(parts[0]);
|
const major = this.getVersionNumberOrThrow(parts[0]);
|
||||||
let minor = this.getVersionNumberOrThrow(parts[1]);
|
const minor = ['x', '*'].includes(parts[1])
|
||||||
|
? parts[1]
|
||||||
|
: this.getVersionNumberOrThrow(parts[1]);
|
||||||
|
|
||||||
this.fullversion = major + '.' + minor;
|
this.fullversion = major + '.' + minor;
|
||||||
}
|
}
|
||||||
@ -60,7 +61,9 @@ export class DotNetVersionInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private throwInvalidVersionFormat() {
|
private throwInvalidVersionFormat() {
|
||||||
throw 'Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*';
|
throw new Error(
|
||||||
|
'Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,8 +79,9 @@ export class DotNetVersionInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class DotnetCoreInstaller {
|
export class DotnetCoreInstaller {
|
||||||
constructor(version: string) {
|
constructor(version: string, includePrerelease: boolean = false) {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
|
this.includePrerelease = includePrerelease;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async installDotnet() {
|
public async installDotnet() {
|
||||||
@ -187,7 +191,7 @@ export class DotnetCoreInstaller {
|
|||||||
console.log(process.env['PATH']);
|
console.log(process.env['PATH']);
|
||||||
|
|
||||||
if (resultCode != 0) {
|
if (resultCode != 0) {
|
||||||
throw `Failed to install dotnet ${resultCode}. ${output}`;
|
throw new Error(`Failed to install dotnet ${resultCode}. ${output}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,13 +216,15 @@ export class DotnetCoreInstaller {
|
|||||||
let releasesInfo: any[] = releasesResult['releases'];
|
let releasesInfo: any[] = releasesResult['releases'];
|
||||||
releasesInfo = releasesInfo.filter((releaseInfo: any) => {
|
releasesInfo = releasesInfo.filter((releaseInfo: any) => {
|
||||||
return (
|
return (
|
||||||
semver.satisfies(
|
semver.satisfies(releaseInfo['sdk']['version'], versionInfo.version(), {
|
||||||
releaseInfo['sdk']['version'],
|
includePrerelease: this.includePrerelease
|
||||||
versionInfo.version()
|
}) ||
|
||||||
) ||
|
|
||||||
semver.satisfies(
|
semver.satisfies(
|
||||||
releaseInfo['sdk']['version-display'],
|
releaseInfo['sdk']['version-display'],
|
||||||
versionInfo.version()
|
versionInfo.version(),
|
||||||
|
{
|
||||||
|
includePrerelease: this.includePrerelease
|
||||||
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -227,16 +233,22 @@ export class DotnetCoreInstaller {
|
|||||||
let latestSdk: string = releasesResult['latest-sdk'];
|
let latestSdk: string = releasesResult['latest-sdk'];
|
||||||
|
|
||||||
releasesInfo = releasesInfo.filter((releaseInfo: any) =>
|
releasesInfo = releasesInfo.filter((releaseInfo: any) =>
|
||||||
semver.lte(releaseInfo['sdk']['version'], latestSdk)
|
semver.lte(releaseInfo['sdk']['version'], latestSdk, {
|
||||||
|
includePrerelease: this.includePrerelease
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// Sort for latest version
|
// Sort for latest version
|
||||||
releasesInfo = releasesInfo.sort((a, b) =>
|
releasesInfo = releasesInfo.sort((a, b) =>
|
||||||
semver.rcompare(a['sdk']['version'], b['sdk']['version'])
|
semver.rcompare(a['sdk']['version'], b['sdk']['version'], {
|
||||||
|
includePrerelease: this.includePrerelease
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
if (releasesInfo.length == 0) {
|
if (releasesInfo.length == 0) {
|
||||||
throw `Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`;
|
throw new Error(
|
||||||
|
`Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let release = releasesInfo[0];
|
let release = releasesInfo[0];
|
||||||
@ -264,15 +276,18 @@ export class DotnetCoreInstaller {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (releasesInfo.length === 0) {
|
if (releasesInfo.length === 0) {
|
||||||
throw `Could not find info for version ${versionParts.join(
|
throw new Error(
|
||||||
'.'
|
`Could not find info for version ${versionParts.join(
|
||||||
)} at ${DotNetCoreIndexUrl}`;
|
'.'
|
||||||
|
)} at ${DotNetCoreIndexUrl}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return releasesInfo[0]['releases.json'];
|
return releasesInfo[0]['releases.json'];
|
||||||
}
|
}
|
||||||
|
|
||||||
private version: string;
|
private version: string;
|
||||||
|
private includePrerelease: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DotNetCoreIndexUrl: string =
|
const DotNetCoreIndexUrl: string =
|
||||||
|
@ -20,7 +20,8 @@ export async function run() {
|
|||||||
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
||||||
if (fs.existsSync(globalJsonPath)) {
|
if (fs.existsSync(globalJsonPath)) {
|
||||||
const globalJson = JSON.parse(
|
const globalJson = JSON.parse(
|
||||||
fs.readFileSync(globalJsonPath, {encoding: 'utf8'})
|
// .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649
|
||||||
|
fs.readFileSync(globalJsonPath, {encoding: 'utf8'}).trim()
|
||||||
);
|
);
|
||||||
if (globalJson.sdk && globalJson.sdk.version) {
|
if (globalJson.sdk && globalJson.sdk.version) {
|
||||||
version = globalJson.sdk.version;
|
version = globalJson.sdk.version;
|
||||||
@ -29,7 +30,14 @@ export async function run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (version) {
|
if (version) {
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(version);
|
const includePrerelease: boolean =
|
||||||
|
(core.getInput('include-prerelease') || 'false').toLowerCase() ===
|
||||||
|
'true';
|
||||||
|
|
||||||
|
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
||||||
|
version,
|
||||||
|
includePrerelease
|
||||||
|
);
|
||||||
await dotnetInstaller.installDotnet();
|
await dotnetInstaller.installDotnet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user