Repository navigation
Commit 4debbed
authored
feat: add mode: merge with a layered settings-file (#104)
## What this adds
```yaml
- uses: Vivswan/github-settings-as-code@v3
with:
mode: merge
merged-file: ${{ runner.temp }}/merged.yml
settings-file: | # low to high
fleet/baseline.yml
fleet/bun.yml
.github/settings.yml
fleet/override.yml
- uses: Vivswan/github-settings-as-code@v3
with:
mode: apply
token: ${{ secrets.SETTINGS_TOKEN }}
settings-file: ${{ runner.temp }}/merged.yml
```
```text
$ bun test test/engine/layers.test.ts test/action/run.test.ts
mergeLayers([fleet, bun, repo, override], { layering: "merge" })
labels bug, enhancement + e2e-fuzz -> bug, enhancement, e2e-fuzz (union by name)
rulesets main {deletion, nff} + main {sigs} -> main {deletion, nff, sigs} (rules append by type)
rulesets main {bypass_actors: [5]} + main {bypass: null} -> main without bypass_actors (null deletes, notice)
pages {build_type: workflow} + pages: null -> removed (notice)
labels [...] + {_layering: replace, entries: [...]} -> the higher list alone
mode: merge writes the validated document, makes no API call, reads no token; result: merged
```
## How
Three commits, engine, action, then the value-free refusals:
- `src/engine/layers.ts`: the pure fold. Objects merge key by key; a
higher scalar, array, or tagged value replaces; a higher `null` at any
depth deletes what a lower layer declared. The knobbed list sections
union their entries by key under `merge` when their section module
declares a `layering` (labels by case-folded name, rulesets by name with
`rules` nested by `type`); every other list replaces. `_layering:
merge|replace` on a wrapper or at a document's top level overrides the
run default for that section or file and is consumed. Refusals name the
layer: mis-shaped sections, entries without their key, duplicate keys
within one list in one layer, a `merge` directive on a section without
keyed layering, reference cycles.
- `KeyedListLayering` on `SectionMeta`, typed so only knobbed sections
declare it. Top-level wrappers accept `_layering`; the nested
environment lists reject it.
- Action: `settings-file` is an ordered list in `mode: merge` only (one
path in apply/check, a list there is an input error); new inputs
`merged-file` (required in merge mode) and `layering` (run-wide
default). `mode` is parsed before the token requirement, so merge needs
no token and constructs no client. Each layer is validated standalone on
its null-stripped view, folded, and the result validated again before it
is written. The document schema declares the top-level `_layering`
directive.
- Refusals and notices never print a settings value. Merge mode has no
`private-repos` context, so a shape refusal that echoed a label name or
a rule type could put a private repository's settings into a public log.
Every message goes through one `describeRefusal` over a `Problem` union
and names only the layer, the key path with numeric indices, and the
problem kind: `rulesets[0].rules[0] and rulesets[0].rules[1] both claim
one type; each type belongs to one entry within a layer`,
`rulesets[0].rules[0] must be a mapping; got a string`.
- e2e: `settings_layers` and `expect.merged` in the scenario schema, the
runner writes layer files and compares the merged document; three
scenarios cover the union with a null opt-out, a section-level replace,
and a file-level directive.
## Proof
- `bun run check` green (2418 tests); `bun run test:e2e` 215/215.
- Engine: four codex rounds, the lead's gate review (nulls inside list
entries, cyclic anchors) fixed with negative controls. Action: seven
codex rounds plus the lead's gate review. Refusals: one codex round plus
the lead's gate review; both Copilot threads fixed in that commit.
- Apply and check are unchanged: one document per target.
BREAKING CHANGE: a settings-file path may no longer contain a comma or a
newline in any mode (they are the list separators mode: merge splits
on); apply and check reject such a path with an input error naming the
rule. Rename the file.1 parent 09d6c3f commit 4debbed
192 files changed
Lines changed: 9104 additions & 1779 deletions
File tree
- .github
- scripts
- workflows
- docs
- operate
- playbooks
- reference
- start
- upgrading
- lib
- src
- action
- engine
- github
- report
- sections
- actions_secrets
- scenarios
- actions_variables
- scenarios
- actions
- agents_secrets
- scenarios
- agents_variables
- scenarios
- autolinks
- branches
- check_suite_preferences
- code_quality_setup
- code_scanning_default_setup
- codespaces_secrets
- scenarios
- collaborators
- scenarios
- contract
- custom_properties
- scenarios
- dependabot_secrets
- scenarios
- deploy_keys
- scenarios
- environments
- scenarios
- interaction_limits
- labels
- scenarios
- milestones
- scenarios
- pages
- repository
- rulesets
- scenarios
- secret_scanning_custom_patterns
- scenarios
- teams
- webhooks
- scenarios
- workflows
- test
- action
- architecture
- docs
- e2e
- mock
- openapi
- scenarios
- engine
- fixtures
- layers
- github
- report
- scripts
- sections
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
| 157 | + | |
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
| 163 | + | |
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
173 | 175 | | |
174 | 176 | | |
175 | 177 | | |
| |||
194 | 196 | | |
195 | 197 | | |
196 | 198 | | |
197 | | - | |
| 199 | + | |
198 | 200 | | |
199 | 201 | | |
200 | 202 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
114 | 116 | | |
115 | 117 | | |
116 | 118 | | |
117 | | - | |
| 119 | + | |
118 | 120 | | |
119 | 121 | | |
120 | 122 | | |
| |||
123 | 125 | | |
124 | 126 | | |
125 | 127 | | |
126 | | - | |
| 128 | + | |
127 | 129 | | |
128 | 130 | | |
129 | | - | |
| 131 | + | |
130 | 132 | | |
131 | 133 | | |
132 | 134 | | |
| |||
255 | 257 | | |
256 | 258 | | |
257 | 259 | | |
| 260 | + | |
| 261 | + | |
258 | 262 | | |
259 | | - | |
| 263 | + | |
260 | 264 | | |
261 | 265 | | |
262 | 266 | | |
| |||
267 | 271 | | |
268 | 272 | | |
269 | 273 | | |
270 | | - | |
271 | | - | |
272 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
273 | 277 | | |
274 | 278 | | |
275 | 279 | | |
| |||
358 | 362 | | |
359 | 363 | | |
360 | 364 | | |
361 | | - | |
| 365 | + | |
362 | 366 | | |
363 | 367 | | |
364 | 368 | | |
| |||
374 | 378 | | |
375 | 379 | | |
376 | 380 | | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
377 | 393 | | |
378 | 394 | | |
379 | 395 | | |
380 | 396 | | |
381 | 397 | | |
382 | 398 | | |
383 | 399 | | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
384 | 403 | | |
385 | 404 | | |
386 | 405 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
0 commit comments