dev: switch to eslint

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
pull/170/head
CrazyMax 2 years ago
parent 56f72fcef0
commit 0828e0e718
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7

@ -0,0 +1,23 @@
{
"env": {
"node": true,
"es2021": true,
"jest/globals": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"jest",
"prettier"
]
}

@ -6,6 +6,7 @@ import * as exec from '@actions/exec';
process.env['RUNNER_TEMP'] = path.join(__dirname, 'runner'); process.env['RUNNER_TEMP'] = path.join(__dirname, 'runner');
test('loginStandard calls exec', async () => { test('loginStandard calls exec', async () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
const execSpy = jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => { const execSpy = jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
return { return {
@ -15,9 +16,9 @@ test('loginStandard calls exec', async () => {
}; };
}); });
const username: string = 'dbowie'; const username = 'dbowie';
const password: string = 'groundcontrol'; const password = 'groundcontrol';
const registry: string = 'https://ghcr.io'; const registry = 'https://ghcr.io';
await loginStandard(registry, username, password); await loginStandard(registry, username, password);
@ -29,6 +30,7 @@ test('loginStandard calls exec', async () => {
}); });
test('logout calls exec', async () => { test('logout calls exec', async () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
const execSpy = jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => { const execSpy = jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
return { return {
@ -38,7 +40,7 @@ test('logout calls exec', async () => {
}; };
}); });
const registry: string = 'https://ghcr.io'; const registry = 'https://ghcr.io';
await logout(registry); await logout(registry);

@ -8,8 +8,7 @@ import * as stateHelper from '../src/state-helper';
import * as core from '@actions/core'; import * as core from '@actions/core';
test('errors without username and password', async () => { test('errors without username and password', async () => {
const platSpy = jest.spyOn(osm, 'platform').mockImplementation(() => 'linux'); jest.spyOn(osm, 'platform').mockImplementation(() => 'linux');
process.env['INPUT_LOGOUT'] = 'true'; // default value process.env['INPUT_LOGOUT'] = 'true'; // default value
const coreSpy = jest.spyOn(core, 'setFailed'); const coreSpy = jest.spyOn(core, 'setFailed');
@ -18,21 +17,21 @@ test('errors without username and password', async () => {
}); });
test('successful with username and password', async () => { test('successful with username and password', async () => {
const platSpy = jest.spyOn(osm, 'platform').mockImplementation(() => 'linux'); jest.spyOn(osm, 'platform').mockImplementation(() => 'linux');
const setRegistrySpy = jest.spyOn(stateHelper, 'setRegistry'); const setRegistrySpy = jest.spyOn(stateHelper, 'setRegistry');
const setLogoutSpy = jest.spyOn(stateHelper, 'setLogout'); const setLogoutSpy = jest.spyOn(stateHelper, 'setLogout');
const dockerSpy = jest.spyOn(docker, 'login').mockImplementation(jest.fn()); const dockerSpy = jest.spyOn(docker, 'login').mockImplementation(jest.fn());
const username: string = 'dbowie'; const username = 'dbowie';
process.env[`INPUT_USERNAME`] = username; process.env[`INPUT_USERNAME`] = username;
const password: string = 'groundcontrol'; const password = 'groundcontrol';
process.env[`INPUT_PASSWORD`] = password; process.env[`INPUT_PASSWORD`] = password;
const ecr: string = 'auto'; const ecr = 'auto';
process.env['INPUT_ECR'] = ecr; process.env['INPUT_ECR'] = ecr;
const logout: boolean = false; const logout = false;
process.env['INPUT_LOGOUT'] = String(logout); process.env['INPUT_LOGOUT'] = String(logout);
await run(); await run();
@ -43,25 +42,25 @@ test('successful with username and password', async () => {
}); });
test('calls docker login', async () => { test('calls docker login', async () => {
const platSpy = jest.spyOn(osm, 'platform').mockImplementation(() => 'linux'); jest.spyOn(osm, 'platform').mockImplementation(() => 'linux');
const setRegistrySpy = jest.spyOn(stateHelper, 'setRegistry'); const setRegistrySpy = jest.spyOn(stateHelper, 'setRegistry');
const setLogoutSpy = jest.spyOn(stateHelper, 'setLogout'); const setLogoutSpy = jest.spyOn(stateHelper, 'setLogout');
const dockerSpy = jest.spyOn(docker, 'login'); const dockerSpy = jest.spyOn(docker, 'login');
dockerSpy.mockImplementation(jest.fn()); dockerSpy.mockImplementation(jest.fn());
const username: string = 'dbowie'; const username = 'dbowie';
process.env[`INPUT_USERNAME`] = username; process.env[`INPUT_USERNAME`] = username;
const password: string = 'groundcontrol'; const password = 'groundcontrol';
process.env[`INPUT_PASSWORD`] = password; process.env[`INPUT_PASSWORD`] = password;
const registry: string = 'ghcr.io'; const registry = 'ghcr.io';
process.env[`INPUT_REGISTRY`] = registry; process.env[`INPUT_REGISTRY`] = registry;
const ecr: string = 'auto'; const ecr = 'auto';
process.env['INPUT_ECR'] = ecr; process.env['INPUT_ECR'] = ecr;
const logout: boolean = true; const logout = true;
process.env['INPUT_LOGOUT'] = String(logout); process.env['INPUT_LOGOUT'] = String(logout);
await run(); await run();

@ -57,10 +57,10 @@ RUN --mount=type=bind,target=.,rw \
FROM scratch AS format-update FROM scratch AS format-update
COPY --from=format /out / COPY --from=format /out /
FROM deps AS format-validate FROM deps AS lint
RUN --mount=type=bind,target=.,rw \ RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/src/node_modules \ --mount=type=cache,target=/src/node_modules \
yarn run format-check yarn run lint
FROM docker:${DOCKER_VERSION} as docker FROM docker:${DOCKER_VERSION} as docker
FROM docker/buildx-bin:${BUILDX_VERSION} as buildx FROM docker/buildx-bin:${BUILDX_VERSION} as buildx

32412
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

1
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

9467
dist/licenses.txt generated vendored

File diff suppressed because it is too large Load Diff

1
dist/sourcemap-register.js generated vendored

File diff suppressed because one or more lines are too long

@ -7,7 +7,7 @@ group "pre-checkin" {
} }
group "validate" { group "validate" {
targets = ["format-validate", "build-validate", "vendor-validate"] targets = ["lint", "build-validate", "vendor-validate"]
} }
target "build" { target "build" {
@ -28,9 +28,9 @@ target "format" {
output = ["."] output = ["."]
} }
target "format-validate" { target "lint" {
dockerfile = "dev.Dockerfile" dockerfile = "dev.Dockerfile"
target = "format-validate" target = "lint"
output = ["type=cacheonly"] output = ["type=cacheonly"]
} }

@ -6,5 +6,5 @@ module.exports = {
transform: { transform: {
'^.+\\.ts$': 'ts-jest' '^.+\\.ts$': 'ts-jest'
}, },
verbose: false verbose: true
} }

@ -3,11 +3,11 @@
"description": "GitHub Action to login against a Docker registry", "description": "GitHub Action to login against a Docker registry",
"main": "lib/main.js", "main": "lib/main.js",
"scripts": { "scripts": {
"build": "tsc && ncc build", "build": "ncc build src/main.ts --source-map --minify --license licenses.txt",
"format": "prettier --write '**/*.ts'", "lint": "eslint src/**/*.ts __tests__/**/*.ts",
"format-check": "prettier --check '**/*.ts'", "format": "eslint --fix src/**/*.ts __tests__/**/*.ts",
"test": "jest --coverage", "test": "jest --coverage",
"pre-checkin": "yarn run format && yarn run build" "all": "yarn run build && yarn run format && yarn test"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -37,11 +37,18 @@
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^16.11.26", "@types/node": "^16.11.26",
"@typescript-eslint/eslint-plugin": "^5.14.0",
"@typescript-eslint/parser": "^5.14.0",
"@vercel/ncc": "^0.33.3", "@vercel/ncc": "^0.33.3",
"dotenv": "^16.0.0", "dotenv": "^16.0.0",
"eslint": "^8.11.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jest": "^26.1.1",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.2.5", "jest": "^27.2.5",
"prettier": "^2.5.1", "prettier": "^2.3.1",
"ts-jest": "^27.1.2", "ts-jest": "^27.1.2",
"ts-node": "^10.7.0",
"typescript": "^4.4.4" "typescript": "^4.4.4"
} }
} }

@ -34,7 +34,7 @@ export const getAccountIDs = (registry: string): string[] => {
if (!matches) { if (!matches) {
return []; return [];
} }
let accountIDs: Array<string> = [matches[2]]; const accountIDs: Array<string> = [matches[2]];
if (process.env.AWS_ACCOUNT_IDS) { if (process.env.AWS_ACCOUNT_IDS) {
accountIDs.push(...process.env.AWS_ACCOUNT_IDS.split(',')); accountIDs.push(...process.env.AWS_ACCOUNT_IDS.split(','));
} }
@ -57,14 +57,14 @@ export const getRegistriesData = async (registry: string, username?: string, pas
authTokenRequest['registryIds'] = accountIDs; authTokenRequest['registryIds'] = accountIDs;
} }
let httpProxyAgent: any = null; let httpProxyAgent;
const httpProxy = process.env.http_proxy || process.env.HTTP_PROXY || ''; const httpProxy = process.env.http_proxy || process.env.HTTP_PROXY || '';
if (httpProxy) { if (httpProxy) {
core.debug(`Using http proxy ${httpProxy}`); core.debug(`Using http proxy ${httpProxy}`);
httpProxyAgent = new HttpProxyAgent(httpProxy); httpProxyAgent = new HttpProxyAgent(httpProxy);
} }
let httpsProxyAgent: any = null; let httpsProxyAgent;
const httpsProxy = process.env.https_proxy || process.env.HTTPS_PROXY || ''; const httpsProxy = process.env.https_proxy || process.env.HTTPS_PROXY || '';
if (httpsProxy) { if (httpsProxy) {
core.debug(`Using https proxy ${httpsProxy}`); core.debug(`Using https proxy ${httpsProxy}`);

@ -27,7 +27,7 @@ export async function loginStandard(registry: string, username: string, password
throw new Error('Username and password required'); throw new Error('Username and password required');
} }
let loginArgs: Array<string> = ['login', '--password-stdin']; const loginArgs: Array<string> = ['login', '--password-stdin'];
loginArgs.push('--username', username); loginArgs.push('--username', username);
loginArgs.push(registry); loginArgs.push(registry);

@ -9,7 +9,7 @@ export async function run(): Promise<void> {
stateHelper.setRegistry(input.registry); stateHelper.setRegistry(input.registry);
stateHelper.setLogout(input.logout); stateHelper.setLogout(input.logout);
await docker.login(input.registry, input.username, input.password, input.ecr); await docker.login(input.registry, input.username, input.password, input.ecr);
} catch (error: any) { } catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
} }
} }

@ -1,14 +1,19 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "esnext", "target": "es6",
"module": "commonjs", "module": "commonjs",
"newLine": "lf", "newLine": "lf",
"outDir": "./lib", "outDir": "./lib",
"rootDir": "./src", "rootDir": "./src",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true, "strict": true,
"noImplicitAny": false, "noImplicitAny": false,
"esModuleInterop": true, "useUnknownInCatchVariables": false,
"sourceMap": true
}, },
"exclude": ["node_modules", "**/*.test.ts"] "exclude": [
"node_modules",
"**/*.test.ts",
"jest.config.ts"
]
} }

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save