mirror of
https://github.com/actions/setup-node.git
synced 2025-04-23 20:10:48 +00:00
Merge branch 'main' into v-dmshib/v8-canary-factory
This commit is contained in:
commit
822a587e93
8 changed files with 115 additions and 41 deletions
|
@ -21,7 +21,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Update the ${{ env.TAG_NAME }} tag
|
- name: Update the ${{ env.TAG_NAME }} tag
|
||||||
uses: actions/publish-action@v0.1.0
|
uses: actions/publish-action@v0.2.1
|
||||||
with:
|
with:
|
||||||
source-tag: ${{ env.TAG_NAME }}
|
source-tag: ${{ env.TAG_NAME }}
|
||||||
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
||||||
|
|
|
@ -123,6 +123,7 @@ describe('authutil tests', () => {
|
||||||
expect(rc['registry']).toBe('https://registry.npmjs.org/');
|
expect(rc['registry']).toBe('https://registry.npmjs.org/');
|
||||||
expect(rc['always-auth']).toBe('true');
|
expect(rc['always-auth']).toBe('true');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('It is already set the NODE_AUTH_TOKEN export it ', async () => {
|
it('It is already set the NODE_AUTH_TOKEN export it ', async () => {
|
||||||
process.env.NODE_AUTH_TOKEN = 'foobar';
|
process.env.NODE_AUTH_TOKEN = 'foobar';
|
||||||
await auth.configAuthentication('npm.pkg.github.com', 'false');
|
await auth.configAuthentication('npm.pkg.github.com', 'false');
|
||||||
|
@ -132,4 +133,84 @@ describe('authutil tests', () => {
|
||||||
expect(rc['always-auth']).toBe('false');
|
expect(rc['always-auth']).toBe('false');
|
||||||
expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar');
|
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`
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -46,7 +46,8 @@ describe('cache-utils', () => {
|
||||||
isFeatureAvailable.mockImplementation(() => false);
|
isFeatureAvailable.mockImplementation(() => false);
|
||||||
process.env['GITHUB_SERVER_URL'] = 'https://www.test.com';
|
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.'
|
'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.'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -729,8 +729,9 @@ describe('setup-node', () => {
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
expect(cnSpy).toHaveBeenCalledWith(
|
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}`
|
// `::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.'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
14
dist/cache-save/index.js
vendored
14
dist/cache-save/index.js
vendored
|
@ -61185,16 +61185,14 @@ function isGhes() {
|
||||||
}
|
}
|
||||||
exports.isGhes = isGhes;
|
exports.isGhes = isGhes;
|
||||||
function isCacheFeatureAvailable() {
|
function isCacheFeatureAvailable() {
|
||||||
if (!cache.isFeatureAvailable()) {
|
if (cache.isFeatureAvailable())
|
||||||
if (isGhes()) {
|
return true;
|
||||||
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.');
|
||||||
else {
|
|
||||||
core.warning('The runner was not able to contact the cache service. Caching will be skipped');
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
core.warning('The runner was not able to contact the cache service. Caching will be skipped');
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
||||||
|
|
||||||
|
|
22
dist/setup/index.js
vendored
22
dist/setup/index.js
vendored
|
@ -72945,7 +72945,7 @@ function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) {
|
||||||
scope = '@' + scope;
|
scope = '@' + scope;
|
||||||
}
|
}
|
||||||
if (scope) {
|
if (scope) {
|
||||||
scope = scope.toLowerCase();
|
scope = scope.toLowerCase() + ':';
|
||||||
}
|
}
|
||||||
core.debug(`Setting auth in ${fileLocation}`);
|
core.debug(`Setting auth in ${fileLocation}`);
|
||||||
let newContents = '';
|
let newContents = '';
|
||||||
|
@ -72953,16 +72953,14 @@ function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) {
|
||||||
const curContents = fs.readFileSync(fileLocation, 'utf8');
|
const curContents = fs.readFileSync(fileLocation, 'utf8');
|
||||||
curContents.split(os.EOL).forEach((line) => {
|
curContents.split(os.EOL).forEach((line) => {
|
||||||
// Add current contents unless they are setting the registry
|
// Add current contents unless they are setting the registry
|
||||||
if (!line.toLowerCase().startsWith('registry')) {
|
if (!line.toLowerCase().startsWith(`${scope}registry`)) {
|
||||||
newContents += line + os.EOL;
|
newContents += line + os.EOL;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Remove http: or https: from front of registry.
|
// Remove http: or https: from front of registry.
|
||||||
const authString = registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}';
|
const authString = registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}';
|
||||||
const registryString = scope
|
const registryString = `${scope}registry=${registryUrl}`;
|
||||||
? `${scope}:registry=${registryUrl}`
|
|
||||||
: `registry=${registryUrl}`;
|
|
||||||
const alwaysAuthString = `always-auth=${alwaysAuth}`;
|
const alwaysAuthString = `always-auth=${alwaysAuth}`;
|
||||||
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
|
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
|
||||||
fs.writeFileSync(fileLocation, newContents);
|
fs.writeFileSync(fileLocation, newContents);
|
||||||
|
@ -73141,16 +73139,14 @@ function isGhes() {
|
||||||
}
|
}
|
||||||
exports.isGhes = isGhes;
|
exports.isGhes = isGhes;
|
||||||
function isCacheFeatureAvailable() {
|
function isCacheFeatureAvailable() {
|
||||||
if (!cache.isFeatureAvailable()) {
|
if (cache.isFeatureAvailable())
|
||||||
if (isGhes()) {
|
return true;
|
||||||
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.');
|
||||||
else {
|
|
||||||
core.warning('The runner was not able to contact the cache service. Caching will be skipped');
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
core.warning('The runner was not able to contact the cache service. Caching will be skipped');
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ function writeRegistryToFile(
|
||||||
scope = '@' + scope;
|
scope = '@' + scope;
|
||||||
}
|
}
|
||||||
if (scope) {
|
if (scope) {
|
||||||
scope = scope.toLowerCase();
|
scope = scope.toLowerCase() + ':';
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug(`Setting auth in ${fileLocation}`);
|
core.debug(`Setting auth in ${fileLocation}`);
|
||||||
|
@ -38,7 +38,7 @@ function writeRegistryToFile(
|
||||||
const curContents: string = fs.readFileSync(fileLocation, 'utf8');
|
const curContents: string = fs.readFileSync(fileLocation, 'utf8');
|
||||||
curContents.split(os.EOL).forEach((line: string) => {
|
curContents.split(os.EOL).forEach((line: string) => {
|
||||||
// Add current contents unless they are setting the registry
|
// Add current contents unless they are setting the registry
|
||||||
if (!line.toLowerCase().startsWith('registry')) {
|
if (!line.toLowerCase().startsWith(`${scope}registry`)) {
|
||||||
newContents += line + os.EOL;
|
newContents += line + os.EOL;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -46,9 +46,7 @@ function writeRegistryToFile(
|
||||||
// Remove http: or https: from front of registry.
|
// Remove http: or https: from front of registry.
|
||||||
const authString: string =
|
const authString: string =
|
||||||
registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}';
|
registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}';
|
||||||
const registryString: string = scope
|
const registryString: string = `${scope}registry=${registryUrl}`;
|
||||||
? `${scope}:registry=${registryUrl}`
|
|
||||||
: `registry=${registryUrl}`;
|
|
||||||
const alwaysAuthString: string = `always-auth=${alwaysAuth}`;
|
const alwaysAuthString: string = `always-auth=${alwaysAuth}`;
|
||||||
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
|
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
|
||||||
fs.writeFileSync(fileLocation, newContents);
|
fs.writeFileSync(fileLocation, newContents);
|
||||||
|
|
|
@ -105,19 +105,18 @@ export function isGhes(): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isCacheFeatureAvailable(): boolean {
|
export function isCacheFeatureAvailable(): boolean {
|
||||||
if (!cache.isFeatureAvailable()) {
|
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.'
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
core.warning(
|
|
||||||
'The runner was not able to contact the cache service. Caching will be skipped'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
core.warning(
|
||||||
|
'The runner was not able to contact the cache service. Caching will be skipped'
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue