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