Skip to content

Commit

Permalink
Merge pull request #186 from tSte/feature/add-ip-ranges
Browse files Browse the repository at this point in the history
feat: Add circleci_ip_ranges
  • Loading branch information
bear authored Feb 2, 2024
2 parents ad4db8c + 5667dd8 commit 290baa5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib/Components/Job/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Command } from '../Commands/exports/Command';
import { Executable } from '../Executors/types/ExecutorParameters.types';
import { Generable } from '../index';
import {
BooleanParameter,
EnvironmentParameter,
IntegerParameter,
StringParameter,
Expand Down Expand Up @@ -34,6 +35,10 @@ export class Job implements Generable, Executable {
* Number of parallel instances of this job to run (defaults to 1 if undefined)
*/
parallelism: IntegerParameter | undefined;
/**
* Whether to use CircleCI IP Ranges for the job (defaults to false if undefined)
*/
circleci_ip_ranges: BooleanParameter | undefined;

// Execution environment properties

Expand Down Expand Up @@ -62,6 +67,7 @@ export class Job implements Generable, Executable {
this.shell = properties?.shell;
this.working_directory = properties?.working_directory;
this.parallelism = properties?.parallelism;
this.circleci_ip_ranges = properties?.circleci_ip_ranges;
}

/**
Expand All @@ -81,6 +87,7 @@ export class Job implements Generable, Executable {
shell: this.shell,
working_directory: this.working_directory,
parallelism: this.parallelism,
circleci_ip_ranges: this.circleci_ip_ranges,
};
}
/**
Expand Down
2 changes: 2 additions & 0 deletions src/lib/Components/Job/types/Job.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { JobParameterLiteral } from '../../Parameters/types/CustomParameterLiter
export type JobContentsShape = {
steps: unknown[];
parallelism?: number;
circleci_ip_ranges?: boolean;
} & AnyExecutorShape &
JobEnvironmentShape;

Expand All @@ -40,6 +41,7 @@ export type JobDependencies = {

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

export type UnknownJobShape = {
Expand Down
29 changes: 29 additions & 0 deletions tests/Job.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,35 @@ describe('Instantiate Docker Job', () => {
});
});

describe('Instantiate Docker Job with custom properties', () => {
const docker = new CircleCI.executors.DockerExecutor('cimg/node:lts');
const helloWorld = new CircleCI.commands.Run({
command: 'echo hello world',
});
const jobName = 'my-job';
const job = new CircleCI.Job(jobName, docker, [helloWorld], {
parallelism: 3,
circleci_ip_ranges: true,
});
const jobContents = {
docker: [{ image: 'cimg/node:lts' }],
resource_class: 'medium',
parallelism: 3,
circleci_ip_ranges: true,
steps: [{ run: 'echo hello world' }],
};

it('Should match the expected output', () => {
expect(job.generate(true)).toEqual({ [jobName]: jobContents });
});

it('Add job to config and validate', () => {
const myConfig = new CircleCI.Config();
myConfig.addJob(job);
expect(myConfig.jobs.length).toBeGreaterThan(0);
});
});

describe('Instantiate Parameterized Docker Job With Custom Parameters', () => {
const docker = new CircleCI.executors.DockerExecutor('cimg/node:lts');
const helloWorld = new CircleCI.commands.Run({
Expand Down

0 comments on commit 290baa5

Please sign in to comment.