From 3ae886ede4e5ed7ca0b68ff6124d681158afe891 Mon Sep 17 00:00:00 2001 From: "James M. Greene" Date: Mon, 28 Nov 2022 12:06:52 -0600 Subject: [PATCH 1/7] Update to latest `actions/publish-action` (#630) --- .github/workflows/release-new-action-version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-new-action-version.yml b/.github/workflows/release-new-action-version.yml index 908248b8..b8076d43 100644 --- a/.github/workflows/release-new-action-version.yml +++ b/.github/workflows/release-new-action-version.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Update the ${{ env.TAG_NAME }} tag - uses: actions/publish-action@v0.1.0 + uses: actions/publish-action@v0.2.1 with: source-tag: ${{ env.TAG_NAME }} slack-webhook: ${{ secrets.SLACK_WEBHOOK }} From a69d45adcd128d92db46d8cc7245c2237b41520b Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Mon, 5 Dec 2022 13:32:26 +0100 Subject: [PATCH 2/7] Add modification of scoped registry --- src/authutil.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/authutil.ts b/src/authutil.ts index aaebdfd2..d1885482 100644 --- a/src/authutil.ts +++ b/src/authutil.ts @@ -29,7 +29,7 @@ function writeRegistryToFile( scope = '@' + scope; } if (scope) { - scope = scope.toLowerCase(); + scope = scope.toLowerCase() + ':'; } core.debug(`Setting auth in ${fileLocation}`); @@ -38,7 +38,7 @@ function writeRegistryToFile( const curContents: string = fs.readFileSync(fileLocation, 'utf8'); curContents.split(os.EOL).forEach((line: string) => { // Add current contents unless they are setting the registry - if (!line.toLowerCase().startsWith('registry')) { + if (!line.toLowerCase().startsWith(`${scope}registry`)) { newContents += line + os.EOL; } }); @@ -46,9 +46,7 @@ function writeRegistryToFile( // Remove http: or https: from front of registry. const authString: string = registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}'; - const registryString: string = scope - ? `${scope}:registry=${registryUrl}` - : `registry=${registryUrl}`; + const registryString: string = `${scope}registry=${registryUrl}`; const alwaysAuthString: string = `always-auth=${alwaysAuth}`; newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`; fs.writeFileSync(fileLocation, newContents); From e77eaaccd3948bf790da061e9f0fe5c9cb8297a2 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Mon, 5 Dec 2022 13:36:23 +0100 Subject: [PATCH 3/7] Add unit tests --- __tests__/authutil.test.ts | 81 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/__tests__/authutil.test.ts b/__tests__/authutil.test.ts index 594c6a13..458ceb12 100644 --- a/__tests__/authutil.test.ts +++ b/__tests__/authutil.test.ts @@ -123,6 +123,7 @@ describe('authutil tests', () => { expect(rc['registry']).toBe('https://registry.npmjs.org/'); expect(rc['always-auth']).toBe('true'); }); + it('It is already set the NODE_AUTH_TOKEN export it ', async () => { process.env.NODE_AUTH_TOKEN = 'foobar'; await auth.configAuthentication('npm.pkg.github.com', 'false'); @@ -132,4 +133,84 @@ describe('authutil tests', () => { expect(rc['always-auth']).toBe('false'); expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar'); }); + + it('configAuthentication should overwrite non-scoped with non-scoped', async () => { + fs.writeFileSync(rcFile, 'registry=NNN'); + await auth.configAuthentication('https://registry.npmjs.org/', 'true'); + let contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); + expect(contents).toBe( + `//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}always-auth=true` + ); + }); + + it('configAuthentication should overwrite only non-scoped', async () => { + fs.writeFileSync(rcFile, `registry=NNN${os.EOL}@myscope:registry=MMM`); + await auth.configAuthentication('https://registry.npmjs.org/', 'true'); + let contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); + expect(contents).toBe( + `@myscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}always-auth=true` + ); + }); + + it('configAuthentication should add non-scoped to scoped', async () => { + fs.writeFileSync(rcFile, '@myscope:registry=NNN'); + await auth.configAuthentication('https://registry.npmjs.org/', 'true'); + let contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); + expect(contents).toBe( + `@myscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}always-auth=true` + ); + }); + + it('configAuthentication should overwrite scoped with scoped', async () => { + process.env['INPUT_SCOPE'] = 'myscope'; + fs.writeFileSync(rcFile, `@myscope:registry=NNN`); + await auth.configAuthentication('https://registry.npmjs.org/', 'true'); + let contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); + expect(contents).toBe( + `//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true` + ); + }); + + it('configAuthentication should overwrite only scoped', async () => { + process.env['INPUT_SCOPE'] = 'myscope'; + fs.writeFileSync(rcFile, `registry=NNN${os.EOL}@myscope:registry=MMM`); + await auth.configAuthentication('https://registry.npmjs.org/', 'true'); + let contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); + expect(contents).toBe( + `registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true` + ); + }); + + it('configAuthentication should add scoped to non-scoped', async () => { + process.env['INPUT_SCOPE'] = 'myscope'; + fs.writeFileSync(rcFile, `registry=MMM`); + await auth.configAuthentication('https://registry.npmjs.org/', 'true'); + let contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); + expect(contents).toBe( + `registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true` + ); + }); + + it('configAuthentication should overwrite only one scoped', async () => { + process.env['INPUT_SCOPE'] = 'myscope'; + fs.writeFileSync( + rcFile, + `@otherscope:registry=NNN${os.EOL}@myscope:registry=MMM` + ); + await auth.configAuthentication('https://registry.npmjs.org/', 'true'); + let contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); + expect(contents).toBe( + `@otherscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true` + ); + }); + + it('configAuthentication should add scoped to another scoped', async () => { + process.env['INPUT_SCOPE'] = 'myscope'; + fs.writeFileSync(rcFile, `@otherscope:registry=MMM`); + await auth.configAuthentication('https://registry.npmjs.org/', 'true'); + let contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); + expect(contents).toBe( + `@otherscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true` + ); + }); }); From 069a4f8926c4ea0bfca73c3d3ffa0a5d0c7bdce2 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Mon, 5 Dec 2022 13:37:05 +0100 Subject: [PATCH 4/7] Add dist --- dist/setup/index.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index aa4f708a..b6c3e23f 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -72945,7 +72945,7 @@ function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) { scope = '@' + scope; } if (scope) { - scope = scope.toLowerCase(); + scope = scope.toLowerCase() + ':'; } core.debug(`Setting auth in ${fileLocation}`); let newContents = ''; @@ -72953,16 +72953,14 @@ function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) { const curContents = fs.readFileSync(fileLocation, 'utf8'); curContents.split(os.EOL).forEach((line) => { // Add current contents unless they are setting the registry - if (!line.toLowerCase().startsWith('registry')) { + if (!line.toLowerCase().startsWith(`${scope}registry`)) { newContents += line + os.EOL; } }); } // Remove http: or https: from front of registry. const authString = registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}'; - const registryString = scope - ? `${scope}:registry=${registryUrl}` - : `registry=${registryUrl}`; + const registryString = `${scope}registry=${registryUrl}`; const alwaysAuthString = `always-auth=${alwaysAuth}`; newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`; fs.writeFileSync(fileLocation, newContents); From 676975d9aaccb55b3621a6d481497820a9942577 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Fri, 9 Dec 2022 11:41:54 +0100 Subject: [PATCH 5/7] Use early return pattern --- dist/cache-save/index.js | 16 ++++++---------- dist/setup/index.js | 16 ++++++---------- src/cache-utils.ts | 23 ++++++++++------------- 3 files changed, 22 insertions(+), 33 deletions(-) diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index 876629ef..5f499403 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -61185,16 +61185,12 @@ function isGhes() { } exports.isGhes = isGhes; function isCacheFeatureAvailable() { - if (!cache.isFeatureAvailable()) { - if (isGhes()) { - throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); - } - else { - core.warning('The runner was not able to contact the cache service. Caching will be skipped'); - } - return false; - } - return true; + if (cache.isFeatureAvailable()) + return true; + if (isGhes()) + throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); + core.warning('The runner was not able to contact the cache service. Caching will be skipped'); + return false; } exports.isCacheFeatureAvailable = isCacheFeatureAvailable; diff --git a/dist/setup/index.js b/dist/setup/index.js index b6c3e23f..af122147 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73139,16 +73139,12 @@ function isGhes() { } exports.isGhes = isGhes; function isCacheFeatureAvailable() { - if (!cache.isFeatureAvailable()) { - if (isGhes()) { - throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); - } - else { - core.warning('The runner was not able to contact the cache service. Caching will be skipped'); - } - return false; - } - return true; + if (cache.isFeatureAvailable()) + return true; + if (isGhes()) + throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); + core.warning('The runner was not able to contact the cache service. Caching will be skipped'); + return false; } exports.isCacheFeatureAvailable = isCacheFeatureAvailable; diff --git a/src/cache-utils.ts b/src/cache-utils.ts index ccd4e987..065d347e 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -105,19 +105,16 @@ export function isGhes(): boolean { } export function isCacheFeatureAvailable(): boolean { - if (!cache.isFeatureAvailable()) { - if (isGhes()) { - throw new Error( - 'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.' - ); - } else { - core.warning( - 'The runner was not able to contact the cache service. Caching will be skipped' - ); - } + if (cache.isFeatureAvailable()) return true; - return false; - } + if (isGhes()) + throw new Error( + 'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.' + ); - return true; + core.warning( + 'The runner was not able to contact the cache service. Caching will be skipped' + ); + + return false; } From b28830cbe242f8218618bacd97758c82c162a981 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Fri, 9 Dec 2022 12:05:59 +0100 Subject: [PATCH 6/7] replace throw with warn --- __tests__/cache-utils.test.ts | 3 ++- __tests__/installer.test.ts | 5 +++-- dist/cache-save/index.js | 6 ++++-- dist/setup/index.js | 6 ++++-- src/cache-utils.ts | 6 ++++-- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/__tests__/cache-utils.test.ts b/__tests__/cache-utils.test.ts index d8934eba..9e8d653d 100644 --- a/__tests__/cache-utils.test.ts +++ b/__tests__/cache-utils.test.ts @@ -46,7 +46,8 @@ describe('cache-utils', () => { isFeatureAvailable.mockImplementation(() => false); process.env['GITHUB_SERVER_URL'] = 'https://www.test.com'; - expect(() => isCacheFeatureAvailable()).toThrowError( + expect(isCacheFeatureAvailable()).toBeFalsy(); + expect(warningSpy).toHaveBeenCalledWith( 'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.' ); }); diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 3c3105e2..2a74f78f 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -728,8 +728,9 @@ describe('setup-node', () => { await main.run(); - expect(cnSpy).toHaveBeenCalledWith( - `::error::Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.${osm.EOL}` + expect(warningSpy).toHaveBeenCalledWith( + // `::error::Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.${osm.EOL}` + 'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.' ); }); diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index 5f499403..d099eecb 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -61187,8 +61187,10 @@ exports.isGhes = isGhes; function isCacheFeatureAvailable() { if (cache.isFeatureAvailable()) return true; - if (isGhes()) - throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); + if (isGhes()) { + core.warning('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); + return false; + } core.warning('The runner was not able to contact the cache service. Caching will be skipped'); return false; } diff --git a/dist/setup/index.js b/dist/setup/index.js index af122147..01a4548b 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73141,8 +73141,10 @@ exports.isGhes = isGhes; function isCacheFeatureAvailable() { if (cache.isFeatureAvailable()) return true; - if (isGhes()) - throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); + if (isGhes()) { + core.warning('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); + return false; + } core.warning('The runner was not able to contact the cache service. Caching will be skipped'); return false; } diff --git a/src/cache-utils.ts b/src/cache-utils.ts index 065d347e..5df3e718 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -107,10 +107,12 @@ export function isGhes(): boolean { export function isCacheFeatureAvailable(): boolean { if (cache.isFeatureAvailable()) return true; - if (isGhes()) - throw new Error( + if (isGhes()) { + core.warning( 'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.' ); + return false; + } core.warning( 'The runner was not able to contact the cache service. Caching will be skipped' From bbe2ac79a1347190c27c8a7ca53301a26c066415 Mon Sep 17 00:00:00 2001 From: Evan Mattson Date: Mon, 19 Dec 2022 04:12:38 -0500 Subject: [PATCH 7/7] Fix typo in README (#646) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f2fbd3d9..072da659 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ If the runner is not able to access github.com, any Nodejs versions requested du 1. [Check latest version](docs/advanced-usage.md#check-latest-version) 2. [Using a node version file](docs/advanced-usage.md#node-version-file) 3. [Using different architectures](docs/advanced-usage.md#architecture) -4. [Using nigthly versions](docs/advanced-usage.md#nightly-versions) +4. [Using nightly versions](docs/advanced-usage.md#nightly-versions) 5. [Using rc versions](docs/advanced-usage.md#rc-versions) 6. [Caching packages data](docs/advanced-usage.md#caching-packages-data) 7. [Using multiple operating systems and architectures](docs/advanced-usage.md#multiple-operating-systems-and-architectures)