Compare commits

..

8 Commits

Author SHA1 Message Date
CrazyMax
18e358fee3
Merge 859a0ca3d3 into a5609cb39f 2023-09-07 12:58:59 +00:00
CrazyMax
859a0ca3d3
chore: node 20 as default runtime
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-09-07 14:58:51 +02:00
CrazyMax
4580814a5d
chore: update generated content
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-09-07 14:58:50 +02:00
CrazyMax
6bd04e769a
test: fix tests after toolkit update
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-09-07 14:58:50 +02:00
CrazyMax
a0ff215914
vendor: bump @docker/actions-toolkit from 0.7.1 to 0.12.0
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-09-07 14:58:50 +02:00
CrazyMax
699c7e9616
dev: remove unneeded binaries
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-09-07 14:58:50 +02:00
CrazyMax
4b8e182de5
chore: update dev dependencies
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-09-07 14:58:50 +02:00
CrazyMax
f71e6ddc95
chore: update to node 20
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-09-07 14:58:50 +02:00
4 changed files with 77 additions and 13 deletions

View File

@ -1,3 +0,0 @@
/dist/**
/coverage/**
/node_modules/**

65
__tests__/main.test.ts Normal file
View File

@ -0,0 +1,65 @@
import {expect, jest, test} from '@jest/globals';
import osm = require('os');
import {main} from '../src/main';
import * as docker from '../src/docker';
import * as stateHelper from '../src/state-helper';
test('errors without username and password', async () => {
jest.spyOn(osm, 'platform').mockImplementation(() => 'linux');
process.env['INPUT_LOGOUT'] = 'true'; // default value
await expect(main()).rejects.toThrow(new Error('Username and password required'));
});
test('successful with username and password', async () => {
jest.spyOn(osm, 'platform').mockImplementation(() => 'linux');
const setRegistrySpy = jest.spyOn(stateHelper, 'setRegistry');
const setLogoutSpy = jest.spyOn(stateHelper, 'setLogout');
const dockerSpy = jest.spyOn(docker, 'login').mockImplementation(() => Promise.resolve());
const username = 'dbowie';
process.env[`INPUT_USERNAME`] = username;
const password = 'groundcontrol';
process.env[`INPUT_PASSWORD`] = password;
const ecr = 'auto';
process.env['INPUT_ECR'] = ecr;
const logout = false;
process.env['INPUT_LOGOUT'] = String(logout);
await main();
expect(setRegistrySpy).toHaveBeenCalledWith('');
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
expect(dockerSpy).toHaveBeenCalledWith('', username, password, ecr);
});
test('calls docker login', async () => {
jest.spyOn(osm, 'platform').mockImplementation(() => 'linux');
const setRegistrySpy = jest.spyOn(stateHelper, 'setRegistry');
const setLogoutSpy = jest.spyOn(stateHelper, 'setLogout');
const dockerSpy = jest.spyOn(docker, 'login').mockImplementation(() => Promise.resolve());
const username = 'dbowie';
process.env[`INPUT_USERNAME`] = username;
const password = 'groundcontrol';
process.env[`INPUT_PASSWORD`] = password;
const registry = 'ghcr.io';
process.env[`INPUT_REGISTRY`] = registry;
const ecr = 'auto';
process.env['INPUT_ECR'] = ecr;
const logout = true;
process.env['INPUT_LOGOUT'] = String(logout);
await main();
expect(setRegistrySpy).toHaveBeenCalledWith(registry);
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
expect(dockerSpy).toHaveBeenCalledWith(registry, username, password, ecr);
});

View File

@ -65,7 +65,7 @@ ENV RUNNER_TEMP=/tmp/github_runner
ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/src/node_modules \
yarn run test --coverage --coverageDirectory=/tmp/coverage
yarn run test --coverageDirectory=/tmp/coverage
FROM scratch AS test-coverage
COPY --from=test /tmp/coverage /

View File

@ -4,13 +4,9 @@
"main": "lib/main.js",
"scripts": {
"build": "ncc build src/main.ts --source-map --minify --license licenses.txt",
"lint": "yarn run prettier && yarn run eslint",
"format": "yarn run prettier:fix && yarn run eslint:fix",
"eslint": "eslint --max-warnings=0 .",
"eslint:fix": "eslint --fix .",
"prettier": "prettier --check \"./**/*.ts\"",
"prettier:fix": "prettier --write \"./**/*.ts\"",
"test": "jest",
"lint": "eslint src/**/*.ts __tests__/**/*.ts",
"format": "eslint --fix src/**/*.ts __tests__/**/*.ts",
"test": "jest --coverage",
"all": "yarn run build && yarn run format && yarn test"
},
"repository": {
@ -22,8 +18,14 @@
"docker",
"login"
],
"author": "Docker Inc.",
"license": "Apache-2.0",
"author": "Docker",
"contributors": [
{
"name": "CrazyMax",
"url": "https://crazymax.dev"
}
],
"license": "MIT",
"dependencies": {
"@actions/core": "^1.10.0",
"@aws-sdk/client-ecr": "^3.398.0",