Skip to content

Commit b9a4d91

Browse files
committed
ecr input to specify whether the given registry is ECR
Signed-off-by: CrazyMax <[email protected]>
1 parent b20b9f5 commit b9a4d91

File tree

8 files changed

+29
-15
lines changed

8 files changed

+29
-15
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: ci
33
on:
44
workflow_dispatch:
55
schedule:
6-
- cron: '0 10 * * *' # everyday at 10am
6+
- cron: '0 10 * * *'
77
push:
88
branches:
99
- 'master'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ Following inputs can be used as `step.with` keys
379379
| `registry` | String | | Server address of Docker registry. If not set then will default to Docker Hub |
380380
| `username` | String | | Username used to log against the Docker registry |
381381
| `password` | String | | Password or personal access token used to log against the Docker registry |
382+
| `ecr` | String | `auto` | Specifies whether the given registry is ECR (`auto`, `true` or `false`) |
382383
| `logout` | Bool | `true` | Log out from the Docker registry at the end of a job |
383384

384385
## Keep up-to-date with GitHub Dependabot

__tests__/main.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ test('successful with username and password', async () => {
3434
const password: string = 'groundcontrol';
3535
process.env[`INPUT_PASSWORD`] = password;
3636

37+
const ecr: string = 'auto';
38+
process.env['INPUT_ECR'] = ecr;
39+
3740
const logout: boolean = false;
3841
process.env['INPUT_LOGOUT'] = String(logout);
3942

4043
await run();
4144

4245
expect(setRegistrySpy).toHaveBeenCalledWith('');
4346
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
44-
expect(dockerSpy).toHaveBeenCalledWith('', username, password);
47+
expect(dockerSpy).toHaveBeenCalledWith('', username, password, ecr);
4548
});
4649

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

68+
const ecr: string = 'auto';
69+
process.env['INPUT_ECR'] = ecr;
70+
6571
const logout: boolean = true;
6672
process.env['INPUT_LOGOUT'] = String(logout);
6773

6874
await run();
6975

7076
expect(setRegistrySpy).toHaveBeenCalledWith(registry);
7177
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
72-
expect(dockerSpy).toHaveBeenCalledWith(registry, username, password);
78+
expect(dockerSpy).toHaveBeenCalledWith(registry, username, password, ecr);
7379
});

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ inputs:
1616
password:
1717
description: 'Password or personal access token used to log against the Docker registry'
1818
required: false
19+
ecr:
20+
description: 'Specifies whether the given registry is ECR (auto, true or false)'
21+
default: 'auto'
22+
required: false
1923
logout:
2024
description: 'Log out from the Docker registry at the end of a job'
2125
default: 'true'

dist/index.js

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/context.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export interface Inputs {
44
registry: string;
55
username: string;
66
password: string;
7+
ecr: string;
78
logout: boolean;
89
}
910

@@ -12,6 +13,7 @@ export function getInputs(): Inputs {
1213
registry: core.getInput('registry'),
1314
username: core.getInput('username'),
1415
password: core.getInput('password'),
16+
ecr: core.getInput('ecr'),
1517
logout: core.getBooleanInput('logout')
1618
};
1719
}

src/docker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import * as aws from './aws';
22
import * as core from '@actions/core';
33
import * as exec from '@actions/exec';
44

5-
export async function login(registry: string, username: string, password: string): Promise<void> {
6-
if (aws.isECR(registry)) {
5+
export async function login(registry: string, username: string, password: string, ecr: string): Promise<void> {
6+
if (/true/i.test(ecr) || (ecr == 'auto' && aws.isECR(registry))) {
77
await loginECR(registry, username, password);
88
} else {
99
await loginStandard(registry, username, password);

src/main.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import * as stateHelper from './state-helper';
55

66
export async function run(): Promise<void> {
77
try {
8-
const {registry, username, password, logout} = context.getInputs();
9-
stateHelper.setRegistry(registry);
10-
stateHelper.setLogout(logout);
11-
await docker.login(registry, username, password);
8+
const input: context.Inputs = context.getInputs();
9+
stateHelper.setRegistry(input.registry);
10+
stateHelper.setLogout(input.logout);
11+
await docker.login(input.registry, input.username, input.password, input.ecr);
1212
} catch (error) {
1313
core.setFailed(error.message);
1414
}

0 commit comments

Comments
 (0)