mirror of
				https://github.com/actions/setup-node.git
				synced 2025-11-04 13:29:12 +08:00 
			
		
		
		
	Merge pull request #639 from akv-platform/v-sdolin/early-return
Use early return pattern to avoid nested conditions
This commit is contained in:
		@@ -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.'
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -728,8 +728,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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										14
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										14
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							@@ -73139,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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user