Skip to content

Commit

Permalink
feat: output registry URI if single registry ID is provided as input (#…
Browse files Browse the repository at this point in the history
…50)

* feat: output registry URI if single registry ID is provided as input

* Package

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
clareliguori and mergify[bot] authored May 27, 2020
1 parent a750761 commit cfd96f4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 2 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
31 changes: 31 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit cfd96f4

Please sign in to comment.