Skip to content

Commit 370db68

Browse files
WIP move base config to circleci toolkitrc
1 parent 481750c commit 370db68

File tree

6 files changed

+2431
-114
lines changed

6 files changed

+2431
-114
lines changed

core/cli/test/__snapshots__/config.test.ts.snap

Lines changed: 2317 additions & 7 deletions
Large diffs are not rendered by default.

plugins/circleci-deploy/test/__snapshots__/circleci-deploy.test.ts.snap

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,25 @@ executors:
88
- image: cimg/node:20.19-browsers
99
jobs:
1010
checkout:
11-
docker:
12-
- image: cimg/base:stable
11+
executor: base
1312
steps:
13+
- attach_workspace:
14+
at: .
1415
- checkout
1516
- persist_to_workspace:
1617
root: .
1718
paths:
1819
- .
20+
setup:
21+
executor: node
22+
steps:
23+
- attach_workspace:
24+
at: .
25+
- node/install-packages
26+
- persist_to_workspace:
27+
root: .
28+
paths:
29+
- .
1930
build:
2031
executor: node
2132
steps:
@@ -112,18 +123,13 @@ jobs:
112123
CIRCLE_BRANCH: << pipeline.event.github.pull_request.head.ref >>
113124
workflows:
114125
tool-kit:
115-
when:
116-
not:
117-
equal:
118-
- scheduled_pipeline
119-
- << pipeline.trigger_source >>
120126
jobs:
121127
- checkout:
128+
requires: []
122129
filters:
123130
tags:
124131
only: /^v\\d+\\.\\d+\\.\\d+(-.+)?/
125132
- setup:
126-
executor: node
127133
requires:
128134
- checkout
129135
filters:
@@ -173,19 +179,12 @@ workflows:
173179
only: /^v\\d+\\.\\d+\\.\\d+(-.+)?/
174180
branches:
175181
only: main
182+
when: pipeline.trigger_source != "scheduled_pipeline"
176183
nightly:
177-
when:
178-
and:
179-
- equal:
180-
- scheduled_pipeline
181-
- << pipeline.trigger_source >>
182-
- equal:
183-
- nightly
184-
- << pipeline.schedule.name >>
185184
jobs:
186-
- checkout
185+
- checkout:
186+
requires: []
187187
- setup:
188-
executor: node
189188
requires:
190189
- checkout
191190
- build:
@@ -200,6 +199,9 @@ workflows:
200199
filters:
201200
branches:
202201
ignore: main
202+
when: |
203+
pipeline.trigger_source == "scheduled_pipeline" and
204+
pipeline.schedule.name == "nightly"
203205
pr-close:
204206
jobs:
205207
- checkout:
@@ -215,5 +217,7 @@ workflows:
215217
216218
(pipeline.event.name == "pull_request" and pipeline.event.action ==
217219
"closed")
220+
orbs:
221+
node: circleci/node@5.0.2
218222
"
219223
`;

plugins/circleci-npm/test/__snapshots__/circleci-npm.test.ts.snap

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,25 @@ executors:
88
- image: cimg/node:20.19-browsers
99
jobs:
1010
checkout:
11-
docker:
12-
- image: cimg/base:stable
11+
executor: base
1312
steps:
13+
- attach_workspace:
14+
at: .
1415
- checkout
1516
- persist_to_workspace:
1617
root: .
1718
paths:
1819
- .
20+
setup:
21+
executor: node
22+
steps:
23+
- attach_workspace:
24+
at: .
25+
- node/install-packages
26+
- persist_to_workspace:
27+
root: .
28+
paths:
29+
- .
1930
build:
2031
executor: node
2132
steps:
@@ -54,18 +65,13 @@ jobs:
5465
- .toolkitstate
5566
workflows:
5667
tool-kit:
57-
when:
58-
not:
59-
equal:
60-
- scheduled_pipeline
61-
- << pipeline.trigger_source >>
6268
jobs:
6369
- checkout:
70+
requires: []
6471
filters:
6572
tags:
6673
only: /^v\\d+\\.\\d+\\.\\d+(-.+)?/
6774
- setup:
68-
executor: node
6975
requires:
7076
- checkout
7177
filters:
@@ -92,19 +98,12 @@ workflows:
9298
branches:
9399
ignore: /.*/
94100
context: npm-publish-token
101+
when: pipeline.trigger_source != "scheduled_pipeline"
95102
nightly:
96-
when:
97-
and:
98-
- equal:
99-
- scheduled_pipeline
100-
- << pipeline.trigger_source >>
101-
- equal:
102-
- nightly
103-
- << pipeline.schedule.name >>
104103
jobs:
105-
- checkout
104+
- checkout:
105+
requires: []
106106
- setup:
107-
executor: node
108107
requires:
109108
- checkout
110109
- build:
@@ -113,6 +112,9 @@ workflows:
113112
- test:
114113
requires:
115114
- build
115+
when: |
116+
pipeline.trigger_source == "scheduled_pipeline" and
117+
pipeline.schedule.name == "nightly"
116118
pr-close:
117119
jobs:
118120
- checkout:
@@ -125,5 +127,7 @@ workflows:
125127
126128
(pipeline.event.name == "pull_request" and pipeline.event.action ==
127129
"closed")
130+
orbs:
131+
node: circleci/node@5.0.2
128132
"
129133
`;

plugins/circleci/.toolkitrc.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,25 @@ optionsSchema: './lib/schemas/plugin'
99
options:
1010
hooks:
1111
- CircleCi:
12+
custom:
13+
orbs:
14+
node: circleci/node@5.0.2
1215
jobs:
16+
- name: checkout
17+
steps:
18+
custom:
19+
- checkout
20+
custom:
21+
executor: base
22+
workspace:
23+
persist: ['.']
24+
splitIntoMatrix: false
25+
- name: setup
26+
steps:
27+
custom:
28+
- node/install-packages
29+
workspace:
30+
persist: ['.']
1331
- name: build
1432
command: 'build:ci'
1533
workspace:
@@ -18,7 +36,13 @@ options:
1836
command: 'test:ci'
1937
workflows:
2038
- name: 'tool-kit'
39+
custom:
40+
when: pipeline.trigger_source != "scheduled_pipeline"
2141
jobs:
42+
- name: checkout
43+
- name: setup
44+
requires:
45+
- 'checkout'
2246
- name: build
2347
requires:
2448
- 'setup'
@@ -27,7 +51,15 @@ options:
2751
- 'build'
2852
runOnRelease: true
2953
- name: 'nightly'
54+
custom:
55+
when: |
56+
pipeline.trigger_source == "scheduled_pipeline" and
57+
pipeline.schedule.name == "nightly"
3058
jobs:
59+
- name: checkout
60+
- name: setup
61+
requires:
62+
- 'checkout'
3163
- name: build
3264
requires:
3365
- 'setup'

plugins/circleci/src/circleci-config.ts

Lines changed: 16 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -105,61 +105,24 @@ const mergeWithConcatenatedArrays = (arg0: unknown, ...args: unknown[]) =>
105105
}
106106
})
107107

108-
const getBaseConfig = (nodeVersions: string[], tagFilterRegex?: string): CircleCIState => {
109-
const runsOnMultipleNodeVersions = nodeVersions.length > 1
110-
const setupMatrix = runsOnMultipleNodeVersions
111-
? matrixBoilerplate('setup', nodeVersions)
112-
: { executor: 'node' }
113-
return {
108+
const getBaseConfig = (nodeVersions: string[]): CircleCIState => ({
114109
version: 2.1,
115-
executors: Object.fromEntries(
116-
nodeVersions.map((version, i) => [
117-
nodeVersionToExecutor(version, i),
118-
{
119-
docker: [{ image: `cimg/node:${version}` }]
120-
}
121-
])
122-
),
123-
jobs: {
124-
checkout: {
125-
docker: [{ image: 'cimg/base:stable' }],
126-
steps: ['checkout', persistWorkspaceStep(['.'])]
127-
}
128-
},
129-
workflows: {
130-
'tool-kit': {
131-
when: {
132-
not: {
133-
equal: ['scheduled_pipeline', '<< pipeline.trigger_source >>']
134-
}
135-
},
136-
jobs: [
137-
tagFilterRegex ? { checkout: tagFilter(tagFilterRegex) } : 'checkout',
110+
executors: {
111+
base: {
112+
docker: [{ image: 'cimg/base:stable' }]
113+
},
114+
...Object.fromEntries(
115+
nodeVersions.map((version, i) => [
116+
nodeVersionToExecutor(version, i),
138117
{
139-
setup: {
140-
...setupMatrix,
141-
requires: ['checkout'],
142-
...(tagFilterRegex ? tagFilter(tagFilterRegex) : {})
143-
}
118+
docker: [{ image: `cimg/node:${version}` }]
144119
}
145-
]
146-
},
147-
nightly: {
148-
when: {
149-
and: [
150-
{
151-
equal: ['scheduled_pipeline', '<< pipeline.trigger_source >>']
152-
},
153-
{
154-
equal: ['nightly', '<< pipeline.schedule.name >>']
155-
}
156-
]
157-
},
158-
jobs: ['checkout', { setup: { ...setupMatrix, requires: ['checkout'] } }]
159-
}
160-
}
161-
}
162-
}
120+
])
121+
),
122+
},
123+
jobs: {},
124+
workflows: {}
125+
})
163126

164127
const rootOptionKeys = ['executors', 'jobs', 'workflows'] as const satisfies readonly (keyof Omit<
165128
CircleCiOptions,
@@ -570,7 +533,7 @@ export default class CircleCi extends Hook<
570533
}
571534
const generatedConfig = mergeWithConcatenatedArrays(
572535
{},
573-
this.options.disableBaseConfig ? {} : getBaseConfig(nodeVersions, configuredTagFilterRegex),
536+
this.options.disableBaseConfig ? {} : getBaseConfig(nodeVersions),
574537
generated,
575538
this.options.custom ?? {}
576539
)

0 commit comments

Comments
 (0)