Skip to content

Commit

Permalink
feat!: add optional properties to parameterized jobs (#139)
Browse files Browse the repository at this point in the history
* feat: add optional properties to parameterized jobs
* feat: output parallelism and update docs
  • Loading branch information
Jaryt authored Sep 13, 2022
1 parent 33e9329 commit f53d462
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
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,
) {
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

0 comments on commit f53d462

Please sign in to comment.