CircleCI-Public / circleci-config-sdk-ts

Generate CircleCI Configuration YAML from JavaScript or TypeScript. Use Dynamic Configuration and the Config SDK together for live generative config.
https://circleci-public.github.io/circleci-config-sdk-ts/
Apache License 2.0
82 stars 29 forks source link

refactor!: Remove reusable executors #47

Closed KyleTryon closed 3 years ago

KyleTryon commented 3 years ago

Remove Reusable Executors

Reusable Executors are an abstraction added to CircleCI Config to emulate programmatic logic. Once CircleCI 2.1 code is processed on CircleCI circleci config process, the reusable executors are expanded and "duplicated" in place.

Removing Reusable Executors allows us to better customize our job creation, now allowing for patterns like Matrix jobs, where a job is dynamically created and added to the config. This is possible because the executor can be directly embedded.

Example from the test added that shows Matrix Jobs:

// Generate a "Matrix" of Jobs with node executors, testing node versions: 13.0.0, 16.0.0, 18.0.0
describe('Generate 3 node-based jobs with different node versions', () => {
  const config = new CircleCI.Config();
  const nodeVersions = ['13.0.0', '16.0.0', '18.0.0'];
  const workflow = new CircleCI.Workflow('my-workflow');
  const helloWorld = new CircleCI.Command.Run({
    command: 'echo hello world',
  });

  nodeVersions.forEach((version) => {
    const docker = new CircleCI.Executor.DockerExecutor(`cimg/node:${version}`);
    const job = new CircleCI.Job(`test-${version}`, docker, [helloWorld]);
    config.addJob(job);
    workflow.addJob(job);
  });

  config.addWorkflow(workflow);

  it('The config should contain three jobs', () => {
    expect(config.jobs.length).toEqual(3);
  });
  it('The config workflow should contain three jobs', () => {
    expect(config.workflows[0].jobs.length).toEqual(3);
  });
});
codecov[bot] commented 3 years ago

Codecov Report

Merging #47 (6997a90) into main (cfc5eea) will increase coverage by 0.65%. The diff coverage is 90.90%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #47      +/-   ##
==========================================
+ Coverage   95.80%   96.45%   +0.65%     
==========================================
  Files          30       30              
  Lines         262      254       -8     
  Branches       28       23       -5     
==========================================
- Hits          251      245       -6     
+ Misses          7        6       -1     
+ Partials        4        3       -1     
Impacted Files Coverage Δ
src/lib/Components/Executor/Executor.ts 100.00% <ø> (ø)
src/lib/Components/Executor/index.ts 100.00% <ø> (ø)
src/lib/Components/Executor/MacOSExecutor.ts 85.71% <50.00%> (ø)
src/lib/Components/Executor/DockerExecutor.ts 100.00% <100.00%> (ø)
src/lib/Components/Executor/MachineExecutor.ts 100.00% <100.00%> (ø)
src/lib/Components/Executor/WindowsExecutor.ts 100.00% <100.00%> (ø)
src/lib/Components/Job/index.ts 100.00% <100.00%> (ø)
src/lib/Config/index.ts 100.00% <100.00%> (+5.40%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update cfc5eea...6997a90. Read the comment docs.