Merge pull request #250 from jromero/feature/windows-download-filename
Use explicit filename when downloading Windows go package
This commit is contained in:
		
						commit
						f279813975
					
				| @ -13,6 +13,8 @@ let matchers = require('../matchers.json'); | |||||||
| let goTestManifest = require('./data/versions-manifest.json'); | let goTestManifest = require('./data/versions-manifest.json'); | ||||||
| let matcherPattern = matchers.problemMatcher[0].pattern[0]; | let matcherPattern = matchers.problemMatcher[0].pattern[0]; | ||||||
| let matcherRegExp = new RegExp(matcherPattern.regexp); | let matcherRegExp = new RegExp(matcherPattern.regexp); | ||||||
|  | let win32Join = path.win32.join; | ||||||
|  | let posixJoin = path.posix.join; | ||||||
| 
 | 
 | ||||||
| describe('setup-go', () => { | describe('setup-go', () => { | ||||||
|   let inputs = {} as any; |   let inputs = {} as any; | ||||||
| @ -27,8 +29,10 @@ describe('setup-go', () => { | |||||||
|   let getSpy: jest.SpyInstance; |   let getSpy: jest.SpyInstance; | ||||||
|   let platSpy: jest.SpyInstance; |   let platSpy: jest.SpyInstance; | ||||||
|   let archSpy: jest.SpyInstance; |   let archSpy: jest.SpyInstance; | ||||||
|  |   let joinSpy: jest.SpyInstance; | ||||||
|   let dlSpy: jest.SpyInstance; |   let dlSpy: jest.SpyInstance; | ||||||
|   let extractTarSpy: jest.SpyInstance; |   let extractTarSpy: jest.SpyInstance; | ||||||
|  |   let extractZipSpy: jest.SpyInstance; | ||||||
|   let cacheSpy: jest.SpyInstance; |   let cacheSpy: jest.SpyInstance; | ||||||
|   let dbgSpy: jest.SpyInstance; |   let dbgSpy: jest.SpyInstance; | ||||||
|   let whichSpy: jest.SpyInstance; |   let whichSpy: jest.SpyInstance; | ||||||
| @ -61,10 +65,21 @@ describe('setup-go', () => { | |||||||
|     archSpy.mockImplementation(() => os['arch']); |     archSpy.mockImplementation(() => os['arch']); | ||||||
|     execSpy = jest.spyOn(cp, 'execSync'); |     execSpy = jest.spyOn(cp, 'execSync'); | ||||||
| 
 | 
 | ||||||
|  |     // switch path join behaviour based on set os.platform
 | ||||||
|  |     joinSpy = jest.spyOn(path, 'join'); | ||||||
|  |     joinSpy.mockImplementation((...paths: string[]): string => { | ||||||
|  |       if (os['platform'] == 'win32') { | ||||||
|  |         return win32Join(...paths); | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|  |       return posixJoin(...paths); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|     // @actions/tool-cache
 |     // @actions/tool-cache
 | ||||||
|     findSpy = jest.spyOn(tc, 'find'); |     findSpy = jest.spyOn(tc, 'find'); | ||||||
|     dlSpy = jest.spyOn(tc, 'downloadTool'); |     dlSpy = jest.spyOn(tc, 'downloadTool'); | ||||||
|     extractTarSpy = jest.spyOn(tc, 'extractTar'); |     extractTarSpy = jest.spyOn(tc, 'extractTar'); | ||||||
|  |     extractZipSpy = jest.spyOn(tc, 'extractZip'); | ||||||
|     cacheSpy = jest.spyOn(tc, 'cacheDir'); |     cacheSpy = jest.spyOn(tc, 'cacheDir'); | ||||||
|     getSpy = jest.spyOn(im, 'getVersionsDist'); |     getSpy = jest.spyOn(im, 'getVersionsDist'); | ||||||
|     getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo'); |     getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo'); | ||||||
| @ -325,6 +340,31 @@ describe('setup-go', () => { | |||||||
|     expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); |     expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|  |   it('downloads a version not in the cache (windows)', async () => { | ||||||
|  |     os.platform = 'win32'; | ||||||
|  |     os.arch = 'x64'; | ||||||
|  | 
 | ||||||
|  |     inputs['go-version'] = '1.13.1'; | ||||||
|  |     process.env['RUNNER_TEMP'] = 'C:\\temp\\'; | ||||||
|  | 
 | ||||||
|  |     findSpy.mockImplementation(() => ''); | ||||||
|  |     dlSpy.mockImplementation(() => 'C:\\temp\\some\\path'); | ||||||
|  |     extractZipSpy.mockImplementation(() => 'C:\\temp\\some\\other\\path'); | ||||||
|  | 
 | ||||||
|  |     let toolPath = path.normalize('C:\\cache\\go\\1.13.0\\x64'); | ||||||
|  |     cacheSpy.mockImplementation(() => toolPath); | ||||||
|  | 
 | ||||||
|  |     await main.run(); | ||||||
|  | 
 | ||||||
|  |     let expPath = path.win32.join(toolPath, 'bin'); | ||||||
|  |     expect(dlSpy).toHaveBeenCalledWith( | ||||||
|  |       'https://storage.googleapis.com/golang/go1.13.1.windows-amd64.zip', | ||||||
|  |       'C:\\temp\\go1.13.1.windows-amd64.zip', | ||||||
|  |       undefined | ||||||
|  |     ); | ||||||
|  |     expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|   it('does not find a version that does not exist', async () => { |   it('does not find a version that does not exist', async () => { | ||||||
|     os.platform = 'linux'; |     os.platform = 'linux'; | ||||||
|     os.arch = 'x64'; |     os.arch = 'x64'; | ||||||
|  | |||||||
							
								
								
									
										6
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							| @ -62942,7 +62942,11 @@ function resolveVersionFromManifest(versionSpec, stable, auth) { | |||||||
| function installGoVersion(info, auth) { | function installGoVersion(info, auth) { | ||||||
|     return __awaiter(this, void 0, void 0, function* () { |     return __awaiter(this, void 0, void 0, function* () { | ||||||
|         core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); |         core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); | ||||||
|         const downloadPath = yield tc.downloadTool(info.downloadUrl, undefined, auth); |         // Windows requires that we keep the extension (.zip) for extraction
 | ||||||
|  |         const isWindows = os_1.default.platform() === 'win32'; | ||||||
|  |         const tempDir = process.env.RUNNER_TEMP || '.'; | ||||||
|  |         const fileName = isWindows ? path.join(tempDir, info.fileName) : undefined; | ||||||
|  |         const downloadPath = yield tc.downloadTool(info.downloadUrl, fileName, auth); | ||||||
|         core.info('Extracting Go...'); |         core.info('Extracting Go...'); | ||||||
|         let extPath = yield extractGoArchive(downloadPath); |         let extPath = yield extractGoArchive(downloadPath); | ||||||
|         core.info(`Successfully extracted go to ${extPath}`); |         core.info(`Successfully extracted go to ${extPath}`); | ||||||
|  | |||||||
| @ -132,7 +132,13 @@ async function installGoVersion( | |||||||
|   auth: string | undefined |   auth: string | undefined | ||||||
| ): Promise<string> { | ): Promise<string> { | ||||||
|   core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); |   core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); | ||||||
|   const downloadPath = await tc.downloadTool(info.downloadUrl, undefined, auth); | 
 | ||||||
|  |   // Windows requires that we keep the extension (.zip) for extraction
 | ||||||
|  |   const isWindows = os.platform() === 'win32'; | ||||||
|  |   const tempDir = process.env.RUNNER_TEMP || '.'; | ||||||
|  |   const fileName = isWindows ? path.join(tempDir, info.fileName) : undefined; | ||||||
|  | 
 | ||||||
|  |   const downloadPath = await tc.downloadTool(info.downloadUrl, fileName, auth); | ||||||
| 
 | 
 | ||||||
|   core.info('Extracting Go...'); |   core.info('Extracting Go...'); | ||||||
|   let extPath = await extractGoArchive(downloadPath); |   let extPath = await extractGoArchive(downloadPath); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user