Skip to content

Commit

Permalink
Merge pull request #123 from crazy-max/ecr-input
Browse files Browse the repository at this point in the history
ecr input to specify whether the given registry is ECR
  • Loading branch information
crazy-max authored Dec 20, 2021
2 parents b20b9f5 + b9a4d91 commit d9927c4
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: ci
on:
workflow_dispatch:
schedule:
- cron: '0 10 * * *' # everyday at 10am
- cron: '0 10 * * *'
push:
branches:
- 'master'
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ Following inputs can be used as `step.with` keys
| `registry` | String | | Server address of Docker registry. If not set then will default to Docker Hub |
| `username` | String | | Username used to log against the Docker registry |
| `password` | String | | Password or personal access token used to log against the Docker registry |
| `ecr` | String | `auto` | Specifies whether the given registry is ECR (`auto`, `true` or `false`) |
| `logout` | Bool | `true` | Log out from the Docker registry at the end of a job |

## Keep up-to-date with GitHub Dependabot
Expand Down
10 changes: 8 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ test('successful with username and password', async () => {
const password: string = 'groundcontrol';
process.env[`INPUT_PASSWORD`] = password;

const ecr: string = 'auto';
process.env['INPUT_ECR'] = ecr;

const logout: boolean = false;
process.env['INPUT_LOGOUT'] = String(logout);

await run();

expect(setRegistrySpy).toHaveBeenCalledWith('');
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
expect(dockerSpy).toHaveBeenCalledWith('', username, password);
expect(dockerSpy).toHaveBeenCalledWith('', username, password, ecr);
});

test('calls docker login', async () => {
Expand All @@ -62,12 +65,15 @@ test('calls docker login', async () => {
const registry: string = 'ghcr.io';
process.env[`INPUT_REGISTRY`] = registry;

const ecr: string = 'auto';
process.env['INPUT_ECR'] = ecr;

const logout: boolean = true;
process.env['INPUT_LOGOUT'] = String(logout);

await run();

expect(setRegistrySpy).toHaveBeenCalledWith(registry);
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
expect(dockerSpy).toHaveBeenCalledWith(registry, username, password);
expect(dockerSpy).toHaveBeenCalledWith(registry, username, password, ecr);
});
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ inputs:
password:
description: 'Password or personal access token used to log against the Docker registry'
required: false
ecr:
description: 'Specifies whether the given registry is ECR (auto, true or false)'
default: 'auto'
required: false
logout:
description: 'Log out from the Docker registry at the end of a job'
default: 'true'
Expand Down
13 changes: 7 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface Inputs {
registry: string;
username: string;
password: string;
ecr: string;
logout: boolean;
}

Expand All @@ -12,6 +13,7 @@ export function getInputs(): Inputs {
registry: core.getInput('registry'),
username: core.getInput('username'),
password: core.getInput('password'),
ecr: core.getInput('ecr'),
logout: core.getBooleanInput('logout')
};
}
4 changes: 2 additions & 2 deletions src/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as aws from './aws';
import * as core from '@actions/core';
import * as exec from '@actions/exec';

export async function login(registry: string, username: string, password: string): Promise<void> {
if (aws.isECR(registry)) {
export async function login(registry: string, username: string, password: string, ecr: string): Promise<void> {
if (/true/i.test(ecr) || (ecr == 'auto' && aws.isECR(registry))) {
await loginECR(registry, username, password);
} else {
await loginStandard(registry, username, password);
Expand Down
8 changes: 4 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import * as stateHelper from './state-helper';

export async function run(): Promise<void> {
try {
const {registry, username, password, logout} = context.getInputs();
stateHelper.setRegistry(registry);
stateHelper.setLogout(logout);
await docker.login(registry, username, password);
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);
} catch (error) {
core.setFailed(error.message);
}
Expand Down

0 comments on commit d9927c4

Please sign in to comment.