Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Contributor

@allisaurus allisaurus May 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the mocked return value be registries: { with: [1111111111] } ?
EDIT: ugh I realize this was backwards; but the below comment saw what I was getting at :P

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to mock the configuration:

      - name: Login to Amazon ECR
        id: login-ecr
        uses: aws-actions/amazon-ecr-login@v1
        with:
          registries: 1111111111

The GH actions toolkit takes care of parsing the config, and then the action just does core.getInput('registries')

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