Skip to content

Commit 290baa5

Browse files
authored
Merge pull request #186 from tSte/feature/add-ip-ranges
feat: Add circleci_ip_ranges
2 parents ad4db8c + 5667dd8 commit 290baa5

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

Diff for: src/lib/Components/Job/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Command } from '../Commands/exports/Command';
33
import { Executable } from '../Executors/types/ExecutorParameters.types';
44
import { Generable } from '../index';
55
import {
6+
BooleanParameter,
67
EnvironmentParameter,
78
IntegerParameter,
89
StringParameter,
@@ -34,6 +35,10 @@ export class Job implements Generable, Executable {
3435
* Number of parallel instances of this job to run (defaults to 1 if undefined)
3536
*/
3637
parallelism: IntegerParameter | undefined;
38+
/**
39+
* Whether to use CircleCI IP Ranges for the job (defaults to false if undefined)
40+
*/
41+
circleci_ip_ranges: BooleanParameter | undefined;
3742

3843
// Execution environment properties
3944

@@ -62,6 +67,7 @@ export class Job implements Generable, Executable {
6267
this.shell = properties?.shell;
6368
this.working_directory = properties?.working_directory;
6469
this.parallelism = properties?.parallelism;
70+
this.circleci_ip_ranges = properties?.circleci_ip_ranges;
6571
}
6672

6773
/**
@@ -81,6 +87,7 @@ export class Job implements Generable, Executable {
8187
shell: this.shell,
8288
working_directory: this.working_directory,
8389
parallelism: this.parallelism,
90+
circleci_ip_ranges: this.circleci_ip_ranges,
8491
};
8592
}
8693
/**

Diff for: src/lib/Components/Job/types/Job.types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { JobParameterLiteral } from '../../Parameters/types/CustomParameterLiter
1515
export type JobContentsShape = {
1616
steps: unknown[];
1717
parallelism?: number;
18+
circleci_ip_ranges?: boolean;
1819
} & AnyExecutorShape &
1920
JobEnvironmentShape;
2021

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

4142
export type JobOptionalProperties = {
4243
parallelism?: number;
44+
circleci_ip_ranges?: boolean;
4345
} & ExecutableProperties;
4446

4547
export type UnknownJobShape = {

Diff for: tests/Job.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,35 @@ describe('Instantiate Docker Job', () => {
2626
});
2727
});
2828

29+
describe('Instantiate Docker Job with custom properties', () => {
30+
const docker = new CircleCI.executors.DockerExecutor('cimg/node:lts');
31+
const helloWorld = new CircleCI.commands.Run({
32+
command: 'echo hello world',
33+
});
34+
const jobName = 'my-job';
35+
const job = new CircleCI.Job(jobName, docker, [helloWorld], {
36+
parallelism: 3,
37+
circleci_ip_ranges: true,
38+
});
39+
const jobContents = {
40+
docker: [{ image: 'cimg/node:lts' }],
41+
resource_class: 'medium',
42+
parallelism: 3,
43+
circleci_ip_ranges: true,
44+
steps: [{ run: 'echo hello world' }],
45+
};
46+
47+
it('Should match the expected output', () => {
48+
expect(job.generate(true)).toEqual({ [jobName]: jobContents });
49+
});
50+
51+
it('Add job to config and validate', () => {
52+
const myConfig = new CircleCI.Config();
53+
myConfig.addJob(job);
54+
expect(myConfig.jobs.length).toBeGreaterThan(0);
55+
});
56+
});
57+
2958
describe('Instantiate Parameterized Docker Job With Custom Parameters', () => {
3059
const docker = new CircleCI.executors.DockerExecutor('cimg/node:lts');
3160
const helloWorld = new CircleCI.commands.Run({

0 commit comments

Comments
 (0)