Skip to content

Commit 4e495a7

Browse files
authored
Merge pull request #92 from mbarbin/crs-config.schema.json
Add distribution of crs-config.schema.json to validate configs
2 parents 74d6230 + c5e6bd1 commit 4e495a7

File tree

16 files changed

+249
-61
lines changed

16 files changed

+249
-61
lines changed

.github/crs-config.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
{
2+
// This config uses a relative path to the schema from the source tree. This
3+
// is intentional: in this repository, CRs Actions (.github/workflows/crs.yml)
4+
// builds and runs the crs binary from the checked-out sources, not from a
5+
// versioned release. The schema reference must stay in sync with the local
6+
// build to validate against the latest config format.
7+
//
8+
// Normal repositories using crs should instead reference a version-pinned
9+
// schema URL matching their installed crs version. See the documentation at
10+
// doc/docs/reference/crs-actions-config/README.md for details.
11+
"$schema": "../schema/crs-config.schema.json",
212
"default_repo_owner": "mbarbin",
313
"user_mentions_allowlist": [
414
"mbarbin"

.github/workflows/release-artifacts.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,19 @@ jobs:
6060
bin_name="${{ github.workspace }}/crs-$TAG_NAME-$os-$arch"
6161
cp "$OPAM_DESTDIR/bin/crs" $bin_name
6262
echo "BIN_NAME=$bin_name" >> $GITHUB_ENV
63+
schema_name="${{ github.workspace }}/crs-config.schema.json"
64+
cp "$OPAM_DESTDIR/share/crs/schema/crs-config.schema.json" $schema_name
65+
echo "SCHEMA_NAME=$schema_name" >> $GITHUB_ENV
6366
6467
- name: Attest Build Provenance
6568
uses: actions/attest-build-provenance@v3
6669
with:
6770
subject-path: "${{ env.BIN_NAME }}"
6871

6972
- name: Upload Release Artifacts
70-
uses: softprops/action-gh-release@72f2c25fcb47643c292f7107632f7a47c1df5cd8 # v2.3.2
73+
uses: softprops/action-gh-release@6cbd405e2c4e67a21c47fa9e383d020e4e28b836 # v2.3.3
7174
with:
7275
tag_name: ${{ env.TAG_NAME }}
73-
files: ${{ env.BIN_NAME }}
76+
files: |
77+
${{ env.BIN_NAME }}
78+
${{ env.SCHEMA_NAME }}

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
{
2+
"files.associations": {
3+
"**/crs-config.json": "jsonc"
4+
},
5+
"[jsonc]": {
6+
"files.insertFinalNewline": true
7+
},
28
"cSpell.words": [
39
"alist",
410
"autofmt",

CHANGES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 0.0.2025XXXX (unreleased)
2+
3+
### Added
4+
5+
- Added local dunolint invariants (#91, @mbarbin).
6+
7+
### Changed
8+
9+
- Switch to `pplumbing-*` split packages (#87, @mbarbin).
10+
111
## 0.0.20250914 (2025-09-14)
212

313
### Changed

doc/docs/reference/crs-actions-config/README.md

Lines changed: 68 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
This document provides a complete reference for the `crs-config.json` configuration file used by CRs Actions in GitHub Actions workflows.
44

5-
## Configuration File Location
5+
## Overview
66

7-
The configuration file should be placed at `.github/crs-config.json` in your repository root.
7+
The configuration file should be placed at `.github/crs-config.json` in your repository root. The file uses JSON5 format, which supports comments and trailing commas.
88

9-
## Configuration Schema
9+
## Quick Start
1010

11-
The file uses JSON5 format, which supports comments and trailing commas.
12-
13-
### Complete Example
11+
Here's a complete working example showing all available configuration options:
1412

1513
<!-- $MDX file=complete-example.json -->
1614
```json
1715
{
16+
// Enable editor validation and auto-completion (replace with your crs version).
17+
"$schema": "https://github.com/mbarbin/crs/releases/download/v1.2.3/crs-config.schema.json",
18+
1819
// Alice takes over CRs that are otherwise hard to assign.
1920
default_repo_owner: "alice",
2021

@@ -32,15 +33,9 @@ The file uses JSON5 format, which supports comments and trailing commas.
3233
}
3334
```
3435

35-
You can validate a configuration file using the *crs* cli like this:
36-
37-
```bash
38-
$ crs tools config validate complete-example.json
39-
```
40-
41-
The command silently exit 0 when the config is valid, or otherwise complains on *stderr* and a non zero exit code (examples below).
36+
Replace `v1.2.3` with your installed `crs` version (check with `crs --version`). The `$schema` field enables editor validation and auto-completion features (see [Validation](#validation) section below).
4237

43-
## Fields Reference
38+
## Configuration Reference
4439

4540
### `default_repo_owner`
4641

@@ -55,11 +50,13 @@ If the repository is owned by an individual, this would typically be that user.
5550

5651
- **Type:** `array of strings` (optional)
5752
- **Example:** `["alice", "bob", "charlie"]`
58-
- **Default** same as supplying an empty array (no user enabled).
53+
- **Default:** `[]` (empty array - no mentions allowed)
54+
55+
List of users who can be mentioned in CR annotations using `@username` mentions. Only users explicitly listed here can be notified through GitHub mentions.
5956

60-
Enables a specific list of users to be notified in annotation comments when notifications are requested. This is a protection measure to avoid spamming users that do not have ties to a repository in particular, or simply do not wish to be notified via CRs.
57+
If this field is not provided, it defaults to an empty list, meaning no user mentions are allowed. This is a protection measure to avoid spamming users who do not have ties to the repository or do not wish to be notified via CRs.
6158

62-
When specified, only users in this allowlist can be mentioned in CR annotations. This helps prevent typos in usernames and ensures CRs are only assigned to valid team members.
59+
Adding users to this list enables notifications for them and helps prevent typos in usernames by restricting mentions to known team members.
6360

6461
### `invalid_crs_annotation_severity`
6562

@@ -77,23 +74,64 @@ Controls the GitHub annotation severity level for invalid CR syntax. This determ
7774

7875
Controls the GitHub annotation severity level for CRs that are due now (such as in the PR where they were found).
7976

80-
## GitHub Annotation Severity Levels
77+
#### About Annotation Severity Levels
8178

82-
The severity levels map to GitHub's annotation levels. See [GitHub's documentation on annotation levels](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-error-message) for details on how these are displayed in the UI.
79+
The severity levels map to GitHub's annotation levels (see [GitHub's documentation](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-error-message) for details):
8380

8481
- **Error**: Most prominent display, typically for critical issues
85-
- **Warning**: Medium prominence, suitable for issues that should be addressed (default for `invalid_crs_annotation_severity`)
86-
- **Info**: Informational notice messages (default for `crs_due_now_annotation_severity`)
82+
- **Warning**: Medium prominence, suitable for issues that should be addressed
83+
- **Info**: Informational notice messages
8784

8885
## Validation
8986

87+
Configuration files can be validated in two ways: real-time validation in your editor using JSON Schema, or batch validation using the `crs` CLI command.
88+
89+
### Editor Validation with JSON Schema
90+
91+
CRs provides a JSON Schema that enables real-time validation and editor features like auto-completion, inline validation, and hover documentation.
92+
93+
#### Enabling Schema Validation
94+
95+
Add a `$schema` field to your `.github/crs-config.json` that matches your installed `crs` version:
96+
97+
<!-- $MDX skip -->
98+
```json
99+
{
100+
"$schema": "https://github.com/mbarbin/crs/releases/download/v1.2.3/crs-config.schema.json",
101+
"default_repo_owner": "alice",
102+
"user_mentions_allowlist": ["alice", "bob"]
103+
}
104+
```
105+
106+
Replace `v1.2.3` with your installed `crs` version. Check your version with:
107+
108+
<!-- $MDX skip -->
109+
```bash
110+
$ crs --version
111+
```
112+
113+
**Important:** When you upgrade `crs`, update the version in the `$schema` URL to match. Editors cache schemas, so using `latest` can cause validation issues when the cached schema doesn't match your installed version.
114+
115+
#### Editor Features
116+
117+
Once the `$schema` field is added, editors like VS Code will:
118+
119+
- **Validate** - Show red squiggles for invalid values or unknown fields
120+
- **Auto-complete** - Press Ctrl+Space to see available fields and enum values
121+
- **Hover documentation** - Hover over fields to see their descriptions and valid values
122+
- **Inline hints** - Get suggestions for default values
123+
124+
**Note:** Editors cache the schema locally after the first fetch, so schema validation works offline once cached.
125+
126+
### Command-Line Validation
127+
90128
The `crs` CLI provides a validation command to check your configuration files. The validation checks:
91129
- JSON syntax correctness
92130
- Required fields presence
93131
- Value type correctness
94132
- Enum values validity
95133

96-
### Basic Validation
134+
#### Basic Validation
97135

98136
To validate your configuration file:
99137

@@ -102,11 +140,9 @@ To validate your configuration file:
102140
crs tools config validate .github/crs-config.json
103141
```
104142

105-
### Validation Examples
106-
107-
#### Valid Minimal Configuration
143+
#### Validation Examples
108144

109-
At the moment all fields in the config are optional, so an empty json object is a minimal valid configuration:
145+
**Valid Minimal Configuration** - At the moment all fields in the config are optional, so an empty json object is a minimal valid configuration:
110146

111147
<!-- $MDX file=valid-minimal.json -->
112148
```json
@@ -117,13 +153,12 @@ At the moment all fields in the config are optional, so an empty json object is
117153
$ crs tools config validate valid-minimal.json
118154
```
119155

120-
#### Valid Full Configuration
121-
122-
A complete configuration with all optional fields, in regular json:
156+
**Valid Full Configuration** - A complete configuration with all optional fields, in regular json:
123157

124158
<!-- $MDX file=valid-full.json -->
125159
```json
126160
{
161+
"$schema": "https://github.com/mbarbin/crs/releases/download/0.0.20250914/crs-config.schema.json",
127162
"default_repo_owner": "alice",
128163
"user_mentions_allowlist": [
129164
"alice",
@@ -139,9 +174,7 @@ A complete configuration with all optional fields, in regular json:
139174
$ crs tools config validate valid-full.json
140175
```
141176

142-
#### Configuration with Selected Fields Only
143-
144-
Since all fields are optional, you can have a configuration with just specific fields:
177+
**Configuration with Selected Fields Only** - Since all fields are optional, you can have a configuration with just specific fields:
145178

146179
<!-- $MDX file=minimal-with-allowlist.json -->
147180
```json
@@ -154,11 +187,7 @@ Since all fields are optional, you can have a configuration with just specific f
154187
$ crs tools config validate minimal-with-allowlist.json
155188
```
156189

157-
### Invalid Config Examples
158-
159-
#### Warning: Use of wrapped enum
160-
161-
Enum values used to be wrapped in the config format. This is still supported for compatibility but now this creates a warning:
190+
**Warning: Use of wrapped enum** - Enum values used to be wrapped in the config format. This is still supported for compatibility but now this creates a warning:
162191

163192
<!-- $MDX file=wrapped-enum.json -->
164193
```json
@@ -175,9 +204,7 @@ expected to be a json string rather than a list.
175204
Hint: Change it to simply: "Warning"
176205
```
177206

178-
#### Invalid: Wrong Type for Field
179-
180-
Configuration with incorrect type for `user_mentions_allowlist`:
207+
**Invalid: Wrong Type for Field** - Configuration with incorrect type for `user_mentions_allowlist`:
181208

182209
<!-- $MDX file=invalid-wrong-type.json -->
183210
```json
@@ -196,9 +223,7 @@ User handle list expected to be a list of json strings.
196223
[123]
197224
```
198225

199-
#### Invalid: Bad Severity Value
200-
201-
Configuration with invalid annotation severity:
226+
**Invalid: Bad Severity Value** - Configuration with invalid annotation severity:
202227

203228
<!-- $MDX file=invalid-severity.json -->
204229
```json

doc/docs/reference/crs-actions-config/complete-example.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
// Enable editor validation and auto-completion (replace with your crs version).
3+
"$schema": "https://github.com/mbarbin/crs/releases/download/v1.2.3/crs-config.schema.json",
4+
25
// Alice takes over CRs that are otherwise hard to assign.
36
default_repo_owner: "alice",
47

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"default_repo_owner": "alice",
33
"invalid_crs_annotation_severity": "Notice"
4-
}
4+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"default_repo_owner": "alice",
33
"user_mentions_allowlist": "bob"
4-
}
4+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
22
"user_mentions_allowlist": ["alice", "bob"]
3-
}
3+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://github.com/mbarbin/crs/releases/download/0.0.20250914/crs-config.schema.json",
23
"default_repo_owner": "alice",
34
"user_mentions_allowlist": [
45
"alice",
@@ -7,4 +8,4 @@
78
],
89
"invalid_crs_annotation_severity": "Warning",
910
"crs_due_now_annotation_severity": "Info"
10-
}
11+
}

0 commit comments

Comments
 (0)