Skip to content

Commit a188f23

Browse files
authored
Fix a few things and update README (#9)
1 parent b7beca9 commit a188f23

File tree

8 files changed

+238
-10
lines changed

8 files changed

+238
-10
lines changed

README.md

Lines changed: 231 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,237 @@
22

33
[![CircleCI Build Status](https://circleci.com/gh/bufferings/orb-split-config.svg?style=shield "CircleCI Build Status")](https://circleci.com/gh/bufferings/orb-split-config) [![CircleCI Orb Version](https://badges.circleci.com/orbs/bufferings/split-config.svg)](https://circleci.com/orbs/registry/orb/bufferings/orb-split-config) [![GitHub License](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/bufferings/orb-split-config/master/LICENSE) [![CircleCI Community](https://img.shields.io/badge/community-CircleCI%20Discuss-343434.svg)](https://discuss.circleci.com/c/ecosystem/orbs)
44

5-
You can merge split files when CircleCI starts.
6-
This Orb uses CUE https://cuelang.org/ to merge the configuration files.
5+
## Are you having trouble with a large configuration file?
6+
7+
Here is Split Config Orb for you!
8+
9+
You no longer have to tire of managing one huge configuration file. With this Orb, you can split the `config.yml` into multiple files. The split configs are merged when CircleCI starts.
10+
11+
## Getting Started
12+
13+
### `config.yml` file
14+
15+
It's super simple, you just need to prepare the following `config.yml`:
16+
17+
```yaml
18+
version: 2.1
19+
20+
setup: true
21+
22+
orbs:
23+
# Please specify the latest version
24+
split-config: bufferings/[email protected]
25+
26+
workflows:
27+
generate-config:
28+
jobs:
29+
- split-config/generate-config:
30+
find-config-regex: .*/\.circleci/config\.yml
31+
```
32+
33+
The Orb finds the split config files according to the regex, merges them, and starts a CircleCI pipeline with the merged config.
34+
35+
### Enable Dynamic Config
36+
37+
This Orb uses the [Dynamic Config](https://circleci.com/docs/dynamic-config) feature of CircleCI. By default, the feature is disabled, so please [enable the feature](https://circleci.com/docs/dynamic-config#getting-started-with-dynamic-config-in-circleci) to get started.
38+
39+
## How to use
40+
41+
### I want to use regex to find the split configs
42+
43+
You can use regex to specify config paths. Actually, it uses `find` command with the regex. Please use relative paths to the working directory.
44+
45+
**Regex Example1**
46+
47+
For example, if your repository structure is like this:
48+
49+
<img src="./img/example1.png" alt="example1 files" width="300"/>
50+
51+
The `config.yml` is like this:
52+
53+
```yaml
54+
version: 2.1
55+
56+
setup: true
57+
58+
orbs:
59+
# Please specify the latest version
60+
split-config: bufferings/[email protected]
61+
62+
workflows:
63+
generate-config:
64+
jobs:
65+
- split-config/generate-config:
66+
find-config-regex: .*/\.circleci/config\.yml
67+
```
68+
69+
Working example: https://github.com/bufferings/orb-split-config-example1
70+
71+
> **Note**
72+
> The Orb ignores `./.circleci/config.yml` file. Specifically, it automatically adds `-not -regex "\./\.circleci/config\.yml"` option.
73+
74+
**Example2**
75+
76+
Here is another regex example. If you put configs under `.circleci/configs` directory, it will be like this:
77+
78+
```yaml
79+
version: 2.1
80+
81+
setup: true
82+
83+
orbs:
84+
# Please specify the latest version
85+
split-config: bufferings/[email protected]
86+
87+
workflows:
88+
generate-config:
89+
jobs:
90+
- split-config/generate-config:
91+
find-config-regex: \./\.circleci/configs/.*\.yml
92+
```
93+
94+
Working example: https://github.com/bufferings/orb-split-config-example2
95+
96+
### I want to write the split config paths in the `config.yml`
97+
98+
You can set the fixed paths in your `config.yml`. Please use relative paths to the working directory.
99+
100+
```yaml
101+
version: 2.1
102+
103+
setup: true
104+
105+
orbs:
106+
# Please specify the latest version
107+
split-config: bufferings/[email protected]
108+
109+
workflows:
110+
generate-config:
111+
jobs:
112+
- split-config/generate-config:
113+
fixed-config-paths: |
114+
./common/.circleci/config.yml
115+
./service1/.circleci/config.yml
116+
./service2/.circleci/config.yml
117+
./service3/.circleci/config.yml
118+
```
119+
120+
Working example: https://github.com/bufferings/orb-split-config-example3
121+
122+
### I want to write the split config paths in a file
123+
124+
You can also use a file to specify the fixed list. Please use relative paths to the working directory.
125+
126+
```shell
127+
❯ cat .circleci/config-list
128+
./common/.circleci/config.yml
129+
./service1/.circleci/config.yml
130+
./service2/.circleci/config.yml
131+
./service3/.circleci/config.yml
132+
```
133+
134+
```yaml
135+
version: 2.1
136+
137+
setup: true
138+
139+
orbs:
140+
# Please specify the latest version
141+
split-config: bufferings/[email protected]
142+
143+
workflows:
144+
generate-config:
145+
jobs:
146+
- split-config/generate-config:
147+
config-list-path: .circleci/config-list
148+
```
149+
150+
Working example: https://github.com/bufferings/orb-split-config-example4
151+
152+
### I want to use all the ways to specify config paths
153+
154+
You can!
155+
156+
```yaml
157+
version: 2.1
158+
159+
setup: true
160+
161+
orbs:
162+
# Please specify the latest version
163+
split-config: bufferings/[email protected]
164+
165+
workflows:
166+
generate-config:
167+
jobs:
168+
- split-config/generate-config:
169+
config-list-path: .circleci/config-list
170+
fixed-config-paths: |
171+
./service1/.circleci/config.yml
172+
./service2/.circleci/config.yml
173+
find-config-regex: \./service3/\.circleci/configs/.*\.yml
174+
175+
```
176+
177+
Working example: https://github.com/bufferings/orb-split-config-example5
178+
179+
180+
### I want to use Split Config Orb with path-filtering Orb
181+
182+
You can pass the generated config to path-filtering using workspace.
183+
184+
```yaml
185+
version: 2.1
186+
187+
setup: true
188+
189+
orbs:
190+
split-config: bufferings/[email protected]
191+
path-filtering: circleci/[email protected]
192+
193+
workflows:
194+
generate-config:
195+
jobs:
196+
- split-config/generate-config:
197+
find-config-regex: .*/\.circleci/.*\.yml
198+
generated-config-path: /tmp/generated_config.yml
199+
post-steps:
200+
- persist_to_workspace:
201+
root: /tmp
202+
paths:
203+
- generated_config.yml
204+
- path-filtering/filter:
205+
workspace_path: /tmp
206+
config-path: /tmp/generated_config.yml
207+
mapping: |
208+
service1/.* build-service1 true
209+
service2/.* build-service2 true
210+
requires:
211+
- split-config/generate-config
212+
```
213+
214+
Working example: https://github.com/bufferings/orb-split-config-example6
215+
216+
## How it works
217+
218+
The Split Config Orb uses CUE to merge the YAML files.
219+
220+
* CUE https://cuelang.org/
221+
222+
Therefore, it follows the CUE specification to merge the files.
223+
224+
## Restrictions
225+
226+
There're some restrictions coming from the mechanism behind this Orb.
227+
228+
You need to be careful not to use the same name for Jobs and Workflows. Since it is merged into one YAML file in the end, you can't use the same Job name nor Workflow name.
229+
230+
YAML anchors and aliases need to be in the same YAML file. When CUE import YAML, it parse the anchors and aliases in the file. Therefore, you can't put anchors and aliases into different files separately.
231+
232+
## (Advanced) I want to use CUE to write CircleCI config
233+
234+
```yaml
235+
```
7236

8237
---
9238

img/example1.png

48.6 KB
Loading

src/commands/append-find-result.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ parameters:
77
default: /tmp/config-list
88
description: >
99
A file path to append config paths.
10-
Each path in this file should be relateive to the working directory.
10+
Each path in this file should be relative to the working directory.
1111
find-config-regex:
1212
type: string
1313
default: ""

src/commands/append-fixed-paths.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ parameters:
77
default: /tmp/config-list
88
description: >
99
A file path to append config paths.
10-
Each path in this file should be relateive to the working directory.
10+
Each path in this file should be relative to the working directory.
1111
fixed-config-paths:
1212
type: string
1313
default: ""
1414
description: >
1515
Multiline string of fixed config paths to append. One path for each line.
16-
Each path should be relateive to the working directory.
16+
Each path should be relative to the working directory.
1717
1818
steps:
1919
- run:

src/commands/generate-config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ parameters:
77
default: /tmp/config-list
88
description: >
99
A file path to append config paths.
10-
Each path in this file should be relateive to the working directory.
10+
Each path in this file should be relative to the working directory.
1111
generated-config-path:
1212
type: string
1313
default: /tmp/generated-config.yml

src/jobs/generate-config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ parameters:
99
default: /tmp/config-list
1010
description: >
1111
A file path to append config paths.
12-
Each path in this file should be relateive to the working directory.
12+
Each path in this file should be relative to the working directory.
1313
fixed-config-paths:
1414
type: string
1515
default: ""
1616
description: >
1717
Multiline string of fixed config paths to append. One path for each line.
18-
Each path should be relateive to the working directory.
18+
Each path should be relative to the working directory.
1919
find-config-regex:
2020
type: string
2121
default: ""

src/scripts/append-fixed-paths.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
echo "${PARAM_FIND_CONFIG_REGEX}" >> "${PARAM_CONFIG_LIST_PATH}"
3+
echo "${PARAM_FIXED_CONFIG_PATH}" >> "${PARAM_CONFIG_LIST_PATH}"
44

55
echo "Config list ==="
66

src/scripts/generate-config.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ echo "Config list ==="
55
cat "${PARAM_CONFIG_LIST_PATH}"
66

77
echo
8-
98
echo "Generated YAML ==="
109

1110
cat "${PARAM_CONFIG_LIST_PATH}" \

0 commit comments

Comments
 (0)