mirror of
				https://github.com/actions/setup-go.git
				synced 2025-10-31 15:23:42 +00:00 
			
		
		
		
	Update self-hosted environment validation and bump undici version (#556)
* Fix self-hosted environment check * Update isSelfHosted logic
This commit is contained in:
		
							parent
							
								
									691cc3533f
								
							
						
					
					
						commit
						dca8468d37
					
				
							
								
								
									
										52
									
								
								__tests__/utils.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								__tests__/utils.test.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,52 @@ | ||||
| import {isSelfHosted} from '../src/utils'; | ||||
| 
 | ||||
| describe('utils', () => { | ||||
|   describe('isSelfHosted', () => { | ||||
|     let AGENT_ISSELFHOSTED: string | undefined; | ||||
|     let RUNNER_ENVIRONMENT: string | undefined; | ||||
| 
 | ||||
|     beforeEach(() => { | ||||
|       AGENT_ISSELFHOSTED = process.env['AGENT_ISSELFHOSTED']; | ||||
|       delete process.env['AGENT_ISSELFHOSTED']; | ||||
|       RUNNER_ENVIRONMENT = process.env['RUNNER_ENVIRONMENT']; | ||||
|       delete process.env['RUNNER_ENVIRONMENT']; | ||||
|     }); | ||||
| 
 | ||||
|     afterEach(() => { | ||||
|       if (AGENT_ISSELFHOSTED === undefined) { | ||||
|         delete process.env['AGENT_ISSELFHOSTED']; | ||||
|       } else { | ||||
|         process.env['AGENT_ISSELFHOSTED'] = AGENT_ISSELFHOSTED; | ||||
|       } | ||||
|       if (RUNNER_ENVIRONMENT === undefined) { | ||||
|         delete process.env['RUNNER_ENVIRONMENT']; | ||||
|       } else { | ||||
|         process.env['RUNNER_ENVIRONMENT'] = RUNNER_ENVIRONMENT; | ||||
|       } | ||||
|     }); | ||||
| 
 | ||||
|     it('isSelfHosted should be true if no environment variables set', () => { | ||||
|       expect(isSelfHosted()).toBeTruthy(); | ||||
|     }); | ||||
| 
 | ||||
|     it('isSelfHosted should be true if environment variable is not set to denote GitHub hosted', () => { | ||||
|       process.env['RUNNER_ENVIRONMENT'] = 'some'; | ||||
|       expect(isSelfHosted()).toBeTruthy(); | ||||
|     }); | ||||
| 
 | ||||
|     it('isSelfHosted should be true if environment variable set to denote Azure Pipelines self hosted', () => { | ||||
|       process.env['AGENT_ISSELFHOSTED'] = '1'; | ||||
|       expect(isSelfHosted()).toBeTruthy(); | ||||
|     }); | ||||
| 
 | ||||
|     it('isSelfHosted should be false if environment variable set to denote GitHub hosted', () => { | ||||
|       process.env['RUNNER_ENVIRONMENT'] = 'github-hosted'; | ||||
|       expect(isSelfHosted()).toBeFalsy(); | ||||
|     }); | ||||
| 
 | ||||
|     it('isSelfHosted should be false if environment variable is not set to denote Azure Pipelines self hosted', () => { | ||||
|       process.env['AGENT_ISSELFHOSTED'] = 'some'; | ||||
|       expect(isSelfHosted()).toBeFalsy(); | ||||
|     }); | ||||
|   }); | ||||
| }); | ||||
							
								
								
									
										14
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										14
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							| @ -93353,8 +93353,7 @@ function cacheWindowsDir(extPath, tool, version, arch) { | ||||
|         if (os_1.default.platform() !== 'win32') | ||||
|             return false; | ||||
|         // make sure the action runs in the hosted environment
 | ||||
|         if (process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && | ||||
|             process.env['AGENT_ISSELFHOSTED'] === '1') | ||||
|         if ((0, utils_1.isSelfHosted)()) | ||||
|             return false; | ||||
|         const defaultToolCacheRoot = process.env['RUNNER_TOOL_CACHE']; | ||||
|         if (!defaultToolCacheRoot) | ||||
| @ -93861,12 +93860,21 @@ exports.getArch = getArch; | ||||
| "use strict"; | ||||
| 
 | ||||
| Object.defineProperty(exports, "__esModule", ({ value: true })); | ||||
| exports.StableReleaseAlias = void 0; | ||||
| exports.isSelfHosted = exports.StableReleaseAlias = void 0; | ||||
| var StableReleaseAlias; | ||||
| (function (StableReleaseAlias) { | ||||
|     StableReleaseAlias["Stable"] = "stable"; | ||||
|     StableReleaseAlias["OldStable"] = "oldstable"; | ||||
| })(StableReleaseAlias || (exports.StableReleaseAlias = StableReleaseAlias = {})); | ||||
| const isSelfHosted = () => process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && | ||||
|     (process.env['AGENT_ISSELFHOSTED'] === '1' || | ||||
|         process.env['AGENT_ISSELFHOSTED'] === undefined); | ||||
| exports.isSelfHosted = isSelfHosted; | ||||
| /* the above is simplified from: | ||||
|     process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && process.env['AGENT_ISSELFHOSTED'] === '1' | ||||
|     || | ||||
|     process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && process.env['AGENT_ISSELFHOSTED'] === undefined | ||||
| */ | ||||
| 
 | ||||
| 
 | ||||
| /***/ }), | ||||
|  | ||||
| @ -6,7 +6,7 @@ import * as httpm from '@actions/http-client'; | ||||
| import * as sys from './system'; | ||||
| import fs from 'fs'; | ||||
| import os from 'os'; | ||||
| import {StableReleaseAlias} from './utils'; | ||||
| import {StableReleaseAlias, isSelfHosted} from './utils'; | ||||
| 
 | ||||
| const MANIFEST_REPO_OWNER = 'actions'; | ||||
| const MANIFEST_REPO_NAME = 'go-versions'; | ||||
| @ -180,11 +180,7 @@ async function cacheWindowsDir( | ||||
|   if (os.platform() !== 'win32') return false; | ||||
| 
 | ||||
|   // make sure the action runs in the hosted environment
 | ||||
|   if ( | ||||
|     process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && | ||||
|     process.env['AGENT_ISSELFHOSTED'] === '1' | ||||
|   ) | ||||
|     return false; | ||||
|   if (isSelfHosted()) return false; | ||||
| 
 | ||||
|   const defaultToolCacheRoot = process.env['RUNNER_TOOL_CACHE']; | ||||
|   if (!defaultToolCacheRoot) return false; | ||||
|  | ||||
							
								
								
									
										10
									
								
								src/utils.ts
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/utils.ts
									
									
									
									
									
								
							| @ -2,3 +2,13 @@ export enum StableReleaseAlias { | ||||
|   Stable = 'stable', | ||||
|   OldStable = 'oldstable' | ||||
| } | ||||
| 
 | ||||
| export const isSelfHosted = (): boolean => | ||||
|   process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && | ||||
|   (process.env['AGENT_ISSELFHOSTED'] === '1' || | ||||
|     process.env['AGENT_ISSELFHOSTED'] === undefined); | ||||
| /* the above is simplified from: | ||||
|     process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && process.env['AGENT_ISSELFHOSTED'] === '1' | ||||
|     || | ||||
|     process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && process.env['AGENT_ISSELFHOSTED'] === undefined | ||||
| */ | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user