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

feat(core): add lint on diff and sync in default #155

Merged
merged 1 commit into from
Jul 20, 2024
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
6 changes: 5 additions & 1 deletion apps/cli/src/command/diff.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import YAML from 'yaml';
import { DifferV3 } from '../differ/differv3';
import { SignaleRenderer } from '../utils/listr';
import { LoadRemoteConfigurationTask } from './dump.command';
import { BackendCommand } from './helper';
import { BackendCommand, NoLintOption } from './helper';
import { LintTask } from './lint.command';
import { BackendOptions } from './typing';
import {
fillLabels,
Expand All @@ -22,6 +23,7 @@ import {

type DiffOptions = BackendOptions & {
file: Array<string>;
lint: boolean;
};

export interface TaskContext {
Expand Down Expand Up @@ -163,6 +165,7 @@ export const DiffCommand = new BackendCommand<DiffOptions>(
'The files you want to synchronize, can be set more than one.',
(filePath, files: Array<string> = []) => files.concat(filePath),
)
.addOption(NoLintOption)
.addExample('adc diff -f service-a.yaml -f service-b.yaml')
.handle(async (opts) => {
const backend = loadBackend(opts.backend, opts);
Expand All @@ -175,6 +178,7 @@ export const DiffCommand = new BackendCommand<DiffOptions>(
opts.includeResourceType,
opts.excludeResourceType,
),
opts.lint ? LintTask() : { task: () => undefined },
LoadRemoteConfigurationTask({
backend,
labelSelector: opts.labelSelector,
Expand Down
2 changes: 2 additions & 0 deletions apps/cli/src/command/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,5 @@ export class BackendCommand<OPTS extends object = object> extends BaseCommand {
);
}
}

export const NoLintOption = new Option('--no-lint', 'Disable lint check');
6 changes: 5 additions & 1 deletion apps/cli/src/command/sync.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
TaskContext,
} from './diff.command';
import { LoadRemoteConfigurationTask } from './dump.command';
import { BackendCommand } from './helper';
import { BackendCommand, NoLintOption } from './helper';
import { LintTask } from './lint.command';
import { BackendOptions } from './typing';
import { loadBackend } from './utils';

type SyncOption = BackendOptions & {
file: Array<string>;
lint: boolean;
};

export const SyncCommand = new BackendCommand<SyncOption>(
Expand All @@ -24,6 +26,7 @@ export const SyncCommand = new BackendCommand<SyncOption>(
'The files you want to synchronize, can be set more than one.',
(filePath, files: Array<string> = []) => files.concat(filePath),
)
.addOption(NoLintOption)
.addExample('adc sync -f service-a.yaml -f service-b.yaml')
.handle(async (opts) => {
const backend = loadBackend(opts.backend, opts);
Expand All @@ -36,6 +39,7 @@ export const SyncCommand = new BackendCommand<SyncOption>(
opts.includeResourceType,
opts.excludeResourceType,
),
opts.lint ? LintTask() : { task: () => undefined },
LoadRemoteConfigurationTask({
backend,
labelSelector: opts.labelSelector,
Expand Down
50 changes: 24 additions & 26 deletions apps/cli/src/linter/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,30 @@ const upstreamSchema = z
key: z.string().optional(),
checks: z
.object({
active: z
.object({
type: upstreamHealthCheckType.optional(),
timeout: z.number().default(1).optional(),
concurrency: z.number().default(10).optional(),
host: z.string(),
port: portSchema,
http_path: z.string().default('/').optional(),
https_verify_cert: z.boolean().default(true).optional(),
http_request_headers: z.array(z.string()).min(1).optional(),
healthy: z
.object({
interval: z.number().int().min(1).default(1),
})
.merge(upstreamHealthCheckPassiveHealthy)
.strict()
.optional(),
unhealthy: z
.object({
interval: z.number().int().min(1).default(1),
})
.merge(upstreamHealthCheckPassiveUnhealthy)
.strict()
.optional(),
})
.optional(),
active: z.object({
type: upstreamHealthCheckType.optional(),
timeout: z.number().default(1).optional(),
concurrency: z.number().default(10).optional(),
host: z.string(),
port: portSchema,
http_path: z.string().default('/').optional(),
https_verify_cert: z.boolean().default(true).optional(),
http_request_headers: z.array(z.string()).min(1).optional(),
healthy: z
.object({
interval: z.number().int().min(1).default(1),
})
.merge(upstreamHealthCheckPassiveHealthy)
.strict()
.optional(),
unhealthy: z
.object({
interval: z.number().int().min(1).default(1),
})
.merge(upstreamHealthCheckPassiveUnhealthy)
.strict()
.optional(),
}),
passive: z
.object({
type: upstreamHealthCheckType.optional(),
Expand Down
Loading