Scriptable circle.yml files (ex: circle.js, circle.py)

circle.yml

#1

This feature request is to make CircleCI configuration files (circle.yml) more scriptable instead of a completely static templating language. This is what it might look like with JS:

// circle.js
export function machine() {
  return {
    node: 'v5.11.0',
    services: ['docker'],
  };
}

export function test() {
  return { override: ['echo "no tests"'] };
}

Ruby or Python would be fine too.

Motivation
Since we have a full programming language, more advanced CI configuration can be pushed into user space instead of needing CircleCI to add new features to the circle.yml runner.

One example is an “import” feature – we want to import one circle.yml file from another: at my company we merged several repos, each with its own circle.yml, into one repo. So our code looks like this:

superproject/
    circle.yml
    subproject1/
        circle.yml
    subproject2/
        circle.yml

What we want to do is run the tests for subproject1 when files under subproject1 are modified, and same for subproject2. (You could also imagine other conditions for running tests; ex: always run all tests when pushing to the release branch.) These arbitrary conditions are easy to script in JS/Python/Ruby:

// support async functions too plz
export async function tests() {
  let changes = await askGitWhichFilesChanged();
  let commands = { override: [] };

  if (didChangeSubproject1(changes)) {
    let subproject1Commands = await readSubproject1TestOverrideCommands();
    commands.override.push(...subproject1Commands);
  }

  if (didChangeSubproject2(changes)) {
    let subproject2Commands = await readSubproject2TestOverrideCommands();
    commands.override.push(...subproject2Commands);
  }

  return commands;
}

My use case is maybe an unusual one, which is part of my point – a lot of people have unique needs and first-class support for a scripting language lets people write whatever code they want to meet their needs, and CircleCI doesn’t need to anticipate and implement as many features for us.


#2