Skip to content

Commit 4fd5d8e

Browse files
committed
Use core.getBooleanInput
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
1 parent e2346b6 commit 4fd5d8e

6 files changed

Lines changed: 34 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,27 @@ jobs:
2828
username: ${{ github.repository_owner }}
2929
password: ${{ secrets.GITHUB_TOKEN }}
3030

31+
logout:
32+
runs-on: ubuntu-latest
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
logout:
37+
- false
38+
- true
39+
steps:
40+
-
41+
name: Checkout
42+
uses: actions/checkout@v2
43+
-
44+
name: Login to GitHub Container Registry
45+
uses: ./
46+
with:
47+
registry: ghcr.io
48+
username: ${{ github.repository_owner }}
49+
password: ${{ secrets.GITHUB_TOKEN }}
50+
logout: ${{ matrix.logout }}
51+
3152
dind:
3253
runs-on: ubuntu-latest
3354
env:

__tests__/context.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {getInputs} from '../src/context';
55
test('with password and username getInputs does not throw error', async () => {
66
process.env['INPUT_USERNAME'] = 'dbowie';
77
process.env['INPUT_PASSWORD'] = 'groundcontrol';
8+
process.env['INPUT_LOGOUT'] = 'true';
89
expect(() => {
910
getInputs();
1011
}).not.toThrowError();

__tests__/main.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ test('errors without username and password', async () => {
1010
const platSpy = jest.spyOn(osm, 'platform');
1111
platSpy.mockImplementation(() => 'linux');
1212

13+
process.env['INPUT_LOGOUT'] = 'true'; // default value
14+
1315
const coreSpy: jest.SpyInstance = jest.spyOn(core, 'setFailed');
1416

1517
await run();
@@ -32,10 +34,13 @@ test('successful with username and password', async () => {
3234
const password: string = 'groundcontrol';
3335
process.env[`INPUT_PASSWORD`] = password;
3436

37+
const logout: boolean = false;
38+
process.env['INPUT_LOGOUT'] = String(logout);
39+
3540
await run();
3641

3742
expect(setRegistrySpy).toHaveBeenCalledWith('');
38-
expect(setLogoutSpy).toHaveBeenCalledWith('');
43+
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
3944
expect(dockerSpy).toHaveBeenCalledWith('', username, password);
4045
});
4146

@@ -57,8 +62,8 @@ test('calls docker login', async () => {
5762
const registry: string = 'ghcr.io';
5863
process.env[`INPUT_REGISTRY`] = registry;
5964

60-
const logout: string = 'true';
61-
process.env['INPUT_LOGOUT'] = logout;
65+
const logout: boolean = true;
66+
process.env['INPUT_LOGOUT'] = String(logout);
6267

6368
await run();
6469

dist/index.js

Lines changed: 1 addition & 1 deletion
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ export interface Inputs {
44
registry: string;
55
username: string;
66
password: string;
7-
logout: string;
7+
logout: boolean;
88
}
99

1010
export function getInputs(): Inputs {
1111
return {
1212
registry: core.getInput('registry'),
1313
username: core.getInput('username'),
1414
password: core.getInput('password'),
15-
logout: core.getInput('logout')
15+
logout: core.getBooleanInput('logout')
1616
};
1717
}

src/state-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function setRegistry(registry: string) {
88
core.saveState('registry', registry);
99
}
1010

11-
export function setLogout(logout: string) {
11+
export function setLogout(logout: boolean) {
1212
core.saveState('logout', logout);
1313
}
1414

0 commit comments

Comments
 (0)