From 13fd5bf1911312c854895ec9c36c805f89dda2f2 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Fri, 20 Aug 2021 15:43:49 +0300 Subject: [PATCH 01/13] Support rollForward option from global.json --- __tests__/setup-dotnet.test.ts | 16 ++++++++++++++++ dist/index.js | 24 +++++++++++++++++------- src/setup-dotnet.ts | 25 ++++++++++++++++++------- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/__tests__/setup-dotnet.test.ts b/__tests__/setup-dotnet.test.ts index c492f56..72d3856 100644 --- a/__tests__/setup-dotnet.test.ts +++ b/__tests__/setup-dotnet.test.ts @@ -44,4 +44,20 @@ describe('setup-dotnet tests', () => { expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true); } }, 400000); + + it('Acquires version of dotnet from global.json if no matching version is installed', async () => { + const globalJsonPath = path.join(process.cwd(), 'global.json'); + const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "3.1.201",${os.EOL}"rollForward": "latestFeature"${os.EOL}}${os.EOL}}`; + if (!fs.existsSync(globalJsonPath)) { + fs.writeFileSync(globalJsonPath, jsonContents); + } + await setup.run(); + + expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.412'))).toBe(true); + if (IS_WINDOWS) { + expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true); + } else { + expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true); + } + }, 400000); }); diff --git a/dist/index.js b/dist/index.js index be845d6..19a1fc3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7447,7 +7447,7 @@ function octokitRestNormalizeGitReferenceResponses (octokit) { /***/ 314: /***/ (function(module) { -module.exports = {"name":"@octokit/graphql","version":"2.1.3","publishConfig":{"access":"public"},"description":"GitHub GraphQL API client for browsers and Node","main":"index.js","scripts":{"prebuild":"mkdirp dist/","build":"npm-run-all build:*","build:development":"webpack --mode development --entry . --output-library=octokitGraphql --output=./dist/octokit-graphql.js --profile --json > dist/bundle-stats.json","build:production":"webpack --mode production --entry . --plugin=compression-webpack-plugin --output-library=octokitGraphql --output-path=./dist --output-filename=octokit-graphql.min.js --devtool source-map","bundle-report":"webpack-bundle-analyzer dist/bundle-stats.json --mode=static --no-open --report dist/bundle-report.html","coverage":"nyc report --reporter=html && open coverage/index.html","coverage:upload":"nyc report --reporter=text-lcov | coveralls","pretest":"standard","test":"nyc mocha test/*-test.js","test:browser":"cypress run --browser chrome"},"repository":{"type":"git","url":"https://github.com/octokit/graphql.js.git"},"keywords":["octokit","github","api","graphql"],"author":"Gregor Martynus (https://github.com/gr2m)","license":"MIT","bugs":{"url":"https://github.com/octokit/graphql.js/issues"},"homepage":"https://github.com/octokit/graphql.js#readme","dependencies":{"@octokit/request":"^5.0.0","universal-user-agent":"^2.0.3"},"devDependencies":{"chai":"^4.2.0","compression-webpack-plugin":"^2.0.0","coveralls":"^3.0.3","cypress":"^3.1.5","fetch-mock":"^7.3.1","mkdirp":"^0.5.1","mocha":"^6.0.0","npm-run-all":"^4.1.3","nyc":"^14.0.0","semantic-release":"^15.13.3","simple-mock":"^0.8.0","standard":"^12.0.1","webpack":"^4.29.6","webpack-bundle-analyzer":"^3.1.0","webpack-cli":"^3.2.3"},"bundlesize":[{"path":"./dist/octokit-graphql.min.js.gz","maxSize":"5KB"}],"release":{"publish":["@semantic-release/npm",{"path":"@semantic-release/github","assets":["dist/*","!dist/*.map.gz"]}]},"standard":{"globals":["describe","before","beforeEach","afterEach","after","it","expect"]},"files":["lib"],"_resolved":"https://registry.npmjs.org/@octokit/graphql/-/graphql-2.1.3.tgz","_integrity":"sha512-XoXJqL2ondwdnMIW3wtqJWEwcBfKk37jO/rYkoxNPEVeLBDGsGO1TCWggrAlq3keGt/O+C/7VepXnukUxwt5vA==","_from":"@octokit/graphql@2.1.3"}; +module.exports = {"_args":[["@octokit/graphql@2.1.3","/Users/vsafonkin/projects/setup-dotnet"]],"_from":"@octokit/graphql@2.1.3","_id":"@octokit/graphql@2.1.3","_inBundle":false,"_integrity":"sha512-XoXJqL2ondwdnMIW3wtqJWEwcBfKk37jO/rYkoxNPEVeLBDGsGO1TCWggrAlq3keGt/O+C/7VepXnukUxwt5vA==","_location":"/@octokit/graphql","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"@octokit/graphql@2.1.3","name":"@octokit/graphql","escapedName":"@octokit%2fgraphql","scope":"@octokit","rawSpec":"2.1.3","saveSpec":null,"fetchSpec":"2.1.3"},"_requiredBy":["/@actions/github"],"_resolved":"https://registry.npmjs.org/@octokit/graphql/-/graphql-2.1.3.tgz","_spec":"2.1.3","_where":"/Users/vsafonkin/projects/setup-dotnet","author":{"name":"Gregor Martynus","url":"https://github.com/gr2m"},"bugs":{"url":"https://github.com/octokit/graphql.js/issues"},"bundlesize":[{"path":"./dist/octokit-graphql.min.js.gz","maxSize":"5KB"}],"dependencies":{"@octokit/request":"^5.0.0","universal-user-agent":"^2.0.3"},"description":"GitHub GraphQL API client for browsers and Node","devDependencies":{"chai":"^4.2.0","compression-webpack-plugin":"^2.0.0","coveralls":"^3.0.3","cypress":"^3.1.5","fetch-mock":"^7.3.1","mkdirp":"^0.5.1","mocha":"^6.0.0","npm-run-all":"^4.1.3","nyc":"^14.0.0","semantic-release":"^15.13.3","simple-mock":"^0.8.0","standard":"^12.0.1","webpack":"^4.29.6","webpack-bundle-analyzer":"^3.1.0","webpack-cli":"^3.2.3"},"files":["lib"],"homepage":"https://github.com/octokit/graphql.js#readme","keywords":["octokit","github","api","graphql"],"license":"MIT","main":"index.js","name":"@octokit/graphql","publishConfig":{"access":"public"},"release":{"publish":["@semantic-release/npm",{"path":"@semantic-release/github","assets":["dist/*","!dist/*.map.gz"]}]},"repository":{"type":"git","url":"git+https://github.com/octokit/graphql.js.git"},"scripts":{"build":"npm-run-all build:*","build:development":"webpack --mode development --entry . --output-library=octokitGraphql --output=./dist/octokit-graphql.js --profile --json > dist/bundle-stats.json","build:production":"webpack --mode production --entry . --plugin=compression-webpack-plugin --output-library=octokitGraphql --output-path=./dist --output-filename=octokit-graphql.min.js --devtool source-map","bundle-report":"webpack-bundle-analyzer dist/bundle-stats.json --mode=static --no-open --report dist/bundle-report.html","coverage":"nyc report --reporter=html && open coverage/index.html","coverage:upload":"nyc report --reporter=text-lcov | coveralls","prebuild":"mkdirp dist/","pretest":"standard","test":"nyc mocha test/*-test.js","test:browser":"cypress run --browser chrome"},"standard":{"globals":["describe","before","beforeEach","afterEach","after","it","expect"]},"version":"2.1.3"}; /***/ }), @@ -7829,12 +7829,7 @@ function run() { core.debug('No version found, trying to find version from global.json'); const globalJsonPath = path.join(process.cwd(), 'global.json'); if (fs.existsSync(globalJsonPath)) { - 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) { - version = globalJson.sdk.version; - } + version = getVersionFromGlobalJson(globalJsonPath); } } if (version) { @@ -7857,6 +7852,21 @@ function run() { }); } exports.run = run; +function getVersionFromGlobalJson(globalJsonPath) { + let version = ""; + 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) { + version = globalJson.sdk.version; + const rollForward = globalJson.sdk.rollForward; + if (rollForward && (rollForward === 'latestFeature' || rollForward === 'latestPatch')) { + const [major, minor] = version.split('.'); + version = `${major}.${minor}`; + } + } + return version; +} run(); diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index 2a0914f..d868761 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -19,13 +19,7 @@ export async function run() { core.debug('No version found, trying to find version from global.json'); const globalJsonPath = path.join(process.cwd(), 'global.json'); if (fs.existsSync(globalJsonPath)) { - 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) { - version = globalJson.sdk.version; - } + version = getVersionFromGlobalJson(globalJsonPath) } } @@ -54,4 +48,21 @@ export async function run() { } } +function getVersionFromGlobalJson(globalJsonPath: string): string { + let version: string = "" + 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) { + version = globalJson.sdk.version; + const rollForward = globalJson.sdk.rollForward + if (rollForward && (rollForward === 'latestFeature' || rollForward === 'latestPatch')) { + const [major, minor] = version.split('.') + version = `${major}.${minor}` + } + } + return version +} + run(); From 078f7c4a7348b979c9f276b99311bea059d93bff Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Fri, 20 Aug 2021 15:44:47 +0300 Subject: [PATCH 02/13] Format code --- src/setup-dotnet.ts | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index d868761..c704802 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -19,7 +19,7 @@ export async function run() { core.debug('No version found, trying to find version from global.json'); const globalJsonPath = path.join(process.cwd(), 'global.json'); if (fs.existsSync(globalJsonPath)) { - version = getVersionFromGlobalJson(globalJsonPath) + version = getVersionFromGlobalJson(globalJsonPath); } } @@ -49,20 +49,23 @@ export async function run() { } function getVersionFromGlobalJson(globalJsonPath: string): string { - let version: string = "" - const globalJson = JSON.parse( + let version: string = ''; + 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) { - version = globalJson.sdk.version; - const rollForward = globalJson.sdk.rollForward - if (rollForward && (rollForward === 'latestFeature' || rollForward === 'latestPatch')) { - const [major, minor] = version.split('.') - version = `${major}.${minor}` - } + fs.readFileSync(globalJsonPath, {encoding: 'utf8'}).trim() + ); + if (globalJson.sdk && globalJson.sdk.version) { + version = globalJson.sdk.version; + const rollForward = globalJson.sdk.rollForward; + if ( + rollForward && + (rollForward === 'latestFeature' || rollForward === 'latestPatch') + ) { + const [major, minor] = version.split('.'); + version = `${major}.${minor}`; } - return version + } + return version; } run(); From 6b8ad2e72536948d8352af71a843d84fb008eecd Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Fri, 20 Aug 2021 15:48:47 +0300 Subject: [PATCH 03/13] Revert exports in index.js --- dist/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 19a1fc3..fa508cf 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7447,7 +7447,7 @@ function octokitRestNormalizeGitReferenceResponses (octokit) { /***/ 314: /***/ (function(module) { -module.exports = {"_args":[["@octokit/graphql@2.1.3","/Users/vsafonkin/projects/setup-dotnet"]],"_from":"@octokit/graphql@2.1.3","_id":"@octokit/graphql@2.1.3","_inBundle":false,"_integrity":"sha512-XoXJqL2ondwdnMIW3wtqJWEwcBfKk37jO/rYkoxNPEVeLBDGsGO1TCWggrAlq3keGt/O+C/7VepXnukUxwt5vA==","_location":"/@octokit/graphql","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"@octokit/graphql@2.1.3","name":"@octokit/graphql","escapedName":"@octokit%2fgraphql","scope":"@octokit","rawSpec":"2.1.3","saveSpec":null,"fetchSpec":"2.1.3"},"_requiredBy":["/@actions/github"],"_resolved":"https://registry.npmjs.org/@octokit/graphql/-/graphql-2.1.3.tgz","_spec":"2.1.3","_where":"/Users/vsafonkin/projects/setup-dotnet","author":{"name":"Gregor Martynus","url":"https://github.com/gr2m"},"bugs":{"url":"https://github.com/octokit/graphql.js/issues"},"bundlesize":[{"path":"./dist/octokit-graphql.min.js.gz","maxSize":"5KB"}],"dependencies":{"@octokit/request":"^5.0.0","universal-user-agent":"^2.0.3"},"description":"GitHub GraphQL API client for browsers and Node","devDependencies":{"chai":"^4.2.0","compression-webpack-plugin":"^2.0.0","coveralls":"^3.0.3","cypress":"^3.1.5","fetch-mock":"^7.3.1","mkdirp":"^0.5.1","mocha":"^6.0.0","npm-run-all":"^4.1.3","nyc":"^14.0.0","semantic-release":"^15.13.3","simple-mock":"^0.8.0","standard":"^12.0.1","webpack":"^4.29.6","webpack-bundle-analyzer":"^3.1.0","webpack-cli":"^3.2.3"},"files":["lib"],"homepage":"https://github.com/octokit/graphql.js#readme","keywords":["octokit","github","api","graphql"],"license":"MIT","main":"index.js","name":"@octokit/graphql","publishConfig":{"access":"public"},"release":{"publish":["@semantic-release/npm",{"path":"@semantic-release/github","assets":["dist/*","!dist/*.map.gz"]}]},"repository":{"type":"git","url":"git+https://github.com/octokit/graphql.js.git"},"scripts":{"build":"npm-run-all build:*","build:development":"webpack --mode development --entry . --output-library=octokitGraphql --output=./dist/octokit-graphql.js --profile --json > dist/bundle-stats.json","build:production":"webpack --mode production --entry . --plugin=compression-webpack-plugin --output-library=octokitGraphql --output-path=./dist --output-filename=octokit-graphql.min.js --devtool source-map","bundle-report":"webpack-bundle-analyzer dist/bundle-stats.json --mode=static --no-open --report dist/bundle-report.html","coverage":"nyc report --reporter=html && open coverage/index.html","coverage:upload":"nyc report --reporter=text-lcov | coveralls","prebuild":"mkdirp dist/","pretest":"standard","test":"nyc mocha test/*-test.js","test:browser":"cypress run --browser chrome"},"standard":{"globals":["describe","before","beforeEach","afterEach","after","it","expect"]},"version":"2.1.3"}; +module.exports = {"name":"@octokit/graphql","version":"2.1.3","publishConfig":{"access":"public"},"description":"GitHub GraphQL API client for browsers and Node","main":"index.js","scripts":{"prebuild":"mkdirp dist/","build":"npm-run-all build:*","build:development":"webpack --mode development --entry . --output-library=octokitGraphql --output=./dist/octokit-graphql.js --profile --json > dist/bundle-stats.json","build:production":"webpack --mode production --entry . --plugin=compression-webpack-plugin --output-library=octokitGraphql --output-path=./dist --output-filename=octokit-graphql.min.js --devtool source-map","bundle-report":"webpack-bundle-analyzer dist/bundle-stats.json --mode=static --no-open --report dist/bundle-report.html","coverage":"nyc report --reporter=html && open coverage/index.html","coverage:upload":"nyc report --reporter=text-lcov | coveralls","pretest":"standard","test":"nyc mocha test/*-test.js","test:browser":"cypress run --browser chrome"},"repository":{"type":"git","url":"https://github.com/octokit/graphql.js.git"},"keywords":["octokit","github","api","graphql"],"author":"Gregor Martynus (https://github.com/gr2m)","license":"MIT","bugs":{"url":"https://github.com/octokit/graphql.js/issues"},"homepage":"https://github.com/octokit/graphql.js#readme","dependencies":{"@octokit/request":"^5.0.0","universal-user-agent":"^2.0.3"},"devDependencies":{"chai":"^4.2.0","compression-webpack-plugin":"^2.0.0","coveralls":"^3.0.3","cypress":"^3.1.5","fetch-mock":"^7.3.1","mkdirp":"^0.5.1","mocha":"^6.0.0","npm-run-all":"^4.1.3","nyc":"^14.0.0","semantic-release":"^15.13.3","simple-mock":"^0.8.0","standard":"^12.0.1","webpack":"^4.29.6","webpack-bundle-analyzer":"^3.1.0","webpack-cli":"^3.2.3"},"bundlesize":[{"path":"./dist/octokit-graphql.min.js.gz","maxSize":"5KB"}],"release":{"publish":["@semantic-release/npm",{"path":"@semantic-release/github","assets":["dist/*","!dist/*.map.gz"]}]},"standard":{"globals":["describe","before","beforeEach","afterEach","after","it","expect"]},"files":["lib"],"_resolved":"https://registry.npmjs.org/@octokit/graphql/-/graphql-2.1.3.tgz","_integrity":"sha512-XoXJqL2ondwdnMIW3wtqJWEwcBfKk37jO/rYkoxNPEVeLBDGsGO1TCWggrAlq3keGt/O+C/7VepXnukUxwt5vA==","_from":"@octokit/graphql@2.1.3"}; /***/ }), From 9480036ff97f56bb7ee23e12b48016558771dda1 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Fri, 20 Aug 2021 16:35:44 +0300 Subject: [PATCH 04/13] Fix unit test --- __tests__/setup-dotnet.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/__tests__/setup-dotnet.test.ts b/__tests__/setup-dotnet.test.ts index 72d3856..a1eaca6 100644 --- a/__tests__/setup-dotnet.test.ts +++ b/__tests__/setup-dotnet.test.ts @@ -10,7 +10,7 @@ import * as setup from '../src/setup-dotnet'; const IS_WINDOWS = process.platform === 'win32'; -describe('setup-dotnet tests', () => { +describe.only('setup-dotnet tests', () => { beforeAll(async () => { process.env.RUNNER_TOOL_CACHE = toolDir; process.env.DOTNET_INSTALL_DIR = toolDir; @@ -45,9 +45,9 @@ describe('setup-dotnet tests', () => { } }, 400000); - it('Acquires version of dotnet from global.json if no matching version is installed', async () => { + it.only('Acquires version of dotnet from global.json with rollForward option, install the latest patch', async () => { const globalJsonPath = path.join(process.cwd(), 'global.json'); - const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "3.1.201",${os.EOL}"rollForward": "latestFeature"${os.EOL}}${os.EOL}}`; + const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version":"3.1.201",${os.EOL}"rollForward":"latestFeature"${os.EOL}}${os.EOL}}`; if (!fs.existsSync(globalJsonPath)) { fs.writeFileSync(globalJsonPath, jsonContents); } From 0067f023d24e12a5a144447c2745dcb71a61452d Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Fri, 20 Aug 2021 16:45:26 +0300 Subject: [PATCH 05/13] Fix unstaged changes in index.js --- dist/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index fa508cf..5dff700 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7853,14 +7853,15 @@ function run() { } exports.run = run; function getVersionFromGlobalJson(globalJsonPath) { - let version = ""; + let version = ''; 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) { version = globalJson.sdk.version; const rollForward = globalJson.sdk.rollForward; - if (rollForward && (rollForward === 'latestFeature' || rollForward === 'latestPatch')) { + if (rollForward && + (rollForward === 'latestFeature' || rollForward === 'latestPatch')) { const [major, minor] = version.split('.'); version = `${major}.${minor}`; } From f92687c91054d6924cd66337f6dcabfc2c80f73b Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Fri, 20 Aug 2021 16:47:49 +0300 Subject: [PATCH 06/13] Minor fix --- __tests__/setup-dotnet.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__tests__/setup-dotnet.test.ts b/__tests__/setup-dotnet.test.ts index a1eaca6..8cd1a82 100644 --- a/__tests__/setup-dotnet.test.ts +++ b/__tests__/setup-dotnet.test.ts @@ -10,7 +10,7 @@ import * as setup from '../src/setup-dotnet'; const IS_WINDOWS = process.platform === 'win32'; -describe.only('setup-dotnet tests', () => { +describe('setup-dotnet tests', () => { beforeAll(async () => { process.env.RUNNER_TOOL_CACHE = toolDir; process.env.DOTNET_INSTALL_DIR = toolDir; @@ -45,7 +45,7 @@ describe.only('setup-dotnet tests', () => { } }, 400000); - it.only('Acquires version of dotnet from global.json with rollForward option, install the latest patch', async () => { + it('Acquires version of dotnet from global.json with rollForward option, install the latest patch', async () => { const globalJsonPath = path.join(process.cwd(), 'global.json'); const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version":"3.1.201",${os.EOL}"rollForward":"latestFeature"${os.EOL}}${os.EOL}}`; if (!fs.existsSync(globalJsonPath)) { From b7b99f337e0ad6c0b7811d7c6ab740d9c458d420 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Fri, 20 Aug 2021 16:54:24 +0300 Subject: [PATCH 07/13] Fix unit test --- __tests__/setup-dotnet.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/setup-dotnet.test.ts b/__tests__/setup-dotnet.test.ts index 8cd1a82..4eeec7a 100644 --- a/__tests__/setup-dotnet.test.ts +++ b/__tests__/setup-dotnet.test.ts @@ -19,7 +19,7 @@ describe('setup-dotnet tests', () => { await io.rmRF(tempDir); }); - afterAll(async () => { + afterEach(async () => { try { await io.rmRF(path.join(process.cwd(), 'global.json')); await io.rmRF(toolDir); From 5e45b4b59136aed75b138ebe73cbefb5c198b400 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Fri, 20 Aug 2021 17:11:48 +0300 Subject: [PATCH 08/13] Remove hardcoded patch version from unit test --- __tests__/setup-dotnet.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/__tests__/setup-dotnet.test.ts b/__tests__/setup-dotnet.test.ts index 4eeec7a..76d06e6 100644 --- a/__tests__/setup-dotnet.test.ts +++ b/__tests__/setup-dotnet.test.ts @@ -7,6 +7,7 @@ const toolDir = path.join(__dirname, 'runner', 'tools2'); const tempDir = path.join(__dirname, 'runner', 'temp2'); import * as setup from '../src/setup-dotnet'; +import * as dotnetInstaller from '../src/installer'; const IS_WINDOWS = process.platform === 'win32'; @@ -51,9 +52,13 @@ describe('setup-dotnet tests', () => { if (!fs.existsSync(globalJsonPath)) { fs.writeFileSync(globalJsonPath, jsonContents); } + + const version = '3.1' + const installer = new dotnetInstaller.DotnetCoreInstaller(version) + const patchVersion = await installer.resolveVersion(new dotnetInstaller.DotNetVersionInfo(version)) await setup.run(); - expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.412'))).toBe(true); + expect(fs.existsSync(path.join(toolDir, 'sdk', patchVersion))).toBe(true); if (IS_WINDOWS) { expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true); } else { From f3822c3b025d3704d8a062d0a877c56387a03af9 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Fri, 20 Aug 2021 17:13:23 +0300 Subject: [PATCH 09/13] Prettier --- __tests__/setup-dotnet.test.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/__tests__/setup-dotnet.test.ts b/__tests__/setup-dotnet.test.ts index 76d06e6..7ad8be8 100644 --- a/__tests__/setup-dotnet.test.ts +++ b/__tests__/setup-dotnet.test.ts @@ -53,9 +53,11 @@ describe('setup-dotnet tests', () => { fs.writeFileSync(globalJsonPath, jsonContents); } - const version = '3.1' - const installer = new dotnetInstaller.DotnetCoreInstaller(version) - const patchVersion = await installer.resolveVersion(new dotnetInstaller.DotNetVersionInfo(version)) + const version = '3.1'; + const installer = new dotnetInstaller.DotnetCoreInstaller(version); + const patchVersion = await installer.resolveVersion( + new dotnetInstaller.DotNetVersionInfo(version) + ); await setup.run(); expect(fs.existsSync(path.join(toolDir, 'sdk', patchVersion))).toBe(true); From 2c3efd1f04468c94b6b2459474b474f8c4893cc4 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Fri, 20 Aug 2021 17:28:10 +0300 Subject: [PATCH 10/13] Improve condition --- dist/index.js | 7 ++++--- src/setup-dotnet.ts | 8 +++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index 5dff700..a9c4d74 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7853,15 +7853,16 @@ function run() { } exports.run = run; function getVersionFromGlobalJson(globalJsonPath) { + var _a; + const optionValues = ['latestFeature', 'latestPatch']; let version = ''; 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) { version = globalJson.sdk.version; - const rollForward = globalJson.sdk.rollForward; - if (rollForward && - (rollForward === 'latestFeature' || rollForward === 'latestPatch')) { + const rollForward = (_a = globalJson.sdk.rollForward) !== null && _a !== void 0 ? _a : ''; + if (optionValues.includes(rollForward)) { const [major, minor] = version.split('.'); version = `${major}.${minor}`; } diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index c704802..eea9916 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -49,6 +49,7 @@ export async function run() { } function getVersionFromGlobalJson(globalJsonPath: string): string { + const optionValues = ['latestFeature', 'latestPatch'] let version: string = ''; const globalJson = JSON.parse( // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649 @@ -56,11 +57,8 @@ function getVersionFromGlobalJson(globalJsonPath: string): string { ); if (globalJson.sdk && globalJson.sdk.version) { version = globalJson.sdk.version; - const rollForward = globalJson.sdk.rollForward; - if ( - rollForward && - (rollForward === 'latestFeature' || rollForward === 'latestPatch') - ) { + const rollForward = globalJson.sdk.rollForward ?? ''; + if (optionValues.includes(rollForward)) { const [major, minor] = version.split('.'); version = `${major}.${minor}`; } From 33fad1d14250a684b5719b4271e9b4fc86f891a9 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Fri, 20 Aug 2021 17:28:30 +0300 Subject: [PATCH 11/13] Format code --- src/setup-dotnet.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index eea9916..ae4fe7a 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -49,7 +49,7 @@ export async function run() { } function getVersionFromGlobalJson(globalJsonPath: string): string { - const optionValues = ['latestFeature', 'latestPatch'] + const optionValues = ['latestFeature', 'latestPatch']; let version: string = ''; const globalJson = JSON.parse( // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649 From b2cf6c7cd41500af95efaa3b4d3ba79c0f77be84 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Mon, 30 Aug 2021 17:27:01 +0300 Subject: [PATCH 12/13] Handle only latestFeature option --- src/setup-dotnet.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index ae4fe7a..0d09998 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -49,7 +49,6 @@ export async function run() { } function getVersionFromGlobalJson(globalJsonPath: string): string { - const optionValues = ['latestFeature', 'latestPatch']; let version: string = ''; const globalJson = JSON.parse( // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649 @@ -57,8 +56,8 @@ function getVersionFromGlobalJson(globalJsonPath: string): string { ); if (globalJson.sdk && globalJson.sdk.version) { version = globalJson.sdk.version; - const rollForward = globalJson.sdk.rollForward ?? ''; - if (optionValues.includes(rollForward)) { + const rollForward = globalJson.sdk.rollForward; + if (rollForward && rollForward === 'latestFeature') { const [major, minor] = version.split('.'); version = `${major}.${minor}`; } From b66058b059ef929c72d19b49b3321eb1f0741bd4 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Mon, 30 Aug 2021 17:35:17 +0300 Subject: [PATCH 13/13] Build index.js --- dist/index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index a9c4d74..f510d10 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7853,16 +7853,14 @@ function run() { } exports.run = run; function getVersionFromGlobalJson(globalJsonPath) { - var _a; - const optionValues = ['latestFeature', 'latestPatch']; let version = ''; 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) { version = globalJson.sdk.version; - const rollForward = (_a = globalJson.sdk.rollForward) !== null && _a !== void 0 ? _a : ''; - if (optionValues.includes(rollForward)) { + const rollForward = globalJson.sdk.rollForward; + if (rollForward && rollForward === 'latestFeature') { const [major, minor] = version.split('.'); version = `${major}.${minor}`; }