Skip to content

Use the new Config SDK to create the config #11

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

Draft
wants to merge 18 commits into
base: develop
Choose a base branch
from
Draft
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
77 changes: 14 additions & 63 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,71 +1,22 @@
# https://circleci.com/docs/2.0/config-intro/

version: 2.1

orbs:
node: circleci/[email protected]

continuation: circleci/[email protected]
node: circleci/[email protected]
setup: true
jobs:
js-build:
docker:
- image: cimg/node:14.18
generate-config:
executor: node/default
steps:
- checkout
- node/install-packages
- node/install-packages:
app-dir: .circleci/dynamic
- run:
name: Running JS linting and unit test
command: |
npm run lint:js
npm run test:js

php-lint:
docker:
- image: cimg/php:8.1
steps:
- checkout
- run:
name: Linting PHP
command: |
composer i
composer lint

php-test:
parameters:
php-version-number:
type: string
docker:
- image: cimg/php:<< parameters.php-version-number >>
steps:
- checkout
- run:
name: Testing PHP
command: |
composer i
composer test

e2e-test:
machine:
image: ubuntu-2004:202111-02
steps:
- checkout
- node/install-packages
- run:
name: Running e2e tests
command: |
npm run wp-env start
npm run test:e2e
- store_artifacts:
path: artifacts

name: Generate config
command: npm start
working_directory: .circleci/dynamic
- continuation/continue:
configuration_path: .circleci/dynamic/dynamicConfig.yml
workflows:
test-flow:
dynamic-workflow:
jobs:
- js-build
- php-lint
- php-test:
requires:
- php-lint
matrix:
parameters:
php-version-number: [ '7.3', '7.4', '8.0', '8.1' ]
- e2e-test
- generate-config
103 changes: 103 additions & 0 deletions .circleci/dynamic/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import * as fs from "fs";
import CircleCI from "@circleci/circleci-config-sdk";

const config = new CircleCI.Config();
const workflow = new CircleCI.Workflow("test-lint");
config.addWorkflow(workflow);

const phpVersionParameterName = "php-version-number";
const orbManifest: CircleCI.types.orb.OrbImportManifest = {
jobs: {},
commands: {
"install-packages": new CircleCI.parameters.CustomParametersList(),
},
executors: {},
};

const nodeOrb = new CircleCI.orb.OrbImport(
"node",
"circleci",
"node",
"5.0",
undefined,
orbManifest
);
const phpOrb = new CircleCI.orb.OrbImport(
"php",
"circleci",
"php",
"1.1",
undefined,
orbManifest
);

config.importOrb(nodeOrb);
config.importOrb(phpOrb);

[
new CircleCI.Job(
"js-build",
new CircleCI.executors.DockerExecutor("cimg/node:14.18"),
[
new CircleCI.commands.Checkout(),
new CircleCI.reusable.ReusedCommand(nodeOrb.commands["install-packages"]),
new CircleCI.commands.Run({
name: "Running JS linting and unit test",
command: `npm run lint:js \n npm run test:js`,
}),
]
),
new CircleCI.Job(
"php-lint",
new CircleCI.executors.DockerExecutor("cimg/php:8.1"),
[
new CircleCI.commands.Checkout(),
new CircleCI.reusable.ReusedCommand(phpOrb.commands["install-packages"]),
new CircleCI.commands.Run({ command: "composer lint" }),
]
),
new CircleCI.reusable.ParameterizedJob(
"php-test",
new CircleCI.reusable.ReusableExecutor(
"php",
new CircleCI.executors.DockerExecutor(
"cimg/php:<< parameters.php-version-number >>"
),
new CircleCI.parameters.CustomParametersList([
new CircleCI.parameters.CustomParameter(
phpVersionParameterName,
CircleCI.mapping.ParameterSubtype.STRING
),
])
).executor
)
.defineParameter(phpVersionParameterName, CircleCI.mapping.ParameterSubtype.STRING)
.addStep(new CircleCI.commands.Checkout())
.addStep(
new CircleCI.reusable.ReusedCommand(phpOrb.commands["install-packages"])
)
.addStep(new CircleCI.commands.Run({ command: "composer test" })),
new CircleCI.Job(
"e2e-test",
new CircleCI.executors.MachineExecutor("large", "ubuntu-2004:202111-02"),
[
new CircleCI.commands.Checkout(),
new CircleCI.reusable.ReusedCommand(nodeOrb.commands["install-packages"]),
new CircleCI.commands.Run({
name: "Running e2e tests",
command: "npm run wp-env start && npm run test:e2e",
}),
new CircleCI.commands.StoreArtifacts({ path: "artifacts" }),
]
),
].forEach((job) => {
config.addJob(job);
workflow.addJob(
job,
job.name === "php-test"
? { matrix: { [phpVersionParameterName]: ["7.3", "7.4", "8.0", "8.1"] } }
: undefined
);
});

fs.writeFile("./dynamicConfig.yml", config.stringify(), () => {});
171 changes: 171 additions & 0 deletions .circleci/dynamic/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions .circleci/dynamic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "circleci-tutorial-for-beginners-dynamic-config",
"version": "0.1.0",
"description": "Dynamic CircleCI® config",
"author": "Ryan Kienstra",
"main": "index.ts",
"type": "module",
"scripts": {
"lint": "prettier --check index.ts",
"lint:fix": "prettier --write index.ts",
"start": "ts-node --esm index.ts"
},
"license": "GPL-2.0-or-later",
"devDependencies": {
"@circleci/circleci-config-sdk": "^0.10.1",
"@types/node": "^18.7.20",
"prettier": "^2.7.1",
"ts-node": "^10.9.1",
"tslib": "^2.4.0",
"typescript": "^4.8.3"
}
}
9 changes: 9 additions & 0 deletions .circleci/dynamic/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "Node",
"esModuleInterop": true,
"noEmit": true
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
vendor
.circleci/dynamic/dynamicConfig.yml