@ucm-kit/cli 0.1.39 → 0.1.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +241 -215
- package/aides/resolution-token.md +8 -1
- package/package.json +2 -2
- package/src/init.mjs +104 -43
- package/src/rapport-gitlab.mjs +2 -2
package/README.md
CHANGED
|
@@ -7,71 +7,199 @@ A **UCM contract** is a JSON file describing a UI component exactly as it exists
|
|
|
7
7
|
in Figma: its variants, its structure, its design tokens, its usage rules. It is
|
|
8
8
|
written by the [UCM Contract
|
|
9
9
|
Exporter](https://github.com/Vassili-g/UCM-Exporter) Figma plugin and committed
|
|
10
|
-
next to the component's code. This command reads those files and
|
|
11
|
-
they
|
|
10
|
+
next to the component's code. This command reads those files and reports
|
|
11
|
+
whether they are valid, whether their references resolve, and whether the code
|
|
12
|
+
matches them.
|
|
13
|
+
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
Requires Node 20 or later. At the root of the repository:
|
|
12
17
|
|
|
13
18
|
```sh
|
|
14
|
-
npx --yes @ucm-kit/cli@0.1.
|
|
15
|
-
npx --yes @ucm-kit/cli@0.1.39 check --report ci-report.md
|
|
19
|
+
npx --yes @ucm-kit/cli@0.1.41 init
|
|
16
20
|
```
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
1. Commit and push the files `init` wrote.
|
|
23
|
+
2. Make the check block merges: see [GitHub](#github) or [GitLab](#gitlab).
|
|
24
|
+
3. Give the repository URL to the designer, who enters it in the Figma plugin
|
|
25
|
+
with an access token.
|
|
26
|
+
|
|
27
|
+
To run the check locally:
|
|
21
28
|
|
|
22
|
-
|
|
29
|
+
```sh
|
|
30
|
+
npx --yes @ucm-kit/cli@0.1.41 check --report ci-report.md
|
|
31
|
+
```
|
|
23
32
|
|
|
24
|
-
`
|
|
25
|
-
|
|
26
|
-
only requirement is Node, and in CI `setup-node` provides it.
|
|
33
|
+
`--yes` skips the npx confirmation prompt. Pin an exact version, without `^`:
|
|
34
|
+
a range lets npx install a build this project has not tested.
|
|
27
35
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
**The repository does not have to be a Node project.** The workflow `ucm init`
|
|
37
|
+
writes needs no `package.json`, so an iOS or Android repository, or a plain
|
|
38
|
+
folder of contracts, can have its exports checked. When a `package-lock.json`
|
|
39
|
+
exists, the workflow runs `npm ci` first, so `ucm check` finds a stack adapter
|
|
40
|
+
the repository installed.
|
|
31
41
|
|
|
32
42
|
## Commands
|
|
33
43
|
|
|
34
44
|
| Command | What it does |
|
|
35
45
|
|---|---|
|
|
36
|
-
| `ucm init` | Installs what the repository is missing, never overwriting a file that already exists |
|
|
37
|
-
| `ucm check` | Checks every contract and renders the report |
|
|
46
|
+
| [`ucm init`](#ucm-init) | Installs what the repository is missing, never overwriting a file that already exists |
|
|
47
|
+
| [`ucm check`](#ucm-check) | Checks every contract and renders the report |
|
|
38
48
|
| `ucm icons` | Lists the icons the contracts ask this repository to draw |
|
|
39
|
-
| `ucm tokens css --out <file>` | Writes the CSS stylesheet of the tokens and their modes |
|
|
40
|
-
| `ucm aides [<aide>]` | Lists the implementation guides, or prints one |
|
|
41
|
-
| `ucm guide <contract>` | Prints what an agent reads before implementing that contract |
|
|
42
|
-
| `ucm rapport-gitlab` | Posts the report as a note on a GitLab merge request |
|
|
43
|
-
| `ucm --help` | Prints
|
|
49
|
+
| [`ucm tokens css --out <file>`](#the-token-stylesheet) | Writes the CSS stylesheet of the tokens and their modes |
|
|
50
|
+
| [`ucm aides [<aide>]`](#implementation-guides) | Lists the implementation guides, or prints one |
|
|
51
|
+
| [`ucm guide <contract>`](#the-guide-of-a-contract) | Prints what an agent reads before implementing that contract |
|
|
52
|
+
| [`ucm rapport-gitlab`](#gitlab) | Posts the report as a note on a GitLab merge request |
|
|
53
|
+
| `ucm --help` | Prints every command and option |
|
|
44
54
|
|
|
45
|
-
|
|
55
|
+
Every command exits with the same codes:
|
|
46
56
|
|
|
47
|
-
|
|
|
57
|
+
| Code | Meaning |
|
|
48
58
|
|---|---|
|
|
49
|
-
|
|
|
50
|
-
|
|
|
51
|
-
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
`
|
|
60
|
-
|
|
61
|
-
`--implementation`
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
| `0` | The command did what it was asked |
|
|
60
|
+
| `1` | Checks failed |
|
|
61
|
+
| `2` | The invocation or the configuration is at fault |
|
|
62
|
+
|
|
63
|
+
A faulty invocation never exits with `1`, so it cannot pass for failed checks.
|
|
64
|
+
|
|
65
|
+
## `ucm init`
|
|
66
|
+
|
|
67
|
+
| Option | Default | Effect |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| `--components <dir>` | `components` | The folder the contracts are stored under |
|
|
70
|
+
| `--tokens <dir>` | the repository root | The folder that holds `tokens.json` |
|
|
71
|
+
| `--implementation <pattern>` | `{dir}/{id}.tsx` | The file that implements a contract: `{dir}` is the contract's folder, `{id}` its identifier |
|
|
72
|
+
| `--forge github\|gitlab` | detected, see below | The forge whose CI is written |
|
|
73
|
+
| `--sans-agents` | off | Writes neither the agent relays, nor `.ucm/conventions.md`, nor the templates |
|
|
74
|
+
|
|
75
|
+
`--tokens` takes a folder, and `ucm.config.json` stores the file path
|
|
76
|
+
`<dir>/tokens.json`. `--implementation` must contain `{id}`; without it, every
|
|
77
|
+
contract would resolve to the same file. A repository that does not write React
|
|
78
|
+
states its own extension:
|
|
65
79
|
|
|
66
80
|
```sh
|
|
67
|
-
npx --yes @ucm-kit/cli@0.1.
|
|
81
|
+
npx --yes @ucm-kit/cli@0.1.41 init --components Sources/DesignSystem --implementation '{dir}/{id}.swift'
|
|
68
82
|
```
|
|
69
83
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
84
|
+
The three path options act only on a first install. `ucm init` never overwrites
|
|
85
|
+
an existing `ucm.config.json`, and says so when options were passed. To change
|
|
86
|
+
a path later, edit that file.
|
|
87
|
+
|
|
88
|
+
Without `--forge`, the host of the `origin` remote decides, then the presence of
|
|
89
|
+
`.gitlab-ci.yml`, and GitHub otherwise. The command names the forge and the
|
|
90
|
+
signal it followed.
|
|
91
|
+
|
|
92
|
+
### What it writes
|
|
93
|
+
|
|
94
|
+
Five control files, then what an agent needs, unless `--sans-agents` is passed.
|
|
95
|
+
The command explains each file as it writes it. An existing file is kept as it
|
|
96
|
+
is, and the command names what it left alone.
|
|
97
|
+
|
|
98
|
+
| File | Why |
|
|
99
|
+
|---|---|
|
|
100
|
+
| `ucm.config.json` | Where the contracts, the tokens and the implementations live |
|
|
101
|
+
| `.gitattributes` | Keeps contracts and tokens in LF, so a re-export from a Windows machine does not produce a whole-file diff |
|
|
102
|
+
| `.vscode/settings.json` | Binds `*.contract.json` to the JSON Schema of the installed package, so the editor validates as you read |
|
|
103
|
+
| `.gitignore` | Keeps `ci-report.md` out of the repository; it is regenerated on every run |
|
|
104
|
+
| `.github/workflows/ucm.yml` | Runs the check on every pull request and posts the report as a comment. On GitLab, `.gitlab/ucm.gitlab-ci.yml` and `.gitlab-ci.yml` replace it |
|
|
105
|
+
| `.agents/skills/ucm-implementer/SKILL.md`, `.claude/skills/ucm-implementer/SKILL.md` | Two identical relays: an agent loads one before writing a component, and runs `ucm guide` at the pinned version |
|
|
106
|
+
| `.ucm/conventions.md` | The repository's stack and writings, with its instructions in a comment |
|
|
107
|
+
| `.ucm/gabarits/` | The templates of the installed stack adapter, when it publishes some |
|
|
108
|
+
|
|
109
|
+
The workflow is yours once written, and `ucm init` never rewrites it.
|
|
110
|
+
|
|
111
|
+
The command then prints the lines it does not write, each with its file:
|
|
112
|
+
`@ucm-kit/cli` in `devDependencies`, `ucm tokens css` at the head of the `dev`
|
|
113
|
+
and `build` scripts, the import of the generated stylesheet, and the optional
|
|
114
|
+
`modes` section when `tokens.json` declares axes. A line already present is not
|
|
115
|
+
printed. An installed adapter that fails to load is reported, and the rest is
|
|
116
|
+
installed.
|
|
117
|
+
|
|
118
|
+
### `ucm.config.json`
|
|
119
|
+
|
|
120
|
+
**This file is the only authority on where an export lands.** The Figma plugin
|
|
121
|
+
reads it before publishing, and `ucm check` reads it before looking for
|
|
122
|
+
contracts. Without the file, the defaults below apply on both sides. A file that
|
|
123
|
+
exists but is malformed is refused on both sides.
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"components": "components",
|
|
128
|
+
"tokens": "tokens.json",
|
|
129
|
+
"implementation": "{dir}/{id}.tsx"
|
|
130
|
+
}
|
|
131
|
+
```
|
|
73
132
|
|
|
74
|
-
|
|
133
|
+
Each path is relative to the repository root and written with `/`. A path that
|
|
134
|
+
starts with `/` or a drive letter, contains `\`, or has an empty, `.` or `..`
|
|
135
|
+
segment is refused: the plugin would write outside the repository with the
|
|
136
|
+
designer's token, and the check would read outside it.
|
|
137
|
+
|
|
138
|
+
The file holds no version number. The installed package decides which contract
|
|
139
|
+
versions it reads.
|
|
140
|
+
|
|
141
|
+
### GitHub
|
|
142
|
+
|
|
143
|
+
The workflow runs on every pull request and on every push to `main`. If the
|
|
144
|
+
default branch has another name, change it in `.github/workflows/ucm.yml`.
|
|
145
|
+
|
|
146
|
+
Its `contrats` job runs the check with read-only permissions. Its `commentaire`
|
|
147
|
+
job runs no code from the repository: it receives the report as an artifact
|
|
148
|
+
and posts it, replacing its previous comment.
|
|
149
|
+
|
|
150
|
+
A red check blocks a merge only when the base branch requires the `contrats`
|
|
151
|
+
status check, in a branch protection rule or a ruleset. GitHub offers these on
|
|
152
|
+
public repositories and on paid plans. Without that setting, the report
|
|
153
|
+
announces a blocked merge that is not blocked.
|
|
154
|
+
|
|
155
|
+
### GitLab
|
|
156
|
+
|
|
157
|
+
`init --forge gitlab` writes `.gitlab/ucm.gitlab-ci.yml`, two jobs with no
|
|
158
|
+
global key, so the project's other jobs keep their rules. `ucm` runs the check
|
|
159
|
+
in merge request pipelines and on the default branch; `ucm-rapport` posts the
|
|
160
|
+
note in merge request pipelines. Both take the default `test` stage. A new
|
|
161
|
+
`.gitlab-ci.yml` includes the file; an existing one is left alone, and the
|
|
162
|
+
command prints the `include` line to add. It also prints three settings it
|
|
163
|
+
cannot make:
|
|
164
|
+
|
|
165
|
+
- create the CI/CD variable `UCM_GITLAB_TOKEN`, masked and not protected,
|
|
166
|
+
holding an `api` token of an account with the Reporter role on this project
|
|
167
|
+
only: a service account's personal token, or a project access token where
|
|
168
|
+
the GitLab plan offers one. Export branches are not protected, so a
|
|
169
|
+
protected variable would be empty there. Every pipeline of every branch reads
|
|
170
|
+
an unprotected variable, and any user who can push a branch can print it: the
|
|
171
|
+
Reporter role limits that token to reading and commenting;
|
|
172
|
+
- tick "Pipelines must succeed" in the merge request settings. Without it, a red
|
|
173
|
+
report does not block the merge it says is blocked;
|
|
174
|
+
- keep `test` in `stages:` when `.gitlab-ci.yml` declares them: GitLab refuses a
|
|
175
|
+
pipeline whose job names a missing stage.
|
|
176
|
+
|
|
177
|
+
`ucm` unsets `UCM_GITLAB_TOKEN` before `npm ci`, so install scripts do not
|
|
178
|
+
inherit it on executors that set variables in the job script. `ucm-rapport`
|
|
179
|
+
runs no code from the repository: it clones nothing, receives `ci-report.md`
|
|
180
|
+
as an artifact, disables install scripts, and runs `npx` from an empty
|
|
181
|
+
directory. It writes a minimal report when the check stopped before writing
|
|
182
|
+
one, then posts the report:
|
|
183
|
+
|
|
184
|
+
```sh
|
|
185
|
+
npx --yes @ucm-kit/cli@0.1.41 rapport-gitlab --projet "$CI_PROJECT_ID" --merge-request "$CI_MERGE_REQUEST_IID" --fichier "$CI_PROJECT_DIR/ci-report.md" --api "$CI_API_V4_URL"
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
| Option | Effect |
|
|
189
|
+
|---|---|
|
|
190
|
+
| `--projet <id>` | The GitLab project, by identifier or path |
|
|
191
|
+
| `--merge-request <iid>` | The merge request number within that project |
|
|
192
|
+
| `--fichier <path>` | The report written by `ucm check --report` |
|
|
193
|
+
| `--api <url>` | The GitLab API; `https://gitlab.com/api/v4` by default |
|
|
194
|
+
|
|
195
|
+
The command reads the token from `UCM_GITLAB_TOKEN` and never prints it. It
|
|
196
|
+
replaces the note that the token's account wrote with the `<!-- ucm-rapport -->`
|
|
197
|
+
marker, and creates one otherwise. Without the variable it says so and exits
|
|
198
|
+
with `0`: the report stays in the job artifacts. A refused token exits with `1`
|
|
199
|
+
and names the fix. The job allows failure, so a refused token leaves the
|
|
200
|
+
pipeline the colour of the check.
|
|
201
|
+
|
|
202
|
+
## `ucm check`
|
|
75
203
|
|
|
76
204
|
| Option | Effect |
|
|
77
205
|
|---|---|
|
|
@@ -82,15 +210,57 @@ The report stops before 65,536 characters, the size of a GitHub comment, and
|
|
|
82
210
|
says so in its last line. The verdict opens the report and is never cut; the
|
|
83
211
|
terminal output keeps every detail.
|
|
84
212
|
|
|
85
|
-
###
|
|
213
|
+
### What the report says
|
|
86
214
|
|
|
87
|
-
|
|
215
|
+
The report is written for the **designer** who validates the export. Every
|
|
216
|
+
reason a merge is refused appears in it, so the designer never opens a CI log.
|
|
217
|
+
|
|
218
|
+
Six checks run on each contract. **A check blocks when the file on disk cannot
|
|
219
|
+
be read as it stands**, and warns when the read succeeds and the gap points at
|
|
220
|
+
the code or at the token file.
|
|
221
|
+
|
|
222
|
+
| Check | Verdict |
|
|
88
223
|
|---|---|
|
|
89
|
-
|
|
|
90
|
-
|
|
|
91
|
-
|
|
|
224
|
+
| The contract is readable and complete | Blocks |
|
|
225
|
+
| This repository can read that contract version | Blocks |
|
|
226
|
+
| Composition: every nested component has its own contract, the lists agree, no cycles | Blocks |
|
|
227
|
+
| Typography tokens have the expected type | Blocks |
|
|
228
|
+
| Every `{token.path}` cited exists in the token file | Warns, but a missing or unreadable token file blocks |
|
|
229
|
+
| The code exposes the props the contract declares, with a stack adapter installed | Warns |
|
|
92
230
|
|
|
93
|
-
|
|
231
|
+
The direction of a version gap names who fixes it. A contract that is too old
|
|
232
|
+
is re-exported by the designer. A contract that is too new needs this package
|
|
233
|
+
upgraded by a developer.
|
|
234
|
+
|
|
235
|
+
Before any contract, the check reads the format version at the root of the
|
|
236
|
+
token file. A version newer than this package reads blocks the merge, and a
|
|
237
|
+
developer upgrades the UCM packages. A mark that is not a version blocks too,
|
|
238
|
+
and the designer runs the token export again. Both apply even in a repository
|
|
239
|
+
with no contract yet.
|
|
240
|
+
|
|
241
|
+
A gap with the code warns: a developer closes it, and the merge goes through. A
|
|
242
|
+
token removed from the design system warns too, so an older contract does not
|
|
243
|
+
hold back the tokens. A contract may land before the code that implements it.
|
|
244
|
+
|
|
245
|
+
A repository with no contract passes. Right after `ucm init`, `ucm check`
|
|
246
|
+
returns `0` and reports the next step. From the first contract on, a missing
|
|
247
|
+
token file blocks the merge.
|
|
248
|
+
|
|
249
|
+
The report also relays the warnings the export wrote into the contract, and the
|
|
250
|
+
verdict of the repository's own tests when an orchestrator passes it in through
|
|
251
|
+
the `UCM_ECHECS_DE_TESTS` environment variable, a JSON object with `echoue` and
|
|
252
|
+
`echecs`.
|
|
253
|
+
|
|
254
|
+
### Optional stack adapters
|
|
255
|
+
|
|
256
|
+
The first five checks read contracts and tokens only, whatever the repository
|
|
257
|
+
is written in. Comparing a contract to real code needs a stack adapter.
|
|
258
|
+
|
|
259
|
+
`ucm check` discovers an adapter installed **by the repository**, resolving from
|
|
260
|
+
the checked root rather than from the npx cache. Install
|
|
261
|
+
[`@ucm-kit/adapter-typescript`](https://www.npmjs.com/package/@ucm-kit/adapter-typescript)
|
|
262
|
+
for prop and composition parity in TypeScript projects. Without an adapter, the
|
|
263
|
+
report says the implementation was not read, and never that it is conformant.
|
|
94
264
|
|
|
95
265
|
## The token stylesheet
|
|
96
266
|
|
|
@@ -103,10 +273,16 @@ names and writes one custom property per token. Each property is named by
|
|
|
103
273
|
npx --no-install ucm tokens css --out src/generated/tokens.css
|
|
104
274
|
```
|
|
105
275
|
|
|
106
|
-
|
|
276
|
+
`--no-install` runs the version pinned in `devDependencies`. Run the command
|
|
277
|
+
before `dev` and `build`, in place of any other generator of the same
|
|
107
278
|
stylesheet, and import the generated file once, from the application's CSS
|
|
108
279
|
entry point.
|
|
109
280
|
|
|
281
|
+
| Option | Effect |
|
|
282
|
+
|---|---|
|
|
283
|
+
| `--out <file>` | The stylesheet to write. Required |
|
|
284
|
+
| `--sans-modes` | Writes the default value of every token, for a token file exported before axes were declared |
|
|
285
|
+
|
|
110
286
|
**Modes are attributes.** Each axis of `tokens.json`, one per Figma collection
|
|
111
287
|
with several modes, is selected by an HTML attribute on any element: its
|
|
112
288
|
subtree takes that mode, and removing the attribute gives back the mode
|
|
@@ -121,7 +297,7 @@ the command prints it. A repository names another one in `ucm.config.json`:
|
|
|
121
297
|
```
|
|
122
298
|
|
|
123
299
|
Two axes with the same set of modes may share an attribute. A component reads
|
|
124
|
-
tokens and never declares
|
|
300
|
+
tokens and never declares an attribute, so any ancestor can switch its mode.
|
|
125
301
|
|
|
126
302
|
A collection that Figma extended collections override, an experimental reading,
|
|
127
303
|
adds the axis `<axis>-extensions`: its attribute takes `base` for the collection
|
|
@@ -136,11 +312,11 @@ correct stylesheet: an alias to a missing token, two token paths that give the
|
|
|
136
312
|
same property, two extension names that give the same CSS name, an alias cycle
|
|
137
313
|
that a context can reach, an alias whose type changes in a mode or an extension,
|
|
138
314
|
or modes the export did not attach to an axis. A key of `modes` that names no
|
|
139
|
-
axis of the token file exits with `2`. The previous
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
315
|
+
axis of the token file exits with `2`. The previous stylesheet stays in place. A
|
|
316
|
+
token file exported before axes were declared is refused with that reason, and
|
|
317
|
+
`--sans-modes` applies until the tokens are exported again. Without a token
|
|
318
|
+
file, the command writes an empty stylesheet when no contract cites a token, and
|
|
319
|
+
refuses otherwise.
|
|
144
320
|
|
|
145
321
|
## Implementation guides
|
|
146
322
|
|
|
@@ -177,15 +353,17 @@ guide. `ecritures-par-defaut: non` on the first line prints meanings only, for a
|
|
|
177
353
|
repository that writes no CSS.
|
|
178
354
|
|
|
179
355
|
`ucm aides <aide> --personnaliser [<path>]` appends that guide's section, with
|
|
180
|
-
its default writing to edit, to the
|
|
181
|
-
section, and the command refuses it. The marker records the
|
|
182
|
-
fingerprint of the copied writing: when the default writing
|
|
183
|
-
and `ucm guide` name the section to read again, and a
|
|
184
|
-
fingerprint is named as well. An existing section is never
|
|
356
|
+
its default writing to edit, to the conventions file closest to `<path>`.
|
|
357
|
+
`composant` has no section, and the command refuses it. The marker records the
|
|
358
|
+
version and a fingerprint of the copied writing: when the default writing
|
|
359
|
+
changes, `ucm aides` and `ucm guide` name the section to read again, and a
|
|
360
|
+
marker without a fingerprint is named as well. An existing section is never
|
|
361
|
+
overwritten.
|
|
185
362
|
|
|
186
363
|
## The guide of a contract
|
|
187
364
|
|
|
188
|
-
`ucm guide <contract> [--out <file>]` prints, in one Markdown document
|
|
365
|
+
`ucm guide <contract> [--out <file>]` prints, in one Markdown document, or
|
|
366
|
+
writes to `<file>`:
|
|
189
367
|
|
|
190
368
|
1. what to read again first: conventions anomalies, copied sections whose
|
|
191
369
|
default writing changed, and `@ucm-kit/cli` pins that differ between the two
|
|
@@ -207,158 +385,6 @@ The command exits with `1` when the composition graph or the token file is
|
|
|
207
385
|
inconsistent, and with `2` for an invocation, a configuration or a contract it
|
|
208
386
|
cannot read, a contract version outside its reading window included.
|
|
209
387
|
|
|
210
|
-
## What `ucm init` writes
|
|
211
|
-
|
|
212
|
-
Five control files, then what an agent needs, unless `--sans-agents` is passed.
|
|
213
|
-
The command explains each one as it writes it. An existing file is kept as it
|
|
214
|
-
is, and the command names what it left alone.
|
|
215
|
-
|
|
216
|
-
| File | Why |
|
|
217
|
-
|---|---|
|
|
218
|
-
| `ucm.config.json` | Where the contracts, the tokens and the implementations live |
|
|
219
|
-
| `.gitattributes` | Keeps contracts and tokens in LF, so a re-export from a Windows machine does not produce a whole-file diff |
|
|
220
|
-
| `.vscode/settings.json` | Binds `*.contract.json` to the JSON Schema of the installed package, so the editor validates as you read |
|
|
221
|
-
| `.gitignore` | Keeps `ci-report.md` out of the repository; it is regenerated on every run and describes only that run |
|
|
222
|
-
| `.github/workflows/ucm.yml` | Runs the check on every pull request and posts the report as a comment |
|
|
223
|
-
| `.agents/skills/ucm-implementer/SKILL.md`, `.claude/skills/ucm-implementer/SKILL.md` | Two identical relays: an agent loads one before writing a component, and runs `ucm guide` at the pinned version |
|
|
224
|
-
| `.ucm/conventions.md` | The repository's stack and writings, with its instructions in a comment |
|
|
225
|
-
| `.ucm/gabarits/` | The templates of the installed stack adapter, when it publishes some |
|
|
226
|
-
|
|
227
|
-
The workflow is yours once written. It will never be overwritten. On GitLab,
|
|
228
|
-
`.gitlab/ucm.gitlab-ci.yml` and `.gitlab-ci.yml` replace the GitHub workflow.
|
|
229
|
-
|
|
230
|
-
An installed adapter that fails to load is reported, and the rest is
|
|
231
|
-
installed. The command then prints the lines it does not write, each with its
|
|
232
|
-
file: `@ucm-kit/cli` in `devDependencies`, `ucm tokens css` at the head of the
|
|
233
|
-
`dev` and `build` scripts, the import of the generated stylesheet, and the
|
|
234
|
-
optional `modes` section when `tokens.json` declares axes. A line already present
|
|
235
|
-
is not printed.
|
|
236
|
-
|
|
237
|
-
### `ucm.config.json`
|
|
238
|
-
|
|
239
|
-
Three paths. **This file is the only authority on where an export lands.** The
|
|
240
|
-
Figma plugin reads it before publishing, and `ucm check` reads it before looking
|
|
241
|
-
for contracts. A repository that arranges things differently says so here, once,
|
|
242
|
-
and both sides follow.
|
|
243
|
-
|
|
244
|
-
Its absence is the nominal case: the defaults below apply. A repository with a
|
|
245
|
-
single `components/` folder works without writing a line. A file that exists but
|
|
246
|
-
is malformed is refused on both sides.
|
|
247
|
-
|
|
248
|
-
```json
|
|
249
|
-
{
|
|
250
|
-
"components": "components",
|
|
251
|
-
"tokens": "tokens.json",
|
|
252
|
-
"implementation": "{dir}/{id}.tsx"
|
|
253
|
-
}
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
`implementation` is a pattern with two tokens, `{dir}` for the contract's folder
|
|
257
|
-
and `{id}` for its identifier. Replace it with the pattern your repository uses.
|
|
258
|
-
|
|
259
|
-
No version number goes in this file. Which contract versions can be read belongs
|
|
260
|
-
to the installed package, and repeating it here would create a second authority
|
|
261
|
-
that drifts on the first update.
|
|
262
|
-
|
|
263
|
-
## What the report says
|
|
264
|
-
|
|
265
|
-
The report is written for the **designer** who validates the export. It requires
|
|
266
|
-
no CI log. Every reason a pull request is refused appears in it.
|
|
267
|
-
|
|
268
|
-
Six checks run on each contract. Four block a merge, two only warn: **a check
|
|
269
|
-
blocks when the file on disk cannot be read as it stands**, and warns when the
|
|
270
|
-
read succeeds and the gap points at the code or at the token file.
|
|
271
|
-
|
|
272
|
-
The direction of the gap names who fixes it. The CI never reads who opened the
|
|
273
|
-
pull request. A contract that is too old is re-exported; a contract that is too
|
|
274
|
-
new needs this package upgraded, which no re-export replaces.
|
|
275
|
-
[`@ucm-kit/core`](https://www.npmjs.com/package/@ucm-kit/core) names both
|
|
276
|
-
directions.
|
|
277
|
-
|
|
278
|
-
| Check | Verdict |
|
|
279
|
-
|---|---|
|
|
280
|
-
| The contract is readable and complete | Blocks |
|
|
281
|
-
| This repository can read that contract version | Blocks |
|
|
282
|
-
| Composition: every nested component has its own contract, the lists agree, no cycles | Blocks |
|
|
283
|
-
| Typography tokens have the expected type | Blocks |
|
|
284
|
-
| Every `{token.path}` cited exists in the token file | Warns, but a missing or unreadable token file blocks |
|
|
285
|
-
| The code exposes the props the contract declares, with a stack adapter installed | Warns |
|
|
286
|
-
|
|
287
|
-
Before any contract, the check reads the format version at the root of the
|
|
288
|
-
token file. A version newer than this package reads, or a mark that is not a
|
|
289
|
-
version, blocks the merge, even in a repository with no contract yet. A
|
|
290
|
-
developer upgrades the UCM packages for the first case, and the designer runs
|
|
291
|
-
the token export again for the second.
|
|
292
|
-
[`@ucm-kit/core`](https://www.npmjs.com/package/@ucm-kit/core) lists the four
|
|
293
|
-
states.
|
|
294
|
-
|
|
295
|
-
A gap with the code needs a developer, so it warns and lets the merge through. A
|
|
296
|
-
token removed from the design system does too: tokens are the source of truth,
|
|
297
|
-
so an older contract does not hold back their evolution. A token file that is
|
|
298
|
-
absent or unreadable is another matter: no reference can be resolved at all, so
|
|
299
|
-
the check gives up rather than reporting every path as missing.
|
|
300
|
-
|
|
301
|
-
A contract may land before the code that implements it. A missing implementation
|
|
302
|
-
is an allowed stage of the work.
|
|
303
|
-
|
|
304
|
-
**So is a repository with no contract at all.** Right after `ucm init` nothing
|
|
305
|
-
has been exported: there is no token file, and usually no contract folder. From
|
|
306
|
-
`0.1.10` on, `ucm check` returns 0 there and reports what to do next. The number
|
|
307
|
-
of contracts decides: with one or more, a missing token file blocks the merge
|
|
308
|
-
again, because those contracts cite tokens that cannot be resolved.
|
|
309
|
-
|
|
310
|
-
The report also relays two things it does not measure itself: the warnings the
|
|
311
|
-
export wrote into the contract, and the verdict of the repository's own tests
|
|
312
|
-
when an orchestrator passes it in through `UCM_ECHECS_DE_TESTS`.
|
|
313
|
-
|
|
314
|
-
## GitLab
|
|
315
|
-
|
|
316
|
-
`ucm init` writes the CI of one forge. `--forge` decides; without it, the host
|
|
317
|
-
of the `origin` remote does, then the presence of `.gitlab-ci.yml`, and GitHub
|
|
318
|
-
otherwise. The command names the forge and the signal it followed.
|
|
319
|
-
|
|
320
|
-
For GitLab it writes `.gitlab/ucm.gitlab-ci.yml`, a single `ucm` job with no
|
|
321
|
-
global key, so the project's other jobs keep their rules. The job runs in merge
|
|
322
|
-
request pipelines and on the default branch, in the default `test` stage. A
|
|
323
|
-
new `.gitlab-ci.yml` includes it; an existing one is left alone, and the
|
|
324
|
-
command prints the `include` line to add. It also prints three settings it
|
|
325
|
-
cannot make:
|
|
326
|
-
|
|
327
|
-
- create the CI/CD variable `UCM_GITLAB_TOKEN`, masked and not protected,
|
|
328
|
-
holding a token with the `api` scope. Export branches are not protected, so a
|
|
329
|
-
protected variable would be empty there;
|
|
330
|
-
- tick "Pipelines must succeed" in the merge request settings. Without it, a red
|
|
331
|
-
report does not block the merge it says is blocked;
|
|
332
|
-
- keep `test` in `stages:` when `.gitlab-ci.yml` declares them: GitLab refuses a
|
|
333
|
-
pipeline whose job names a missing stage.
|
|
334
|
-
|
|
335
|
-
`after_script` writes a minimal report when the check stopped before writing
|
|
336
|
-
one, then posts the report:
|
|
337
|
-
|
|
338
|
-
```sh
|
|
339
|
-
npx --yes @ucm-kit/cli@0.1.39 rapport-gitlab --projet "$CI_PROJECT_ID" --merge-request "$CI_MERGE_REQUEST_IID" --fichier ci-report.md --api "$CI_API_V4_URL"
|
|
340
|
-
```
|
|
341
|
-
|
|
342
|
-
The command reads the token from `UCM_GITLAB_TOKEN` and never prints it. It
|
|
343
|
-
replaces the note that the token's account wrote with the `<!-- ucm-rapport -->`
|
|
344
|
-
marker, across every page of notes, and creates one otherwise. Without the
|
|
345
|
-
variable it says so and exits with `0`: the report stays in the job artifacts.
|
|
346
|
-
A refused token exits with `1` and names the fix. `--api` defaults to
|
|
347
|
-
`https://gitlab.com/api/v4`.
|
|
348
|
-
|
|
349
|
-
## Optional stack adapters
|
|
350
|
-
|
|
351
|
-
The first five checks above read contracts and tokens only, so they work
|
|
352
|
-
whatever the repository is written in. Comparing a contract to real code needs
|
|
353
|
-
to read that code, which is a stack adapter's job.
|
|
354
|
-
|
|
355
|
-
`ucm check` discovers an adapter installed **by the repository**, resolving from
|
|
356
|
-
the checked root rather than from the npx cache. Install
|
|
357
|
-
[`@ucm-kit/adapter-typescript`](https://www.npmjs.com/package/@ucm-kit/adapter-typescript)
|
|
358
|
-
to add static prop and composition parity for TypeScript projects. Without an
|
|
359
|
-
adapter, the report says the implementation was not read, and never that it is
|
|
360
|
-
conformant.
|
|
361
|
-
|
|
362
388
|
## Status
|
|
363
389
|
|
|
364
390
|
**0.x, the public surface is not frozen.** Pin an exact version.
|
|
@@ -12,7 +12,14 @@ pistes de grille sont les seules valeurs brutes prévues. Les références d'un
|
|
|
12
12
|
contrat se relèvent partout sauf dans `samples` et `meta`, dont une chaîne en
|
|
13
13
|
forme de référence est un texte.
|
|
14
14
|
|
|
15
|
+
Quand ce moyen est une propriété personnalisée CSS, son nom est celui que
|
|
16
|
+
`tokenCssVariable` donne, et la feuille d'`ucm tokens css` le déclare. Une
|
|
17
|
+
projection recopiée tient la même règle : l'accent tombe et la lettre reste.
|
|
18
|
+
`café.fond` donne `--cafe-fond` ; une copie qui remplace tout caractère non
|
|
19
|
+
ASCII vise `--caf-fond`, une variable absente, sans erreur.
|
|
20
|
+
|
|
15
21
|
## Preuve
|
|
16
22
|
|
|
17
23
|
`ucm check`, section tokens. Relecture : aucune valeur littérale à la place
|
|
18
|
-
d'une référence
|
|
24
|
+
d'une référence, et aucune projection de nom qui s'écarte de
|
|
25
|
+
`tokenCssVariable`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ucm-kit/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.41",
|
|
4
4
|
"description": "La ligne de commande UCM : initialiser un repository, lister ce qu'il doit couvrir.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"test": "node scripts/run-tests.cjs"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ucm-kit/core": "0.1.
|
|
32
|
+
"@ucm-kit/core": "0.1.37"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"yaml": "^2.9.1"
|
package/src/init.mjs
CHANGED
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
CONFIGURATION_PAR_DEFAUT,
|
|
32
32
|
MOTIF_IMPLEMENTATION_PAR_DEFAUT,
|
|
33
33
|
NOM_CONFIGURATION,
|
|
34
|
+
estCheminDuRepository,
|
|
34
35
|
} from "@ucm-kit/core/format";
|
|
35
36
|
import { lireConfiguration } from "@ucm-kit/core/lecteurs";
|
|
36
37
|
|
|
@@ -51,18 +52,14 @@ const OPTIONS_DE_DOSSIER = { "--components": "components", "--tokens": "tokens"
|
|
|
51
52
|
const NOM_FICHIER_TOKENS = CONFIGURATION_PAR_DEFAUT.tokens.split("/").pop();
|
|
52
53
|
|
|
53
54
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* est une autre question, et c'est celle-là qui se pose ici.
|
|
55
|
+
* Le chemin tapé, écrit comme la grammaire du kit l'accepte, ou `null`.
|
|
56
|
+
*
|
|
57
|
+
* Le clavier tolère `\` et des barres obliques de bord ; le fichier écrit n'en
|
|
58
|
+
* garde aucune, et la grammaire décide du reste.
|
|
59
59
|
*/
|
|
60
60
|
function cheminAcceptable(valeur) {
|
|
61
61
|
const normalise = valeur.trim().replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
62
|
-
|
|
63
|
-
const segments = normalise.split("/");
|
|
64
|
-
if (segments.some((segment) => !segment || segment === "." || segment === "..")) return null;
|
|
65
|
-
return segments.join("/");
|
|
62
|
+
return estCheminDuRepository(normalise) ? normalise : null;
|
|
66
63
|
}
|
|
67
64
|
|
|
68
65
|
/**
|
|
@@ -407,6 +404,14 @@ function lignesRestantes(racine, version, configuration) {
|
|
|
407
404
|
* « le rapport manque ». Le premier décrit sa chaîne de construction, qu'un
|
|
408
405
|
* repo Swift n'a pas. Le second est universel : une pull request refusée sans
|
|
409
406
|
* un mot laisse le designer sans recours.
|
|
407
|
+
*
|
|
408
|
+
* **Le job qui exécute le code du repository n'écrit nulle part.** `npm ci`
|
|
409
|
+
* lance les scripts d'installation des dépendances, et un paquet compromis
|
|
410
|
+
* lirait le jeton du job, même hors de l'environnement. Le commentaire part
|
|
411
|
+
* donc d'un second job, sans checkout ni npm, qui reçoit le rapport en
|
|
412
|
+
* artefact. L'auteur d'une branche du repository peut réécrire ce fichier :
|
|
413
|
+
* la séparation ne borne que ce qu'une dépendance obtient. Une fourche reçoit
|
|
414
|
+
* de GitHub un jeton en lecture seule, et son commentaire échoue.
|
|
410
415
|
*/
|
|
411
416
|
function workflow(version) {
|
|
412
417
|
const commande = `npx --yes @ucm-kit/cli@${version} check --report ci-report.md`;
|
|
@@ -417,6 +422,10 @@ function workflow(version) {
|
|
|
417
422
|
"# designer qui valide un export : il n'ouvre pas les logs de la CI. Toute",
|
|
418
423
|
"# étape qui refuse une fusion doit donc lui laisser un message.",
|
|
419
424
|
"#",
|
|
425
|
+
"# Le job `contrats` exécute le code du repository et ses dépendances : il",
|
|
426
|
+
"# ne porte aucun droit d'écriture. Seul `commentaire`, qui n'exécute rien",
|
|
427
|
+
"# du repository, écrit sur la pull request.",
|
|
428
|
+
"#",
|
|
420
429
|
"# Écrit par `ucm init`. Adaptez-le : il ne sera jamais réécrit par-dessus.",
|
|
421
430
|
"name: ucm",
|
|
422
431
|
"",
|
|
@@ -425,17 +434,15 @@ function workflow(version) {
|
|
|
425
434
|
" branches: [main]",
|
|
426
435
|
" pull_request:",
|
|
427
436
|
"",
|
|
428
|
-
"# Nécessaire pour publier le diagnostic en commentaire de pull request.",
|
|
429
437
|
"permissions:",
|
|
430
438
|
" contents: read",
|
|
431
|
-
" pull-requests: write",
|
|
432
439
|
"",
|
|
433
440
|
"jobs:",
|
|
434
441
|
" contrats:",
|
|
435
442
|
" runs-on: ubuntu-latest",
|
|
436
443
|
" steps:",
|
|
437
444
|
" # Le job exécute le code de la pull request : il n'a aucune raison de",
|
|
438
|
-
" # garder un jeton git utilisable.
|
|
445
|
+
" # garder un jeton git utilisable.",
|
|
439
446
|
" - uses: actions/checkout@v4",
|
|
440
447
|
" with:",
|
|
441
448
|
" persist-credentials: false",
|
|
@@ -484,33 +491,59 @@ function workflow(version) {
|
|
|
484
491
|
" **Action attendue :** un développeur doit ouvrir [l'exécution de la CI]($RUN_URL) pour en connaître la raison.",
|
|
485
492
|
" EOF",
|
|
486
493
|
"",
|
|
487
|
-
" #
|
|
494
|
+
" # Le rapport passe au job `commentaire`. Une dépendance a pu le",
|
|
495
|
+
" # réécrire : il part en corps de commentaire, jamais en commande.",
|
|
496
|
+
" - name: Transmettre le rapport",
|
|
497
|
+
" if: always() && github.event_name == 'pull_request'",
|
|
498
|
+
" uses: actions/upload-artifact@v4",
|
|
499
|
+
" with:",
|
|
500
|
+
" name: ucm-rapport",
|
|
501
|
+
" path: ci-report.md",
|
|
502
|
+
" retention-days: 1",
|
|
503
|
+
"",
|
|
504
|
+
" commentaire:",
|
|
505
|
+
" needs: contrats",
|
|
506
|
+
" # `!cancelled()` et non `always()` : un run annulé ne commente pas.",
|
|
507
|
+
" if: ${{ !cancelled() && github.event_name == 'pull_request' }}",
|
|
508
|
+
" runs-on: ubuntu-latest",
|
|
509
|
+
" permissions:",
|
|
510
|
+
" pull-requests: write",
|
|
511
|
+
" steps:",
|
|
512
|
+
" - uses: actions/download-artifact@v4",
|
|
513
|
+
" with:",
|
|
514
|
+
" name: ucm-rapport",
|
|
515
|
+
"",
|
|
488
516
|
" - name: Publier le diagnostic sur la pull request",
|
|
489
|
-
" if: always() && github.event_name == 'pull_request' && hashFiles('ci-report.md') != ''",
|
|
490
517
|
" env:",
|
|
491
518
|
" GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}",
|
|
492
519
|
" NUMERO: ${{ github.event.number }}",
|
|
493
520
|
" # --edit-last met à jour le commentaire précédent au lieu d'en empiler",
|
|
494
521
|
" # un nouveau à chaque push ; s'il n'en existe pas encore, on en crée un.",
|
|
495
522
|
" run: |",
|
|
496
|
-
' gh pr comment "$NUMERO" --body-file ci-report.md --edit-last \\',
|
|
497
|
-
' || gh pr comment "$NUMERO" --body-file ci-report.md',
|
|
523
|
+
' gh pr comment "$NUMERO" -R "$GITHUB_REPOSITORY" --body-file ci-report.md --edit-last \\',
|
|
524
|
+
' || gh pr comment "$NUMERO" -R "$GITHUB_REPOSITORY" --body-file ci-report.md',
|
|
498
525
|
"",
|
|
499
526
|
].join("\n");
|
|
500
527
|
}
|
|
501
528
|
|
|
502
529
|
/**
|
|
503
|
-
* Le
|
|
530
|
+
* Le contrôle pour GitLab, dans un fichier que `.gitlab-ci.yml` inclut.
|
|
531
|
+
*
|
|
532
|
+
* **Deux jobs, aucune clé globale.** Ni `workflow`, ni `image`, ni `variables`,
|
|
533
|
+
* ni `stages` : un fichier inclus qui en déclarerait changerait les pipelines
|
|
534
|
+
* de tous les jobs du projet. Chaque job porte ses propres règles.
|
|
504
535
|
*
|
|
505
|
-
* **
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
536
|
+
* **Le job qui installe les dépendances ne publie pas la note.** Une variable
|
|
537
|
+
* CI/CD non protégée entre dans l'environnement de tous les jobs, et un script
|
|
538
|
+
* d'installation la lirait. `ucm` la retire avant `npm ci`, ce qui ne vaut que
|
|
539
|
+
* pour les exécuteurs qui posent les variables dans le script ; `ucm-rapport`
|
|
540
|
+
* publie sans clone, depuis un dossier vide, sans script d'installation. Qui
|
|
541
|
+
* pousse une branche peut réécrire ce fichier et lire la variable : seul le
|
|
542
|
+
* rôle du compte qui porte le jeton borne ce qu'il en tire.
|
|
509
543
|
*
|
|
510
|
-
* **
|
|
511
|
-
*
|
|
512
|
-
*
|
|
513
|
-
* journal, et le rapport reste dans les artefacts.
|
|
544
|
+
* **La note ne refuse jamais une fusion.** `ucm-rapport` tourne après un échec
|
|
545
|
+
* de `ucm`, et `allow_failure` garde le pipeline de la couleur du contrôle
|
|
546
|
+
* quand GitLab refuse le jeton : le rapport reste dans les artefacts.
|
|
514
547
|
*/
|
|
515
548
|
function workflowGitlab(version) {
|
|
516
549
|
const cli = `npx --yes @ucm-kit/cli@${version}`;
|
|
@@ -521,12 +554,14 @@ function workflowGitlab(version) {
|
|
|
521
554
|
"# reçoit le designer qui valide un export : il n'ouvre pas les journaux de",
|
|
522
555
|
"# la CI. Toute étape qui refuse une fusion doit donc lui laisser un message.",
|
|
523
556
|
"#",
|
|
524
|
-
"# Ce fichier ne déclare
|
|
525
|
-
"# projet gardent leurs règles.
|
|
557
|
+
"# Ce fichier ne déclare que deux jobs et aucune clé globale : les autres jobs",
|
|
558
|
+
"# du projet gardent leurs règles. Les deux jobs prennent le stage `test`.",
|
|
526
559
|
"#",
|
|
527
560
|
"# Un job rouge ne bloque la fusion que si « Pipelines must succeed » est",
|
|
528
561
|
"# coché dans Settings > Merge requests. La note demande la variable",
|
|
529
|
-
"# UCM_GITLAB_TOKEN, masquée et non protégée
|
|
562
|
+
"# UCM_GITLAB_TOKEN, masquée et non protégée. Tout pipeline d'une branche du",
|
|
563
|
+
"# projet la lit : son jeton, de scope api, appartient à un compte de rôle",
|
|
564
|
+
"# Reporter sur ce seul projet.",
|
|
530
565
|
"#",
|
|
531
566
|
"# Écrit par `ucm init`. Adaptez-le : il ne sera jamais réécrit par-dessus.",
|
|
532
567
|
"ucm:",
|
|
@@ -538,6 +573,8 @@ function workflowGitlab(version) {
|
|
|
538
573
|
' - if: $CI_PIPELINE_SOURCE == "merge_request_event"',
|
|
539
574
|
" - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH",
|
|
540
575
|
" script:",
|
|
576
|
+
" # Les scripts d'installation ne reçoivent pas le jeton de la note.",
|
|
577
|
+
" - unset UCM_GITLAB_TOKEN",
|
|
541
578
|
" # Un adaptateur appartient à la stack du repository. Sans lockfile, le",
|
|
542
579
|
" # noyau portable reste seul.",
|
|
543
580
|
" - if [ -f package-lock.json ]; then npm ci; fi",
|
|
@@ -547,25 +584,40 @@ function workflowGitlab(version) {
|
|
|
547
584
|
" else",
|
|
548
585
|
` ${cli} check --report ci-report.md`,
|
|
549
586
|
" fi",
|
|
550
|
-
"
|
|
551
|
-
"
|
|
587
|
+
" artifacts:",
|
|
588
|
+
" when: always",
|
|
589
|
+
" paths:",
|
|
590
|
+
" - ci-report.md",
|
|
591
|
+
"",
|
|
592
|
+
"ucm-rapport:",
|
|
593
|
+
" image: node:22",
|
|
594
|
+
" needs:",
|
|
595
|
+
" - job: ucm",
|
|
596
|
+
" artifacts: true",
|
|
597
|
+
" rules:",
|
|
598
|
+
' - if: $CI_PIPELINE_SOURCE == "merge_request_event"',
|
|
599
|
+
" when: always",
|
|
600
|
+
" # Un jeton refusé ne rend pas rouge un pipeline dont les contrats sont verts.",
|
|
601
|
+
" allow_failure: true",
|
|
602
|
+
" variables:",
|
|
603
|
+
" # Aucun clone : ni .npmrc ni node_modules du repository.",
|
|
604
|
+
" GIT_STRATEGY: none",
|
|
605
|
+
' NPM_CONFIG_IGNORE_SCRIPTS: "true"',
|
|
606
|
+
" script:",
|
|
607
|
+
" # Filet : sans rapport, `ucm` s'est arrêté avant le contrôle (clone,",
|
|
552
608
|
" # installation, plantage).",
|
|
553
609
|
" - |",
|
|
554
610
|
" if [ ! -f ci-report.md ]; then",
|
|
555
611
|
" printf '%s\\n\\n%s\\n\\n%s\\n' \\",
|
|
556
612
|
" \"## ❌ La vérification n'a pas pu rendre son diagnostic\" \\",
|
|
557
613
|
" \"Les contrôles se sont arrêtés avant d'avoir pu analyser cet export : le rapport habituel n'a pas été produit. **Votre design n'est pas en cause** et réexporter depuis Figma n'y changerait rien.\" \\",
|
|
558
|
-
" \"**Action attendue :** un développeur doit ouvrir [le
|
|
614
|
+
" \"**Action attendue :** un développeur doit ouvrir [le pipeline de la CI]($CI_PIPELINE_URL) pour en connaître la raison.\" \\",
|
|
559
615
|
" > ci-report.md",
|
|
560
616
|
" fi",
|
|
561
|
-
"
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
"
|
|
565
|
-
" artifacts:",
|
|
566
|
-
" when: always",
|
|
567
|
-
" paths:",
|
|
568
|
-
" - ci-report.md",
|
|
617
|
+
" # Depuis un dossier vide, npx ne lit ni configuration ni paquet laissés",
|
|
618
|
+
" # par un job précédent sur le runner.",
|
|
619
|
+
" - cd \"$(mktemp -d)\"",
|
|
620
|
+
` - ${cli} rapport-gitlab --projet "$CI_PROJECT_ID" --merge-request "$CI_MERGE_REQUEST_IID" --fichier "$CI_PROJECT_DIR/ci-report.md" --api "$CI_API_V4_URL"`,
|
|
569
621
|
"",
|
|
570
622
|
].join("\n");
|
|
571
623
|
}
|
|
@@ -578,7 +630,7 @@ function lignesGitlab(racine) {
|
|
|
578
630
|
const lignes = [
|
|
579
631
|
{
|
|
580
632
|
fichier: "Settings > CI/CD > Variables",
|
|
581
|
-
ligne: "créez `UCM_GITLAB_TOKEN`, masquée et non protégée
|
|
633
|
+
ligne: "créez `UCM_GITLAB_TOKEN`, masquée et non protégée. Sa valeur : un jeton de scope api d'un compte de service membre de ce seul projet, au rôle Reporter, ou un jeton d'accès de projet au rôle Reporter si l'offre le permet. Sans cette variable, le rapport n'est pas publié sur la merge request. Non protégée, parce que les branches d'export ne le sont pas ; tout pipeline d'une branche la lit, et le rôle Reporter borne ce qu'on en tire à lire et commenter.",
|
|
582
634
|
},
|
|
583
635
|
{
|
|
584
636
|
fichier: "Settings > Merge requests",
|
|
@@ -740,8 +792,9 @@ export function rendreInit({
|
|
|
740
792
|
: "Aucun fichier à écrire : ce repository est déjà installé.",
|
|
741
793
|
);
|
|
742
794
|
if (forge) {
|
|
743
|
-
lignes.push(
|
|
744
|
-
|
|
795
|
+
lignes.push("");
|
|
796
|
+
lignes.push(`CI écrite pour ${forge.nom === "gitlab" ? "GitLab" : "GitHub"}, d'après ${forge.signal}.`);
|
|
797
|
+
lignes.push("L'option `--forge github` ou `--forge gitlab` en choisit une autre.");
|
|
745
798
|
}
|
|
746
799
|
|
|
747
800
|
if (optionsIgnorees) {
|
|
@@ -771,7 +824,15 @@ export function rendreInit({
|
|
|
771
824
|
if (restantes.length > 0) {
|
|
772
825
|
lignes.push("");
|
|
773
826
|
lignes.push("Reste à ajouter à la main :");
|
|
774
|
-
|
|
827
|
+
// L'endroit en tête, puis une phrase par ligne : le geste d'abord, ses
|
|
828
|
+
// raisons ensuite, sans qu'un paragraphe replié par le terminal les mêle.
|
|
829
|
+
for (const { fichier, ligne } of restantes) {
|
|
830
|
+
lignes.push("");
|
|
831
|
+
lignes.push(`- ${fichier}`);
|
|
832
|
+
for (const phrase of ligne.split(/(?<=\.) (?=\p{Lu})/u)) {
|
|
833
|
+
lignes.push(` ${phrase[0].toUpperCase()}${phrase.slice(1)}`);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
775
836
|
}
|
|
776
837
|
return lignes.join("\n");
|
|
777
838
|
}
|
package/src/rapport-gitlab.mjs
CHANGED
|
@@ -62,7 +62,7 @@ function gesteDuStatut(statut, action) {
|
|
|
62
62
|
}
|
|
63
63
|
if (statut === 403) {
|
|
64
64
|
return `Le jeton de UCM_GITLAB_TOKEN n'a pas le droit de ${action} (403). `
|
|
65
|
-
+ "Un mainteneur du projet doit lui donner le scope api et le rôle
|
|
65
|
+
+ "Un mainteneur du projet doit lui donner le scope api et le rôle Reporter sur ce projet.";
|
|
66
66
|
}
|
|
67
67
|
if (statut === 404) {
|
|
68
68
|
return `GitLab ne trouve pas la merge request en voulant ${action} (404). `
|
|
@@ -94,7 +94,7 @@ export async function rapportGitlab(arguments_, {
|
|
|
94
94
|
if (!jeton) {
|
|
95
95
|
ecrire("UCM_GITLAB_TOKEN est absente : le rapport n'est pas publié sur la merge request. "
|
|
96
96
|
+ "Il reste dans les artefacts du job. Pour le publier, un mainteneur du projet doit créer "
|
|
97
|
-
+ "cette variable, masquée et non protégée, avec un jeton de scope api.");
|
|
97
|
+
+ "cette variable, masquée et non protégée, avec un jeton de scope api d'un compte au rôle Reporter sur ce projet.");
|
|
98
98
|
return 0;
|
|
99
99
|
}
|
|
100
100
|
|