dev: switch to eslint
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>pull/170/head
parent
56f72fcef0
commit
0828e0e718
|
@ -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');
|
||||
|
||||
test('loginStandard calls exec', async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
const execSpy = jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
|
||||
return {
|
||||
|
@ -15,9 +16,9 @@ test('loginStandard calls exec', async () => {
|
|||
};
|
||||
});
|
||||
|
||||
const username: string = 'dbowie';
|
||||
const password: string = 'groundcontrol';
|
||||
const registry: string = 'https://ghcr.io';
|
||||
const username = 'dbowie';
|
||||
const password = 'groundcontrol';
|
||||
const registry = 'https://ghcr.io';
|
||||
|
||||
await loginStandard(registry, username, password);
|
||||
|
||||
|
@ -29,6 +30,7 @@ test('loginStandard calls exec', async () => {
|
|||
});
|
||||
|
||||
test('logout calls exec', async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
const execSpy = jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
|
||||
return {
|
||||
|
@ -38,7 +40,7 @@ test('logout calls exec', async () => {
|
|||
};
|
||||
});
|
||||
|
||||
const registry: string = 'https://ghcr.io';
|
||||
const registry = 'https://ghcr.io';
|
||||
|
||||
await logout(registry);
|
||||
|
||||
|
|
|
@ -8,8 +8,7 @@ import * as stateHelper from '../src/state-helper';
|
|||
import * as core from '@actions/core';
|
||||
|
||||
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
|
||||
const coreSpy = jest.spyOn(core, 'setFailed');
|
||||
|
||||
|
@ -18,21 +17,21 @@ test('errors without 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 setLogoutSpy = jest.spyOn(stateHelper, 'setLogout');
|
||||
const dockerSpy = jest.spyOn(docker, 'login').mockImplementation(jest.fn());
|
||||
|
||||
const username: string = 'dbowie';
|
||||
const username = 'dbowie';
|
||||
process.env[`INPUT_USERNAME`] = username;
|
||||
|
||||
const password: string = 'groundcontrol';
|
||||
const password = 'groundcontrol';
|
||||
process.env[`INPUT_PASSWORD`] = password;
|
||||
|
||||
const ecr: string = 'auto';
|
||||
const ecr = 'auto';
|
||||
process.env['INPUT_ECR'] = ecr;
|
||||
|
||||
const logout: boolean = false;
|
||||
const logout = false;
|
||||
process.env['INPUT_LOGOUT'] = String(logout);
|
||||
|
||||
await run();
|
||||
|
@ -43,25 +42,25 @@ test('successful with username and password', 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 setLogoutSpy = jest.spyOn(stateHelper, 'setLogout');
|
||||
const dockerSpy = jest.spyOn(docker, 'login');
|
||||
dockerSpy.mockImplementation(jest.fn());
|
||||
|
||||
const username: string = 'dbowie';
|
||||
const username = 'dbowie';
|
||||
process.env[`INPUT_USERNAME`] = username;
|
||||
|
||||
const password: string = 'groundcontrol';
|
||||
const password = 'groundcontrol';
|
||||
process.env[`INPUT_PASSWORD`] = password;
|
||||
|
||||
const registry: string = 'ghcr.io';
|
||||
const registry = 'ghcr.io';
|
||||
process.env[`INPUT_REGISTRY`] = registry;
|
||||
|
||||
const ecr: string = 'auto';
|
||||
const ecr = 'auto';
|
||||
process.env['INPUT_ECR'] = ecr;
|
||||
|
||||
const logout: boolean = true;
|
||||
const logout = true;
|
||||
process.env['INPUT_LOGOUT'] = String(logout);
|
||||
|
||||
await run();
|
||||
|
|
|
@ -57,10 +57,10 @@ RUN --mount=type=bind,target=.,rw \
|
|||
FROM scratch AS format-update
|
||||
COPY --from=format /out /
|
||||
|
||||
FROM deps AS format-validate
|
||||
FROM deps AS lint
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn run format-check
|
||||
yarn run lint
|
||||
|
||||
FROM docker:${DOCKER_VERSION} as docker
|
||||
FROM docker/buildx-bin:${BUILDX_VERSION} as buildx
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -7,7 +7,7 @@ group "pre-checkin" {
|
|||
}
|
||||
|
||||
group "validate" {
|
||||
targets = ["format-validate", "build-validate", "vendor-validate"]
|
||||
targets = ["lint", "build-validate", "vendor-validate"]
|
||||
}
|
||||
|
||||
target "build" {
|
||||
|
@ -28,9 +28,9 @@ target "format" {
|
|||
output = ["."]
|
||||
}
|
||||
|
||||
target "format-validate" {
|
||||
target "lint" {
|
||||
dockerfile = "dev.Dockerfile"
|
||||
target = "format-validate"
|
||||
target = "lint"
|
||||
output = ["type=cacheonly"]
|
||||
}
|
||||
|
||||
|
|
|
@ -6,5 +6,5 @@ module.exports = {
|
|||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest'
|
||||
},
|
||||
verbose: false
|
||||
verbose: true
|
||||
}
|
17
package.json
17
package.json
|
@ -3,11 +3,11 @@
|
|||
"description": "GitHub Action to login against a Docker registry",
|
||||
"main": "lib/main.js",
|
||||
"scripts": {
|
||||
"build": "tsc && ncc build",
|
||||
"format": "prettier --write '**/*.ts'",
|
||||
"format-check": "prettier --check '**/*.ts'",
|
||||
"build": "ncc build src/main.ts --source-map --minify --license licenses.txt",
|
||||
"lint": "eslint src/**/*.ts __tests__/**/*.ts",
|
||||
"format": "eslint --fix src/**/*.ts __tests__/**/*.ts",
|
||||
"test": "jest --coverage",
|
||||
"pre-checkin": "yarn run format && yarn run build"
|
||||
"all": "yarn run build && yarn run format && yarn test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -37,11 +37,18 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.26",
|
||||
"@typescript-eslint/eslint-plugin": "^5.14.0",
|
||||
"@typescript-eslint/parser": "^5.14.0",
|
||||
"@vercel/ncc": "^0.33.3",
|
||||
"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",
|
||||
"prettier": "^2.5.1",
|
||||
"prettier": "^2.3.1",
|
||||
"ts-jest": "^27.1.2",
|
||||
"ts-node": "^10.7.0",
|
||||
"typescript": "^4.4.4"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ export const getAccountIDs = (registry: string): string[] => {
|
|||
if (!matches) {
|
||||
return [];
|
||||
}
|
||||
let accountIDs: Array<string> = [matches[2]];
|
||||
const accountIDs: Array<string> = [matches[2]];
|
||||
if (process.env.AWS_ACCOUNT_IDS) {
|
||||
accountIDs.push(...process.env.AWS_ACCOUNT_IDS.split(','));
|
||||
}
|
||||
|
@ -57,14 +57,14 @@ export const getRegistriesData = async (registry: string, username?: string, pas
|
|||
authTokenRequest['registryIds'] = accountIDs;
|
||||
}
|
||||
|
||||
let httpProxyAgent: any = null;
|
||||
let httpProxyAgent;
|
||||
const httpProxy = process.env.http_proxy || process.env.HTTP_PROXY || '';
|
||||
if (httpProxy) {
|
||||
core.debug(`Using http proxy ${httpProxy}`);
|
||||
httpProxyAgent = new HttpProxyAgent(httpProxy);
|
||||
}
|
||||
|
||||
let httpsProxyAgent: any = null;
|
||||
let httpsProxyAgent;
|
||||
const httpsProxy = process.env.https_proxy || process.env.HTTPS_PROXY || '';
|
||||
if (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');
|
||||
}
|
||||
|
||||
let loginArgs: Array<string> = ['login', '--password-stdin'];
|
||||
const loginArgs: Array<string> = ['login', '--password-stdin'];
|
||||
loginArgs.push('--username', username);
|
||||
loginArgs.push(registry);
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ export async function run(): Promise<void> {
|
|||
stateHelper.setRegistry(input.registry);
|
||||
stateHelper.setLogout(input.logout);
|
||||
await docker.login(input.registry, input.username, input.password, input.ecr);
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"newLine": "lf",
|
||||
"outDir": "./lib",
|
||||
"rootDir": "./src",
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"esModuleInterop": true,
|
||||
"sourceMap": true
|
||||
"useUnknownInCatchVariables": false,
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"**/*.test.ts",
|
||||
"jest.config.ts"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue