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 circleci_ip_ranges #186

Merged
merged 3 commits into from
Feb 2, 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
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
Loading