You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit adds important features to `configlet sync`.
Before this commit, the `sync` command operated only on tests. For each
Practice Exercise on the track that existed in the
`exercism/problem-specifications` repo, `sync` would check or update the
exercise's `.meta/tests.toml` file using the corresponding upstream
`canonical-data.json` file.
With this commit, the `sync` command still has that functionality
(which can now be toggled with the `--tests` option). But for such
Practice Exercises that come from `problem-specifications`, `sync` also
gains these new options:
- `--docs` to check or update each exercise's `.docs/instructions.md`
(and possibly `.docs/introduction.md`) file, using the corresponding
docs in `problem-specifications`.
- `--metadata` to check or update the `blurb`, `source`, and
`source_url` values in each exercise's `.meta/config.json` file,
using those in the corresponding `metadata.toml` file in
`problem-specifications`.
And for both Concept Exercises and Practice Exercises, `sync` gains
these new options:
- `--filepaths` for populating empty or missing `files` values in an
exercise `.meta/config.json` from the track `config.json` file.
- `-y/--yes` to auto-confirm every prompt for updating docs, filepaths,
and metadata.
Note that the `-y/--yes` option does not affect prompts for updating
tests. Before this commit, `sync` had a `--mode` option that allowed the
user to specify whether they want to be prompted (the default) to
include/exclude/skip each unseen test individually, or non-interactively
include/exclude all of them. This commit replaces the `--mode` option:
the user should now pass the mode value to the `--tests` option instead
(for example, `--tests include`). The default is still `choose`.
A plain `configlet sync` operates on the full syncing scope, and so
does the same as `configlet sync --docs --filepaths --metadata --tests`.
The `sync` command still operates on every exercise by default, and
still does not create/alter the track's files unless the `-u/--update`
option is used.
When writing a `.meta/config.json` file, `sync` tries to maintain the
key order that it saw, aiming to minimize noise in diffs and PRs. An
exception is when the file is missing or lacks required keys, in which
case configlet will create those files and keys.
Therefore when adding a Practice Exercise `foo` that exists in
`problem-specifications` to a track, to create the docs and a starter
`.meta/config.json` file we can run:
$ configlet sync -uy -e foo --docs --filepaths --metadata
And to interactively create the `.meta/tests.toml` file:
$ configlet sync -u -e foo --tests
When updating exercise `.meta/config.json` files, configlet will
preserve a top-level key named `custom` and its value of any valid JSON
object. You can use this for track-specific feature flagging.
`sync` still performs a `git clone` of `problem-specifications` by
default. In the future, we intend for configlet to cache that repo - but
to skip cloning in the meantime, please continue to use the
`-o/--offline` and `-p/--prob-specs-dir` options. For example:
$ configlet sync -o -p /path/to/local/problem-specifications
For more details about the new `sync` functionality and more usage
examples, please see the `README.md` file.
We will soon add the `configlet fmt` command, for rewriting JSON files
on a track in a canonical form without syncing. You may recall that the
configlet for Exercism v2 had a `fmt` command with similar
functionality.
This commit also fixes a bad error message: previously
`configlet sync -e foo` would say that the `foo` exercise is up to date,
even if `foo` didn't exist on the track.
Closes: #298Closes: #179Fixes: #31
@@ -38,6 +45,89 @@ The `configlet lint` command is still under development. The list of currently i
38
45
39
46
## `configlet sync`
40
47
48
+
A Practice Exercise on an Exercism track is often implemented from a specification in the [`exercism/problem-specifications`](https://github.com/exercism/problem-specifications) repo.
49
+
50
+
Exercism deliberately requires that every exercise has its own copy of certain files (like `.docs/instructions.md`), even when that exercise exists in `problem-specifications`.
51
+
Therefore configlet has a `sync` command, which can check that such Practice Exercises on a track are in sync with that upstream source, and can update them when updates are available.
52
+
53
+
There are three kinds of data that can be updated from `problem-specifications`: documentation, metadata, and tests.
54
+
There is also one kind of data that can be populated from the track-level `config.json` file: filepaths in exercise config files.
55
+
56
+
We describe the checking and updating of these data kinds in individual sections below, but as a quick summary:
57
+
-`configlet sync` only operates on exercises that exist in the track-level `config.json` file. Therefore if you are implementing a new exercise on a track and want to add the initial files with `configlet sync`, please add the exercise to the track-level `config.json` file first. If the exercise is not yet ready to be user-facing, please set its `status` value to `wip`.
58
+
- A plain `configlet sync` makes no changes to the track, and checks every data kind for every exercise.
59
+
- To operate on a subset of data kinds, use some combination of the `--docs`, `--filepaths`, `--metadata`, and `--tests` options.
60
+
- To interactively update data on the track, use the `--update` option.
61
+
- To non-interactively update docs, filepaths, and metadata on the track, use `--update --yes`.
62
+
- To non-interactively include every unseen test for a given exercise, use e.g. `--update --tests include --exercise prime-factors`.
63
+
- To skip downloading the `problem-specifications` repo, add `--offline --prob-specs-dir /path/to/local/problem-specifications`
64
+
- Note that `configlet sync` tries to maintain the key order in exercise `.meta/config.json` files when updating. To write these files in a canonical form without syncing, please use the upcoming `configlet fmt` command. However, `configlet sync`_does_ add (possibly empty) required keys (`authors`, `files`, `blurb`) when they are missing. This is less "sync-like", but more ergonomic: when implementing a new exercise, you can use `sync` to create a starter `.meta/config.json` file.
65
+
-`configlet sync` removes keys that are not in the spec. Custom key/value pairs are still supported: they must be written inside a JSON object named `custom`.
66
+
- The exit code is 0 when all the seen data are synced when configlet exits, and 1 otherwise.
67
+
68
+
Note that in `configlet` releases `4.0.0-alpha.34` and earlier, the `sync` command operated only on tests.
69
+
70
+
### Docs
71
+
72
+
A Practice Exercise that is derived from the `problem-specifications` repo must have a `.docs/instructions.md` file (and possibly a `.docs/introduction.md` file too) containing the exercise documentation from `problem-specifications`.
73
+
74
+
To check every Practice Exercise on the track for available documentation updates (exiting with a non-zero exit code if at least one update is available):
75
+
76
+
```
77
+
$ configlet sync --docs
78
+
```
79
+
80
+
To interactively update the docs for every Practice Exercise, add the `--update` option (or `-u` for short):
81
+
82
+
```
83
+
$ configlet sync --docs --update
84
+
```
85
+
86
+
To non-interactively update the docs for every Practice Exercise, add the `--yes` option (or `-y` for short):
87
+
88
+
```
89
+
$ configlet sync --docs --update --yes
90
+
```
91
+
92
+
To operate on a single Practice Exercise, use the `--exercise` option (or `-e` for short).
93
+
For example, to non-interactively update the docs for the `prime-factors` exercise:
94
+
95
+
```
96
+
$ configlet sync --docs -uy -e prime-factors
97
+
```
98
+
99
+
### Metadata
100
+
101
+
Every exercise on a track must have a `.meta/config.json` file.
102
+
For a Practice Exercise that is derived from the `problem-specifications` repo, this file should contain the `blurb`, `source` and `source_url` key/value pairs that exist in the corresponding upstream `metadata.toml` file.
103
+
104
+
To check every Practice Exercise for available metadata updates (exiting with a non-zero exit code if at least one update is available):
105
+
106
+
```
107
+
$ configlet sync --metadata
108
+
```
109
+
110
+
To interactively update the metadata for every Practice Exercise, add the `--update` option (or `-u` for short):
111
+
112
+
```
113
+
$ configlet sync --metadata --update
114
+
```
115
+
116
+
To non-interactively update the metadata for every Practice Exercise, add the `--yes` option (or `-y` for short):
117
+
118
+
```
119
+
$ configlet sync --metadata --update --yes
120
+
```
121
+
122
+
To operate on a single Practice Exercise, use the `--exercise` option (or `-e` for short).
123
+
For example, to non-interactively update the metadata for the `prime-factors` exercise:
124
+
125
+
```
126
+
$ configlet sync --metadata -uy -e prime-factors
127
+
```
128
+
129
+
### Tests
130
+
41
131
If a track implements an exercise for which test data exists in the [problem-specifications repo](https://github.com/exercism/problem-specifications), the exercise _must_ contain a `.meta/tests.toml` file. The goal of the `tests.toml` file is to keep track of which tests are implemented by the exercise. Tests in this file are identified by their UUID and each test has a boolean value that indicates if it is implemented by that exercise.
42
132
43
133
A `tests.toml` file has this format:
@@ -68,11 +158,66 @@ comment = "excluded because we don't want to add error handling to the exercise"
68
158
69
159
In this case, the track has chosen to implement two of the three available tests. If a track uses a _test generator_ to generate an exercise's test suite, it _must_ use the contents of the `tests.toml` file to determine which tests to include in the generated test suite.
70
160
71
-
The `sync` command allows tracks to keep `tests.toml` files up to date. A plain `configlet sync` performs no changes, and just compares the tests specified in the `tests.toml` files against the tests that are defined in the exercise's canonical data - if there are tests defined only in the latter, it prints a summary and exits with a non-zero exit code.
161
+
To check every Practice Exercise `tests.toml` file for available tests updates (exiting with a non-zero exit code if there is at least one test case that appears in the exercise's canonical data, but not in the `tests.toml`):
162
+
163
+
```
164
+
$ configlet sync --tests
165
+
```
166
+
167
+
To interactively update the `tests.toml` file for every Practice Exercise, add the `--update` option:
168
+
169
+
```
170
+
$ configlet sync --tests --update
171
+
```
172
+
173
+
For each missing test, this prompts the user to choose whether to include/exclude/skip it, and updates the corresponding `tests.toml` file accordingly.
174
+
Configlet writes an exercise's `tests.toml` file when the user has finished making choices for that exercise.
175
+
This means that you can terminate configlet at a prompt (for example, by pressing Ctrl-C in the terminal) and only lose the syncing decisions for at most one exercise.
176
+
177
+
To non-interactively include every unseen test case, use `--tests include`. For example, to do so for an exercise named `prime-factors`:
178
+
179
+
```
180
+
$ configlet sync --tests include -u -e prime-factors
181
+
```
182
+
183
+
Remember to actually implement these tests on the track!
184
+
185
+
### Filepaths
186
+
187
+
Finally, the `sync` command also handles "syncing" from a source that isn't `problem-specifications` - the track-level `config.json` file.
188
+
Every Concept Exercise and Practice Exercise must have a `.meta/config.json` file with a `files` object that specifies the (relative) locations of the files that the exercise uses.
189
+
Such filepaths usually follow a simple pattern, and so configlet can populate the exercise-level values from patterns in the `files` key of the track-level `config.json` file.
190
+
191
+
To check that every Concept Exercise and Practice Exercise on the track has a fully populated `files` key (or at least one that cannot be populated from the track-level `files` key):
192
+
193
+
```
194
+
$ configlet sync --filepaths
195
+
```
196
+
197
+
(Note that `configlet lint` will also produce an error when an exercise has a missing/empty `files` key.)
198
+
199
+
To populate empty/missing values of the exercise-level `files` key for every Concept Exercise and Practice Exercise from the patterns in the track-level `files` key:
200
+
201
+
```
202
+
$ configlet sync --filepaths --update
203
+
```
204
+
205
+
To do this non-interactively and for a single exercise named `prime-factors`:
206
+
207
+
```
208
+
$ configlet sync --filepaths -uy -e prime-factors
209
+
```
72
210
73
-
To interactively update the `tests.toml` files, use `configlet sync --update`. For each missing test, this prompts the user to choose whether to include/exclude/skip it, and updates the corresponding `tests.toml` file accordingly.
211
+
### Using `sync` when adding a new exercise to a track
74
212
75
-
The `configlet sync` command replaces the functionality of the older `canonical_data_syncer` application.
213
+
The `sync` command is useful when adding a new exercise to a track. If you are adding a Practice Exercise named `foo` that exists in `problem-specifications`, one possible workflow is:
214
+
1. Manually add an entry to the track-level `config.json` file for the exercise `foo`. This makes the exercise visible to `configlet sync`.
215
+
1. Run `configlet sync --docs --filepaths --metadata -uy -e foo` to create the exercise's documentation, and a starter `.meta/config.json` file with populated `files`, `blurb`, and perhaps `source` and `source_url` values.
216
+
1. Edit the exercise `.meta/config.json` file as desired. For example, add yourself to the `authors` array.
217
+
1. Run `configlet sync --tests include -u -e foo` to create a `.meta/tests.toml` file with every test included.
218
+
1. View that `.meta/tests.toml` file, and add `include = false` to any test case that the exercise will not implement.
219
+
1. Implement the tests for the exercise to match those included in `.meta/tests.toml`.
0 commit comments