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

Use core.getBooleanInput #76

Merged
merged 1 commit into from
Jun 22, 2021
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
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

logout:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
logout:
- false
- true
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Login to GitHub Container Registry
uses: ./
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
logout: ${{ matrix.logout }}

dind:
runs-on: ubuntu-latest
env:
Expand Down
1 change: 1 addition & 0 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {getInputs} from '../src/context';
test('with password and username getInputs does not throw error', async () => {
process.env['INPUT_USERNAME'] = 'dbowie';
process.env['INPUT_PASSWORD'] = 'groundcontrol';
process.env['INPUT_LOGOUT'] = 'true';
expect(() => {
getInputs();
}).not.toThrowError();
Expand Down
11 changes: 8 additions & 3 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ test('errors without username and password', async () => {
const platSpy = jest.spyOn(osm, 'platform');
platSpy.mockImplementation(() => 'linux');

process.env['INPUT_LOGOUT'] = 'true'; // default value

const coreSpy: jest.SpyInstance = jest.spyOn(core, 'setFailed');

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

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

await run();

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

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

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

await run();

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

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

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

export function getInputs(): Inputs {
return {
registry: core.getInput('registry'),
username: core.getInput('username'),
password: core.getInput('password'),
logout: core.getInput('logout')
logout: core.getBooleanInput('logout')
};
}
2 changes: 1 addition & 1 deletion src/state-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function setRegistry(registry: string) {
core.saveState('registry', registry);
}

export function setLogout(logout: string) {
export function setLogout(logout: boolean) {
core.saveState('logout', logout);
}

Expand Down