From 10f17825919d677ddd26482a0848b9be0c06301f Mon Sep 17 00:00:00 2001 From: Clare Liguori Date: Mon, 25 May 2020 13:33:08 -0700 Subject: [PATCH 1/2] feat: output registry URI if single registry ID is provided as input --- action.yml | 2 +- index.js | 4 ++-- index.test.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 3e57ba22..1ec590a9 100644 --- a/action.yml +++ b/action.yml @@ -9,7 +9,7 @@ inputs: required: false outputs: registry: - description: 'The URI of the default ECR registry i.e. aws_account_id.dkr.ecr.region.amazonaws.com, if none were provided as inputs' + description: 'The URI of the ECR registry i.e. aws_account_id.dkr.ecr.region.amazonaws.com. If multiple registries are provided as inputs, this output will not be set.' runs: using: 'node12' main: 'dist/index.js' diff --git a/index.js b/index.js index a7e28d40..b3969bcb 100644 --- a/index.js +++ b/index.js @@ -29,8 +29,8 @@ async function run() { const creds = authToken.split(':', 2); const proxyEndpoint = authData.proxyEndpoint; - if (!registries) { - // output the default registry if none were provided + if (authTokenResponse.authorizationData.length == 1) { + // output the registry URI if this action is doing a single registry login const registryId = proxyEndpoint.replace(/^https?:\/\//,''); core.setOutput('registry', registryId); } diff --git a/index.test.js b/index.test.js index aa3005b3..ab405a9a 100644 --- a/index.test.js +++ b/index.test.js @@ -85,6 +85,37 @@ describe('Login to ECR', () => { expect.anything()); }); + test('outputs the registry ID if a single registry is provided in the input', async () => { + core.getInput = jest.fn().mockReturnValueOnce('111111111111'); + mockEcrGetAuthToken.mockImplementation(() => { + return { + promise() { + return Promise.resolve({ + authorizationData: [ + { + authorizationToken: Buffer.from('foo:bar').toString('base64'), + proxyEndpoint: 'https://111111111111.dkr.ecr.aws-region-1.amazonaws.com' + } + ] + }); + } + }; + }); + + await run(); + + expect(mockEcrGetAuthToken).toHaveBeenCalledWith({ + registryIds: ['111111111111'] + }); + expect(core.setOutput).toHaveBeenCalledTimes(1); + expect(core.setOutput).toHaveBeenNthCalledWith(1, 'registry', '111111111111.dkr.ecr.aws-region-1.amazonaws.com'); + expect(exec.exec).toHaveBeenCalledTimes(1); + expect(exec.exec).toHaveBeenNthCalledWith(1, + 'docker login', + ['-u', 'foo', '-p', 'bar', 'https://111111111111.dkr.ecr.aws-region-1.amazonaws.com'], + expect.anything()); + }); + test('error is caught by core.setFailed for failed docker login', async () => { exec.exec.mockReturnValue(1); From 84501d02f3ddfa537f68e9e7be639dc8b962ff06 Mon Sep 17 00:00:00 2001 From: Clare Liguori Date: Tue, 26 May 2020 20:18:58 -0700 Subject: [PATCH 2/2] Package --- dist/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 4511c83d..287d08fd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -459,8 +459,8 @@ async function run() { const creds = authToken.split(':', 2); const proxyEndpoint = authData.proxyEndpoint; - if (!registries) { - // output the default registry if none were provided + if (authTokenResponse.authorizationData.length == 1) { + // output the registry URI if this action is doing a single registry login const registryId = proxyEndpoint.replace(/^https?:\/\//,''); core.setOutput('registry', registryId); }