Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit b37a7b2

Browse files
authored
docs: create matrix deploy sample (#178)
1 parent f3287a8 commit b37a7b2

File tree

7 files changed

+2489
-0
lines changed

7 files changed

+2489
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: 2.1
2+
orbs:
3+
continuation: circleci/[email protected]
4+
node: circleci/[email protected]
5+
setup: true
6+
jobs:
7+
generate-config:
8+
executor: node/default
9+
steps:
10+
- checkout
11+
- node/install-packages:
12+
app-dir: .circleci/src
13+
- run:
14+
name: Generate config
15+
command: cd .circleci/src && npm run generate
16+
- continuation/continue:
17+
configuration_path: .circleci/src/dynamicConfig.yml
18+
workflows:
19+
dynamic-workflow:
20+
jobs:
21+
- generate-config
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as CircleCI from "@circleci/circleci-config-sdk";
2+
3+
// A function that returns an executor for a given version of Node. Optionally configure the resource class.
4+
const nodeExecutor = (
5+
version: string,
6+
resourceSize: CircleCI.types.executors.executor.AnyResourceClassBase = "small",
7+
) => new CircleCI.executors.DockerExecutor(`cimg/node:${version}`, resourceSize);
8+
9+
export { nodeExecutor }
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as CircleCI from '@circleci/circleci-config-sdk';
2+
import { testJob, deployJob } from './jobs';
3+
import { isDeployable } from './utils';
4+
5+
// Create a new config and workflow
6+
const myConfig = new CircleCI.Config();
7+
const myWorkflow = new CircleCI.Workflow('my-workflow');
8+
9+
// Support the three latest versions of Node
10+
const nodeVersions = ["16.19", "18.13", "19.7"];
11+
12+
// Create a test job for each version of Node and add it to the config and workflow
13+
const testJobs = nodeVersions.map((version) => testJob(version));
14+
testJobs.forEach((job) => {
15+
myConfig.addJob(job);
16+
myWorkflow.addJob(job)
17+
});
18+
19+
// If it's a deployable day, add the deploy job to the config and workflow
20+
if (isDeployable()) {
21+
myConfig.addJob(deployJob);
22+
myWorkflow.addJob(deployJob, {
23+
requires: testJobs.map((job) => job.name)
24+
});
25+
}
26+
27+
// Add the workflow to the config
28+
myConfig.addWorkflow(myWorkflow);
29+
30+
// Write the config to a file
31+
myConfig.writeFile('dynamicConfig.yml')
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as CircleCI from "@circleci/circleci-config-sdk";
2+
import { nodeExecutor } from "../executors";
3+
4+
// A function that returns a test job for a given version of Node with a unique name
5+
const testJob = (version: string) =>
6+
new CircleCI.Job(`test-${version.replace('.', '-')}`, nodeExecutor(version), [
7+
new CircleCI.commands.Checkout(),
8+
new CircleCI.commands.Run({
9+
command: 'npm install && npm run test',
10+
}),
11+
]);
12+
13+
const deployJob = new CircleCI.Job(
14+
"deploy",
15+
nodeExecutor("18"),
16+
[
17+
new CircleCI.commands.Checkout(),
18+
new CircleCI.commands.Run({
19+
command: "npm install && npm run deploy"
20+
})
21+
]
22+
)
23+
24+
export { testJob, deployJob }

0 commit comments

Comments
 (0)