githops-core 0.5.2

Core library for githops — config parsing, hook syncing, caching
Documentation
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Config",
  "type": "object",
  "properties": {
    "cache": {
      "description": "Smart caching — skip commands whose inputs haven't changed.\n\nSet `enabled: true` here, then add a `cache.inputs` list to each command you want to cache.  The cache key is a SHA-256 of the command script, any extra `cache.key` strings, and the content of every input file.  A cache hit causes the command to be skipped with a \"cached\" message.  Cache entries are stored in `.githops/cache/` (or `cache.dir`).\n\nExample: ```yaml cache: enabled: true\n\nhooks: pre-commit: commands: - name: lint run: cargo clippy -- -D warnings cache: inputs: [\"src/**/*.rs\", \"Cargo.toml\"] - name: test run: cargo test cache: inputs: [\"src/**/*.rs\", \"tests/**/*.rs\"] key: [\"$RUST_TOOLCHAIN\"] ```",
      "allOf": [
        {
          "$ref": "#/definitions/GlobalCache"
        }
      ]
    },
    "definitions": {
      "description": "Reusable command definitions for YAML anchors.\n\nDefine command templates here using YAML anchors (&name), then reference them with YAML aliases (*name) inside hook command lists. A list alias is automatically flattened into the parent sequence.\n\nSingle command anchor: ```yaml definitions: lint: &lint name: lint run: cargo clippy -- -D warnings ```\n\nList-of-commands anchor: ```yaml definitions: quality: &quality - name: lint run: cargo clippy - name: audit run: cargo audit ```\n\nUsage in hooks (list aliases are inlined automatically): ```yaml hooks: pre-commit: commands: - name: fmt run: cargo fmt --check - *lint        # single command - *quality     # expands to two commands inline ```",
      "type": "object",
      "additionalProperties": {
        "$ref": "#/definitions/DefinitionEntry"
      }
    },
    "hooks": {
      "description": "Hook definitions. Keys are git hook names (e.g. pre-commit, commit-msg).",
      "default": {},
      "allOf": [
        {
          "$ref": "#/definitions/Hooks"
        }
      ]
    },
    "version": {
      "description": "Schema version",
      "default": "1",
      "type": "string"
    }
  },
  "x-githops-version": "0.1.0",
  "definitions": {
    "Command": {
      "type": "object",
      "required": [
        "name",
        "run"
      ],
      "properties": {
        "cache": {
          "description": "Cache configuration for this command. Requires `cache.enabled: true` in the top-level config.",
          "anyOf": [
            {
              "$ref": "#/definitions/CommandCache"
            },
            {
              "type": "null"
            }
          ]
        },
        "depends": {
          "description": "Names of commands in this hook that must complete successfully before this command starts. Forms a DAG; cycles are detected and rejected.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "env": {
          "description": "Additional environment variables for this command",
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "name": {
          "description": "Human-readable label shown in output",
          "type": "string"
        },
        "run": {
          "description": "Shell command to execute. Hook arguments are available as $1, $2, etc.",
          "type": "string"
        },
        "test": {
          "description": "Mark this command as a test-only command (informational; not run during normal hooks).",
          "type": "boolean"
        }
      }
    },
    "CommandCache": {
      "description": "Per-command cache configuration.",
      "type": "object",
      "properties": {
        "inputs": {
          "description": "File glob patterns treated as inputs. The command is re-run only when the content of any matching file changes. Globs are relative to the repository root.  Example: `[\"src/**/*.rs\", \"Cargo.toml\"]`",
          "default": [],
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "key": {
          "description": "Extra strings mixed into the cache key (e.g. environment variable values or tool version strings).  Example: `[\"$RUST_TOOLCHAIN\"]`",
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "CommandEntry": {
      "description": "A command entry in a hook's command list: either an inline command definition or a reference to a named definition (`$ref: name`).\n\nThe `$ref` form lets you reuse commands defined in the `definitions` section without YAML anchors, so changes round-trip correctly through the UI editor.\n\nExample using `$ref`: ```yaml hooks: pre-commit: commands: - name: fmt run: cargo fmt --check - $ref: lint   # references definitions.lint ```",
      "anyOf": [
        {
          "description": "A reference to a named definition. Serialises as `{$ref: name}`.",
          "allOf": [
            {
              "$ref": "#/definitions/RefEntry"
            }
          ]
        },
        {
          "description": "An inline command definition.",
          "allOf": [
            {
              "$ref": "#/definitions/Command"
            }
          ]
        }
      ]
    },
    "DefinitionEntry": {
      "description": "A reusable command definition: a single command mapping or a list of commands.",
      "anyOf": [
        {
          "description": "A list of commands that will be inlined when the anchor is used.",
          "type": "array",
          "items": {
            "$ref": "#/definitions/Command"
          }
        },
        {
          "description": "A single command.",
          "allOf": [
            {
              "$ref": "#/definitions/Command"
            }
          ]
        }
      ]
    },
    "GlobalCache": {
      "description": "Global cache settings.",
      "type": "object",
      "properties": {
        "dir": {
          "description": "Override the cache directory (default: `.githops/cache`).",
          "type": [
            "string",
            "null"
          ]
        },
        "enabled": {
          "description": "Enable caching.  Commands without a `cache` block are always executed.",
          "default": false,
          "type": "boolean"
        }
      }
    },
    "HookConfig": {
      "type": "object",
      "properties": {
        "commands": {
          "description": "Commands to run when this hook fires. Each entry is either an inline command or a `$ref` to a definition.",
          "default": [],
          "type": "array",
          "items": {
            "$ref": "#/definitions/CommandEntry"
          }
        },
        "enabled": {
          "description": "Whether this hook is active. Set to false to temporarily disable.",
          "default": true,
          "type": "boolean"
        },
        "parallel": {
          "description": "Run commands concurrently within each dependency wave.\n\nWhen `true`, commands that have no dependency relationship are started at the same time in separate threads.  Commands that share a `depends` link are still serialised — the dependent command waits until all its dependencies finish successfully.\n\nUse this to speed up independent checks (e.g. lint + test) while keeping ordered steps (e.g. build → deploy) sequential.\n\nExample: ```yaml hooks: pre-push: parallel: true commands: - name: lint run: cargo clippy - name: test run: cargo test   # runs at the same time as lint ```",
          "default": false,
          "type": "boolean"
        }
      }
    },
    "Hooks": {
      "description": "All supported git hooks. Configure any hook by adding its name as a key.",
      "type": "object",
      "properties": {
        "applypatch-msg": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "commit-msg": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "fsmonitor-watchman": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "p4-changelist": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "p4-post-changelist": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "p4-pre-submit": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "p4-prepare-changelist": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "post-applypatch": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "post-checkout": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "post-commit": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "post-index-change": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "post-merge": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "post-receive": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "post-rewrite": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "post-update": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "pre-applypatch": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "pre-auto-gc": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "pre-commit": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "pre-merge-commit": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "pre-push": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "pre-rebase": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "pre-receive": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "prepare-commit-msg": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "proc-receive": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "push-to-checkout": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "reference-transaction": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "sendemail-validate": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "update": {
          "anyOf": [
            {
              "$ref": "#/definitions/HookConfig"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "RefEntry": {
      "description": "A reference to a named definition in the `definitions` section.\n\nSupports two optional overrides that are applied at the point of use, without modifying the shared definition:\n\n```yaml hooks: pre-commit: commands: - $ref: lint                  # use definition as-is - $ref: lint args: \"--fix\"               # appends to the definition's run command name: lint-fix              # overrides the display label ```",
      "type": "object",
      "required": [
        "$ref"
      ],
      "properties": {
        "$ref": {
          "description": "Name of the definition to reference.",
          "type": "string"
        },
        "args": {
          "description": "Extra arguments appended to the definition's `run` command.\n\nThe final command executed is `{definition.run} {args}`. For example, if the definition runs `npm run lint`, setting `args: \"--fix\"` produces `npm run lint --fix`.",
          "type": [
            "string",
            "null"
          ]
        },
        "name": {
          "description": "Override the display name shown in hook output for this specific use. When omitted, the definition's own `name` is used.",
          "type": [
            "string",
            "null"
          ]
        }
      }
    }
  }
}