mirror of
				https://github.com/docker/login-action.git
				synced 2025-10-31 10:10:09 +08:00 
			
		
		
		
	fix cases: kebab for action, camelCase for TS
Signed-off-by: Fedor Dikarev <fedor.dikarev@gmail.com>
This commit is contained in:
		
							parent
							
								
									c4d11d0a1e
								
							
						
					
					
						commit
						1e8f0ae375
					
				| @ -6,15 +6,15 @@ import {login} from '../src/docker'; | |||||||
| import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; | import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; | ||||||
| 
 | 
 | ||||||
| test('login retries function', async () => { | test('login retries function', async () => { | ||||||
|   let stderr_strings: string[] = []; |   let stderrStrings: string[] = []; | ||||||
|   let call_count: number = -1; |   let callCount: number = -1; | ||||||
| 
 | 
 | ||||||
|   // using spyOn() here isn't enough, as we alter the logic
 |   // using spyOn() here isn't enough, as we alter the logic
 | ||||||
|   // so use `jest.fn()` here for the `Docker.getExecOutput`
 |   // so use `jest.fn()` here for the `Docker.getExecOutput`
 | ||||||
|   Docker.getExecOutput = jest.fn(async () => { |   Docker.getExecOutput = jest.fn(async () => { | ||||||
|     call_count++; |     callCount++; | ||||||
|     console.log(`Mock: ${call_count}, ${stderr_strings}`); |     console.log(`Mock: ${callCount}, ${stderrStrings}`); | ||||||
|     if (call_count >= stderr_strings.length) { |     if (callCount >= stderrStrings.length) { | ||||||
|       return { |       return { | ||||||
|         exitCode: 0, |         exitCode: 0, | ||||||
|         stdout: 'Mock success', |         stdout: 'Mock success', | ||||||
| @ -24,7 +24,7 @@ test('login retries function', async () => { | |||||||
|     return { |     return { | ||||||
|       exitCode: 1, |       exitCode: 1, | ||||||
|       stdout: '', |       stdout: '', | ||||||
|       stderr: stderr_strings[call_count % stderr_strings.length] |       stderr: stderrStrings[callCount % stderrStrings.length] | ||||||
|     }; |     }; | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
| @ -32,15 +32,15 @@ test('login retries function', async () => { | |||||||
|   const password = 'groundcontrol'; |   const password = 'groundcontrol'; | ||||||
|   const registry = 'https://ghcr.io'; |   const registry = 'https://ghcr.io'; | ||||||
| 
 | 
 | ||||||
|   stderr_strings = ['mock error, failed with status: 408 Request Timeout', 'mock error, failed with status: 502 Request Timeout', 'mock error, failed with status: 400 Request Timeout']; |   stderrStrings = ['mock error, failed with status: 408 Request Timeout', 'mock error, failed with status: 502 Request Timeout', 'mock error, failed with status: 400 Request Timeout']; | ||||||
|   call_count = -1; |   callCount = -1; | ||||||
|   await expect(async () => { |   await expect(async () => { | ||||||
|     await login(registry, username, password, 'false', ['408', '400'], 5, 0.1); |     await login(registry, username, password, 'false', ['408', '400'], 5, 0.1); | ||||||
|   }).rejects.toThrow('mock error, failed with status: 502 Request Timeout'); |   }).rejects.toThrow('mock error, failed with status: 502 Request Timeout'); | ||||||
|   expect(Docker.getExecOutput).toHaveBeenCalledTimes(2); |   expect(Docker.getExecOutput).toHaveBeenCalledTimes(2); | ||||||
| 
 | 
 | ||||||
|   stderr_strings = ['not matching error', 'mock error, failed with status: 502 Request Timeout', 'mock error, failed with status: 400 Request Timeout']; |   stderrStrings = ['not matching error', 'mock error, failed with status: 502 Request Timeout', 'mock error, failed with status: 400 Request Timeout']; | ||||||
|   call_count = -1; |   callCount = -1; | ||||||
|   await expect(async () => { |   await expect(async () => { | ||||||
|     await login(registry, username, password, 'false', ['408', '400'], 5, 0.1); |     await login(registry, username, password, 'false', ['408', '400'], 5, 0.1); | ||||||
|   }).rejects.toThrow('not matching error'); |   }).rejects.toThrow('not matching error'); | ||||||
|  | |||||||
| @ -4,15 +4,15 @@ import {login} from '../src/docker'; | |||||||
| import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; | import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; | ||||||
| 
 | 
 | ||||||
| test('login retries success function', async () => { | test('login retries success function', async () => { | ||||||
|   let stderr_strings: string[] = []; |   let stderrStrings: string[] = []; | ||||||
|   let call_count: number = -1; |   let callCount: number = -1; | ||||||
| 
 | 
 | ||||||
|   // using spyOn() here isn't enough, as we alter the logic
 |   // using spyOn() here isn't enough, as we alter the logic
 | ||||||
|   // so use `jest.fn()` here for the `Docker.getExecOutput`
 |   // so use `jest.fn()` here for the `Docker.getExecOutput`
 | ||||||
|   Docker.getExecOutput = jest.fn(async () => { |   Docker.getExecOutput = jest.fn(async () => { | ||||||
|     call_count++; |     callCount++; | ||||||
|     console.log(`Mock: ${call_count}, ${stderr_strings}`); |     console.log(`Mock: ${callCount}, ${stderrStrings}`); | ||||||
|     if (call_count >= stderr_strings.length) { |     if (callCount >= stderrStrings.length) { | ||||||
|       return { |       return { | ||||||
|         exitCode: 0, |         exitCode: 0, | ||||||
|         stdout: 'Mock success', |         stdout: 'Mock success', | ||||||
| @ -22,7 +22,7 @@ test('login retries success function', async () => { | |||||||
|     return { |     return { | ||||||
|       exitCode: 1, |       exitCode: 1, | ||||||
|       stdout: '', |       stdout: '', | ||||||
|       stderr: stderr_strings[call_count % stderr_strings.length] |       stderr: stderrStrings[callCount % stderrStrings.length] | ||||||
|     }; |     }; | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
| @ -30,13 +30,13 @@ test('login retries success function', async () => { | |||||||
|   const password = 'groundcontrol'; |   const password = 'groundcontrol'; | ||||||
|   const registry = 'https://ghcr.io'; |   const registry = 'https://ghcr.io'; | ||||||
| 
 | 
 | ||||||
|   stderr_strings = []; |   stderrStrings = []; | ||||||
|   call_count = -1; |   callCount = -1; | ||||||
|   await login(registry, username, password, 'false', ['408', '502', '400'], 5, 0.1); |   await login(registry, username, password, 'false', ['408', '502', '400'], 5, 0.1); | ||||||
|   expect(Docker.getExecOutput).toHaveBeenCalledTimes(1); |   expect(Docker.getExecOutput).toHaveBeenCalledTimes(1); | ||||||
| 
 | 
 | ||||||
|   stderr_strings = ['mock error, failed with status: 408 Request Timeout', 'mock error, failed with status: 502 Request Timeout', 'mock error, failed with status: 400 Request Timeout']; |   stderrStrings = ['mock error, failed with status: 408 Request Timeout', 'mock error, failed with status: 502 Request Timeout', 'mock error, failed with status: 400 Request Timeout']; | ||||||
|   call_count = -1; |   callCount = -1; | ||||||
|   await login(registry, username, password, 'false', ['408', '502', '400'], 5, 0.1); |   await login(registry, username, password, 'false', ['408', '502', '400'], 5, 0.1); | ||||||
|   expect(Docker.getExecOutput).toHaveBeenCalledTimes(1 + 4); |   expect(Docker.getExecOutput).toHaveBeenCalledTimes(1 + 4); | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -6,9 +6,9 @@ export interface Inputs { | |||||||
|   password: string; |   password: string; | ||||||
|   ecr: string; |   ecr: string; | ||||||
|   logout: boolean; |   logout: boolean; | ||||||
|   http_codes_to_retry: string[]; |   httpCodesToRetry: string[]; | ||||||
|   max_attempts: number; |   maxAttempts: number; | ||||||
|   retry_timeout: number; |   retryTimeout: number; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export function getInputs(): Inputs { | export function getInputs(): Inputs { | ||||||
| @ -18,8 +18,8 @@ export function getInputs(): Inputs { | |||||||
|     password: core.getInput('password'), |     password: core.getInput('password'), | ||||||
|     ecr: core.getInput('ecr'), |     ecr: core.getInput('ecr'), | ||||||
|     logout: core.getBooleanInput('logout'), |     logout: core.getBooleanInput('logout'), | ||||||
|     http_codes_to_retry: core.getInput('http_codes_to_retry').split(','), |     httpCodesToRetry: core.getInput('http-codes-to-retry').split(','), | ||||||
|     max_attempts: Number.parseInt(core.getInput('max_attempts')), |     maxAttempts: Number.parseInt(core.getInput('max-attempts')), | ||||||
|     retry_timeout: Number.parseInt(core.getInput('retry_timeout')) |     retryTimeout: Number.parseInt(core.getInput('retry-timeout')) | ||||||
|   }; |   }; | ||||||
| } | } | ||||||
|  | |||||||
| @ -3,9 +3,9 @@ import * as core from '@actions/core'; | |||||||
| 
 | 
 | ||||||
| import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; | import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; | ||||||
| 
 | 
 | ||||||
| export async function login(registry: string, username: string, password: string, ecr: string, http_codes_to_retry: string[], max_attempts: number, retry_timeout: number): Promise<void> { | export async function login(registry: string, username: string, password: string, ecr: string, httpCodesToRetry: string[], maxAttempts: number, retryTimeout: number): Promise<void> { | ||||||
|   let succeeded: boolean = false; |   let succeeded: boolean = false; | ||||||
|   for (let attempt = 1; attempt <= max_attempts && !succeeded; attempt++) { |   for (let attempt = 1; attempt <= maxAttempts && !succeeded; attempt++) { | ||||||
|     try { |     try { | ||||||
|       if (/true/i.test(ecr) || (ecr == 'auto' && aws.isECR(registry))) { |       if (/true/i.test(ecr) || (ecr == 'auto' && aws.isECR(registry))) { | ||||||
|         await loginECR(registry, username, password); |         await loginECR(registry, username, password); | ||||||
| @ -14,9 +14,9 @@ export async function login(registry: string, username: string, password: string | |||||||
|       } |       } | ||||||
|       succeeded = true; |       succeeded = true; | ||||||
|     } catch (error) { |     } catch (error) { | ||||||
|       if (attempt < max_attempts && isRetriableError(error.message, http_codes_to_retry)) { |       if (attempt < maxAttempts && isRetriableError(error.message, httpCodesToRetry)) { | ||||||
|         core.info(`Attempt ${attempt} out of ${max_attempts} failed, retrying after ${retry_timeout} seconds`); |         core.info(`Attempt ${attempt} out of ${maxAttempts} failed, retrying after ${retryTimeout} seconds`); | ||||||
|         await new Promise(r => setTimeout(r, retry_timeout * 1000)); |         await new Promise(r => setTimeout(r, retryTimeout * 1000)); | ||||||
|       } else { |       } else { | ||||||
|         throw error; |         throw error; | ||||||
|       } |       } | ||||||
| @ -34,14 +34,14 @@ export async function logout(registry: string): Promise<void> { | |||||||
|   }); |   }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function isRetriableError(error_message: string, http_codes_to_retry: string[]): boolean { | function isRetriableError(errorMessage: string, httpCodesToRetry: string[]): boolean { | ||||||
|   for (const err_code of http_codes_to_retry) { |   for (const errCode of httpCodesToRetry) { | ||||||
|     if (error_message.includes('failed with status: ' + err_code)) { |     if (errorMessage.includes('failed with status: ' + errCode)) { | ||||||
|       core.info(`Retryable match found in ${error_message} for retryable code: ${err_code}`); |       core.info(`Retryable match found in ${errorMessage} for retryable code: ${errCode}`); | ||||||
|       return true; |       return true; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   core.info(`No matches in ${error_message} when lookging for retryable codes: ${http_codes_to_retry}`); |   core.info(`No matches in ${errorMessage} when lookging for retryable codes: ${httpCodesToRetry}`); | ||||||
|   return false; |   return false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ export async function main(): Promise<void> { | |||||||
|   const input: context.Inputs = context.getInputs(); |   const input: context.Inputs = context.getInputs(); | ||||||
|   stateHelper.setRegistry(input.registry); |   stateHelper.setRegistry(input.registry); | ||||||
|   stateHelper.setLogout(input.logout); |   stateHelper.setLogout(input.logout); | ||||||
|   await docker.login(input.registry, input.username, input.password, input.ecr, input.http_codes_to_retry, input.max_attempts, input.retry_timeout); |   await docker.login(input.registry, input.username, input.password, input.ecr, input.httpCodesToRetry, input.maxAttempts, input.retryTimeout); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async function post(): Promise<void> { | async function post(): Promise<void> { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Fedor Dikarev
						Fedor Dikarev