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!: add optional properties to parameterized jobs #139

Merged
merged 2 commits into from
Sep 13, 2022
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
9 changes: 7 additions & 2 deletions src/lib/Components/Job/exports/ParameterizedJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { Command } from '../../Commands/exports/Command';
import { CustomParametersList } from '../../Parameters';
import { Parameterized } from '../../Parameters/exports/Parameterized';
import { JobParameterLiteral } from '../../Parameters/types/CustomParameterLiterals.types';
import { AnyExecutor, ParameterizedJobContents } from '../types/Job.types';
import {
AnyExecutor,
JobOptionalProperties,
ParameterizedJobContents,
} from '../types/Job.types';

/**
* Parameterized jobs are a type of Job which defines the parameters it can accept.
Expand All @@ -24,8 +28,9 @@ class ParameterizedJob
executor: AnyExecutor,
parameters?: CustomParametersList<JobParameterLiteral>,
steps?: Command[],
properties?: JobOptionalProperties,
) {
super(name, executor, steps);
super(name, executor, steps, properties);
this.parameters = parameters || new CustomParametersList();
}

Expand Down
18 changes: 12 additions & 6 deletions src/lib/Components/Job/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import { GenerableType } from '../../Config/exports/Mapping';
import { Command } from '../Commands/exports/Command';
import { Executable } from '../Executors/types/ExecutorParameters.types';
import { Generable } from '../index';
import { EnvironmentParameter, StringParameter } from '../Parameters/types';
import {
EnvironmentParameter,
IntegerParameter,
StringParameter,
} from '../Parameters/types';
import {
AnyExecutor,
JobContentsShape,
JobExtraProperties,
JobOptionalProperties,
JobsShape,
} from './types/Job.types';

Expand All @@ -27,9 +31,9 @@ export class Job implements Generable, Executable {
*/
steps: Command[];
/**
* Number of parallel instances of this job to run (default: 1)
* Number of parallel instances of this job to run (defaults to 1 if undefined)
*/
parallelism;
parallelism: IntegerParameter | undefined;

// Execution environment properties

Expand All @@ -42,21 +46,22 @@ export class Job implements Generable, Executable {
* @param name - Name your job with a unique identifier
* @param executor - The reusable executor to use for this job. The Executor must have already been instantiated and added to the config.
* @param steps - A list of Commands to execute within the job in the order which they were added.
* @param properties - Additional optional properties to further configure the job.
* @see {@link https://circleci.com/docs/2.0/configuration-reference/?section=configuration#jobs}
*/
constructor(
name: string,
executor: AnyExecutor,
steps: Command[] = [],
properties?: JobExtraProperties,
properties?: JobOptionalProperties,
Jaryt marked this conversation as resolved.
Show resolved Hide resolved
) {
this.name = name;
this.executor = executor;
this.steps = steps;
this.environment = properties?.environment;
this.shell = properties?.shell;
this.working_directory = properties?.working_directory;
this.parallelism = properties?.parallelism || 1;
this.parallelism = properties?.parallelism;
}

/**
Expand All @@ -75,6 +80,7 @@ export class Job implements Generable, Executable {
environment: this.environment,
shell: this.shell,
working_directory: this.working_directory,
parallelism: this.parallelism,
};
}
/**
Expand Down
12 changes: 5 additions & 7 deletions src/lib/Components/Job/types/Job.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import {
} from '../../Parameters/types';
import { JobParameterLiteral } from '../../Parameters/types/CustomParameterLiterals.types';

export type JobStepsShape = {
steps: unknown[]; // CommandSchemas for any command.
};

export type JobContentsShape = JobStepsShape &
AnyExecutorShape &
export type JobContentsShape = {
steps: unknown[];
parallelism?: number;
} & AnyExecutorShape &
JobEnvironmentShape;

export type JobsShape = {
Expand All @@ -40,7 +38,7 @@ export type JobDependencies = {
parametersList?: CustomParametersList<JobParameterLiteral>;
};

export type JobExtraProperties = {
export type JobOptionalProperties = {
parallelism?: number;
} & ExecutableProperties;

Expand Down