mirror of
https://gitea.com/docker/login-action.git
synced 2024-11-26 03:19:37 +01:00
Merge pull request #76 from crazy-max/bool-input
Use `core.getBooleanInput`
This commit is contained in:
commit
4608add020
6 changed files with 34 additions and 7 deletions
21
.github/workflows/ci.yml
vendored
21
.github/workflows/ci.yml
vendored
|
@ -28,6 +28,27 @@ jobs:
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
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:
|
dind:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
|
|
|
@ -5,6 +5,7 @@ import {getInputs} from '../src/context';
|
||||||
test('with password and username getInputs does not throw error', async () => {
|
test('with password and username getInputs does not throw error', async () => {
|
||||||
process.env['INPUT_USERNAME'] = 'dbowie';
|
process.env['INPUT_USERNAME'] = 'dbowie';
|
||||||
process.env['INPUT_PASSWORD'] = 'groundcontrol';
|
process.env['INPUT_PASSWORD'] = 'groundcontrol';
|
||||||
|
process.env['INPUT_LOGOUT'] = 'true';
|
||||||
expect(() => {
|
expect(() => {
|
||||||
getInputs();
|
getInputs();
|
||||||
}).not.toThrowError();
|
}).not.toThrowError();
|
||||||
|
|
|
@ -10,6 +10,8 @@ test('errors without username and password', async () => {
|
||||||
const platSpy = jest.spyOn(osm, 'platform');
|
const platSpy = jest.spyOn(osm, 'platform');
|
||||||
platSpy.mockImplementation(() => 'linux');
|
platSpy.mockImplementation(() => 'linux');
|
||||||
|
|
||||||
|
process.env['INPUT_LOGOUT'] = 'true'; // default value
|
||||||
|
|
||||||
const coreSpy: jest.SpyInstance = jest.spyOn(core, 'setFailed');
|
const coreSpy: jest.SpyInstance = jest.spyOn(core, 'setFailed');
|
||||||
|
|
||||||
await run();
|
await run();
|
||||||
|
@ -32,10 +34,13 @@ test('successful with username and password', async () => {
|
||||||
const password: string = 'groundcontrol';
|
const password: string = 'groundcontrol';
|
||||||
process.env[`INPUT_PASSWORD`] = password;
|
process.env[`INPUT_PASSWORD`] = password;
|
||||||
|
|
||||||
|
const logout: boolean = false;
|
||||||
|
process.env['INPUT_LOGOUT'] = String(logout);
|
||||||
|
|
||||||
await run();
|
await run();
|
||||||
|
|
||||||
expect(setRegistrySpy).toHaveBeenCalledWith('');
|
expect(setRegistrySpy).toHaveBeenCalledWith('');
|
||||||
expect(setLogoutSpy).toHaveBeenCalledWith('');
|
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
|
||||||
expect(dockerSpy).toHaveBeenCalledWith('', username, password);
|
expect(dockerSpy).toHaveBeenCalledWith('', username, password);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -57,8 +62,8 @@ test('calls docker login', async () => {
|
||||||
const registry: string = 'ghcr.io';
|
const registry: string = 'ghcr.io';
|
||||||
process.env[`INPUT_REGISTRY`] = registry;
|
process.env[`INPUT_REGISTRY`] = registry;
|
||||||
|
|
||||||
const logout: string = 'true';
|
const logout: boolean = true;
|
||||||
process.env['INPUT_LOGOUT'] = logout;
|
process.env['INPUT_LOGOUT'] = String(logout);
|
||||||
|
|
||||||
await run();
|
await run();
|
||||||
|
|
||||||
|
|
2
dist/index.js
generated
vendored
2
dist/index.js
generated
vendored
|
@ -4737,7 +4737,7 @@ function getInputs() {
|
||||||
registry: core.getInput('registry'),
|
registry: core.getInput('registry'),
|
||||||
username: core.getInput('username'),
|
username: core.getInput('username'),
|
||||||
password: core.getInput('password'),
|
password: core.getInput('password'),
|
||||||
logout: core.getInput('logout')
|
logout: core.getBooleanInput('logout')
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
exports.getInputs = getInputs;
|
exports.getInputs = getInputs;
|
||||||
|
|
|
@ -4,7 +4,7 @@ export interface Inputs {
|
||||||
registry: string;
|
registry: string;
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
logout: string;
|
logout: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getInputs(): Inputs {
|
export function getInputs(): Inputs {
|
||||||
|
@ -12,6 +12,6 @@ export function getInputs(): Inputs {
|
||||||
registry: core.getInput('registry'),
|
registry: core.getInput('registry'),
|
||||||
username: core.getInput('username'),
|
username: core.getInput('username'),
|
||||||
password: core.getInput('password'),
|
password: core.getInput('password'),
|
||||||
logout: core.getInput('logout')
|
logout: core.getBooleanInput('logout')
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ export function setRegistry(registry: string) {
|
||||||
core.saveState('registry', registry);
|
core.saveState('registry', registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setLogout(logout: string) {
|
export function setLogout(logout: boolean) {
|
||||||
core.saveState('logout', logout);
|
core.saveState('logout', logout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue