@ucm-kit/cli 0.1.46 → 0.1.48

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 CHANGED
@@ -16,7 +16,7 @@ matches them.
16
16
  Requires Node 20 or later. At the root of the repository:
17
17
 
18
18
  ```sh
19
- npx --yes @ucm-kit/cli@0.1.46 init
19
+ npx --yes @ucm-kit/cli@0.1.48 init
20
20
  ```
21
21
 
22
22
  1. Commit and push the files `init` wrote.
@@ -27,7 +27,7 @@ npx --yes @ucm-kit/cli@0.1.46 init
27
27
  To run the check locally:
28
28
 
29
29
  ```sh
30
- npx --yes @ucm-kit/cli@0.1.46 check --report ci-report.md
30
+ npx --yes @ucm-kit/cli@0.1.48 check --report ci-report.md
31
31
  ```
32
32
 
33
33
  `--yes` skips the npx confirmation prompt. Pin an exact version, without `^`:
@@ -78,7 +78,7 @@ contract would resolve to the same file. A repository that does not write React
78
78
  states its own extension:
79
79
 
80
80
  ```sh
81
- npx --yes @ucm-kit/cli@0.1.46 init --components Sources/DesignSystem --implementation '{dir}/{id}.swift'
81
+ npx --yes @ucm-kit/cli@0.1.48 init --components Sources/DesignSystem --implementation '{dir}/{id}.swift'
82
82
  ```
83
83
 
84
84
  The three path options act only on a first install. `ucm init` never overwrites
@@ -188,7 +188,7 @@ directory. It writes a minimal report when the check stopped before writing
188
188
  one, then posts the report:
189
189
 
190
190
  ```sh
191
- npx --yes @ucm-kit/cli@0.1.46 rapport-gitlab --projet "$CI_PROJECT_ID" --merge-request "$CI_MERGE_REQUEST_IID" --fichier "$CI_PROJECT_DIR/ci-report.md" --api "$CI_API_V4_URL"
191
+ npx --yes @ucm-kit/cli@0.1.48 rapport-gitlab --projet "$CI_PROJECT_ID" --merge-request "$CI_MERGE_REQUEST_IID" --fichier "$CI_PROJECT_DIR/ci-report.md" --api "$CI_API_V4_URL"
192
192
  ```
193
193
 
194
194
  | Option | Effect |
@@ -200,7 +200,11 @@ npx --yes @ucm-kit/cli@0.1.46 rapport-gitlab --projet "$CI_PROJECT_ID" --merge-r
200
200
 
201
201
  The command reads the token from `UCM_GITLAB_TOKEN` and never prints it. It
202
202
  replaces the note that the token's account wrote with the `<!-- ucm-rapport -->`
203
- marker, and creates one otherwise. Without the variable it says so and exits
203
+ marker, and creates one otherwise. A report carrying `<!-- ucm-sans-objet -->`
204
+ is the exception: it replaces an existing note, and never opens one, so a merge
205
+ request that touches nothing UCM stays free of comments. Written by `ucm check`
206
+ when the merge request changes no contract, no `tokens.json`, no
207
+ `ucm.config.json` and no resolved implementation. Without the variable it says so and exits
204
208
  with `0`: the report stays in the job artifacts. A refused token exits with `1`
205
209
  and names the fix. The job allows failure, so a refused token leaves the
206
210
  pipeline the colour of the check.
@@ -209,12 +213,19 @@ pipeline the colour of the check.
209
213
 
210
214
  | Option | Effect |
211
215
  |---|---|
212
- | `--base <sha>` | Limits informational notices to contracts changed since that commit |
216
+ | `--base <sha>` | Scopes the report to what the merge request changes, since that commit |
213
217
  | `--report <path>` | Writes the markdown report to that path, in addition to the terminal |
214
218
 
215
219
  The report stops before 65,536 characters, the size of a GitHub comment, and
216
- says so in its last line. The verdict opens the report and is never cut; the
217
- terminal output keeps every detail.
220
+ says so in its last line. It opens with the `<!-- ucm-rapport -->` marker, which
221
+ counts towards that limit and lets a publisher find the comment to replace. The
222
+ verdict follows and is never cut; the terminal output keeps every detail.
223
+
224
+ With `--base`, a merge request that changes no contract, no `tokens.json`, no
225
+ `ucm.config.json` and no resolved implementation gets a one-line report marked
226
+ `<!-- ucm-sans-objet -->`. A publisher replaces an existing comment with it and
227
+ never creates one. Blocking verdicts ignore this rule and always print in full.
228
+ Without `--base`, the report covers the whole repository.
218
229
 
219
230
  ### What the report says
220
231
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ucm-kit/cli",
3
- "version": "0.1.46",
3
+ "version": "0.1.48",
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.39"
32
+ "@ucm-kit/core": "0.1.40"
33
33
  },
34
34
  "devDependencies": {
35
35
  "yaml": "^2.9.1"
package/src/check.mjs CHANGED
@@ -56,11 +56,14 @@ export function releveDuDiff(racine, base, sourceTokens, executer = execFileSync
56
56
  const git = (arguments_) =>
57
57
  executer("git", arguments_, { cwd: racine, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
58
58
 
59
- let contratsModifies;
59
+ // Le relevé ne filtre rien. Un glob de contrats, qui était ici, cachait au
60
+ // noyau les fichiers d'implémentation, donc l'écart de conformité qu'une
61
+ // demande vient d'ouvrir dans le code seul. Où vit une implémentation se
62
+ // résout par le motif de `ucm.config.json` ; ce module n'a pas à le savoir,
63
+ // et aucune extension de fichier ne s'écrit ici.
64
+ let cheminsModifies;
60
65
  try {
61
- contratsModifies = git([
62
- "diff", "--name-only", "-z", base, "HEAD", "--", ":(glob)**/*.contract.json",
63
- ]);
66
+ cheminsModifies = git(["diff", "--name-only", "-z", base, "HEAD"]);
64
67
  } catch (erreur) {
65
68
  return {
66
69
  erreur: `Le diff depuis « ${base} » a échoué : ${erreur?.message ?? erreur}.\n`
@@ -71,6 +74,10 @@ export function releveDuDiff(racine, base, sourceTokens, executer = execFileSync
71
74
 
72
75
  // `git diff --quiet` sort en 1 quand il y a une différence : l'exception est
73
76
  // la réponse, et l'absence d'exception veut dire « rien n'a bougé ».
77
+ //
78
+ // La question reste posée à git, et non déduite de la liste ci-dessus : lui
79
+ // seul normalise le `./` d'un chemin de configuration, la casse selon
80
+ // `core.ignorecase` et le dossier passé en pathspec.
74
81
  let tokensModifies = true;
75
82
  try {
76
83
  git(["diff", "--quiet", base, "HEAD", "--", sourceTokens]);
@@ -79,7 +86,7 @@ export function releveDuDiff(racine, base, sourceTokens, executer = execFileSync
79
86
  tokensModifies = true;
80
87
  }
81
88
 
82
- return { contratsModifies: contratsModifies.replaceAll("\0", "\n"), tokensModifies };
89
+ return { cheminsModifies: cheminsModifies.replaceAll("\0", "\n"), tokensModifies };
83
90
  }
84
91
 
85
92
  /**
package/src/init.mjs CHANGED
@@ -33,7 +33,7 @@ import {
33
33
  NOM_CONFIGURATION,
34
34
  estCheminDuRepository,
35
35
  } from "@ucm-kit/core/format";
36
- import { lireConfiguration } from "@ucm-kit/core/lecteurs";
36
+ import { MARQUEUR_RAPPORT, MARQUEUR_SANS_OBJET, lireConfiguration } from "@ucm-kit/core/lecteurs";
37
37
 
38
38
  import { NOM_ADAPTATEUR_TYPESCRIPT } from "./adaptateur.mjs";
39
39
  import { CHEMIN_CONVENTIONS } from "./conventions.mjs";
@@ -484,6 +484,10 @@ function workflow(version) {
484
484
  " RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
485
485
  " run: |",
486
486
  " cat > ci-report.md <<EOF",
487
+ // Le filet n'est pas passé par `ucm check` : il écrit lui-même le marqueur
488
+ // que le noyau aurait posé. Sans lui, le commentaire qu'il crée ne serait
489
+ // retrouvé par aucune exécution suivante, et chaque push en empilerait un.
490
+ ` ${MARQUEUR_RAPPORT}`,
487
491
  " ## ❌ La vérification n'a pas pu rendre son diagnostic",
488
492
  "",
489
493
  " 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.",
@@ -517,18 +521,38 @@ function workflow(version) {
517
521
  " env:",
518
522
  " GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}",
519
523
  " NUMERO: ${{ github.event.number }}",
520
- " # --edit-last met à jour le commentaire précédent au lieu d'en empiler",
521
- " # un nouveau à chaque push ; s'il n'en existe pas encore, on en crée un.",
524
+ " # `ucm check` écrit le marqueur en tête du rapport et le compte dans la",
525
+ " # limite d'un commentaire. Le préfixer ici portait le corps publié",
526
+ " # au-delà de cette limite, que GitHub refuse.",
527
+ " #",
528
+ " # Le commentaire précédent est remplacé au lieu d'en empiler un nouveau à",
529
+ " # chaque push. S'il n'en existe pas encore, on en crée un, SAUF si le",
530
+ " # rapport ne demande aucun geste : une demande de fusion étrangère à UCM",
531
+ " # reste vierge, et une demande dont le refus est corrigé voit son verdict",
532
+ " # remplacé plutôt que laissé périmé.",
533
+ " #",
534
+ " # `GITHUB_TOKEN` est un jeton d'intégration, auquel `GET /user` répond",
535
+ " # 403 : le compte se replie alors sur `github-actions[bot]`, l'auteur",
536
+ " # des commentaires qu'il écrit. Un jeton personnel garde son propre",
537
+ " # compte. Le repli reste hors de la substitution : en échec, `gh` écrit",
538
+ " # le corps de l'erreur sur la sortie standard, qui serait capturé avec.",
539
+ " #",
540
+ " # `pipefail` fait échouer l'étape quand la recherche échoue. Sans lui,",
541
+ " # `tail` rendait son propre code, et une recherche en échec passait",
542
+ " # pour une pull request sans commentaire.",
522
543
  " run: |",
523
- ' printf "<!-- ucm-rapport -->\\n" > ucm-report.md',
524
- ' cat ci-report.md >> ucm-report.md',
525
- ' COMPTE="$(gh api user --jq .login)"',
544
+ " set -o pipefail",
545
+ " if ! COMPTE=\"$(gh api user --jq .login 2>/dev/null)\"; then",
546
+ " COMPTE='github-actions[bot]'",
547
+ " fi",
526
548
  ' NOTE="$(gh api "repos/$GITHUB_REPOSITORY/issues/$NUMERO/comments" --paginate \\',
527
- ' --jq ".[] | select(.user.login == \\\"$COMPTE\\\") | select(.body | startswith(\\\"<!-- ucm-rapport -->\\\")) | .id" | tail -n 1)"',
549
+ ` --jq ".[] | select(.user.login == \\\"$COMPTE\\\") | select(.body | startswith(\\\"${MARQUEUR_RAPPORT}\\\")) | .id" | tail -n 1)"`,
528
550
  ' if [ -n "$NOTE" ]; then',
529
- ' gh api --method PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$NOTE" -f body="$(cat ucm-report.md)"',
551
+ ' gh api --method PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$NOTE" -f body="$(cat ci-report.md)"',
552
+ ` elif ! head -n 2 ci-report.md | grep -qF "${MARQUEUR_SANS_OBJET}"; then`,
553
+ ' gh pr comment "$NUMERO" -R "$GITHUB_REPOSITORY" --body-file ci-report.md',
530
554
  ' else',
531
- ' gh pr comment "$NUMERO" -R "$GITHUB_REPOSITORY" --body-file ucm-report.md',
555
+ " echo \"Cette demande de fusion ne touche aucun fichier suivi par UCM : aucun commentaire n'est créé.\"",
532
556
  ' fi',
533
557
  "",
534
558
  ].join("\n");
@@ -18,7 +18,9 @@
18
18
  import { readFileSync } from "node:fs";
19
19
  import { resolve } from "node:path";
20
20
 
21
- export const MARQUEUR_RAPPORT = "<!-- ucm-rapport -->";
21
+ import { MARQUEUR_RAPPORT, MARQUEUR_SANS_OBJET } from "@ucm-kit/core/lecteurs";
22
+
23
+ export { MARQUEUR_RAPPORT, MARQUEUR_SANS_OBJET };
22
24
 
23
25
  function neutraliserActionsRapides(texte) {
24
26
  return texte.replace(/^([ \t]*)(\/\S.*)$/gm, (_entier, avant, action) => {
@@ -113,7 +115,13 @@ export async function rapportGitlab(arguments_, {
113
115
  alerter(`Le rapport ${valeurs.fichier} ne se lit pas (${erreurLecture?.code ?? erreurLecture?.message}) : aucune note n'est publiée.`);
114
116
  return 1;
115
117
  }
116
- const corps = `${MARQUEUR_RAPPORT}\n${neutraliserActionsRapides(rapport)}`;
118
+ // `ucm check` écrit le marqueur en tête du rapport, et le compte dans la
119
+ // borne d'un commentaire. Le préfixe qui subsiste ici ne sert qu'à un fichier
120
+ // venu d'ailleurs : sans marqueur, la note ne serait jamais retrouvée, donc
121
+ // jamais remplacée, et chaque push en empilerait une de plus.
122
+ const marque = rapport.startsWith(MARQUEUR_RAPPORT) ? rapport : `${MARQUEUR_RAPPORT}\n${rapport}`;
123
+ const sansObjet = marque.includes(MARQUEUR_SANS_OBJET);
124
+ const corps = neutraliserActionsRapides(marque);
117
125
  const projet = encodeURIComponent(valeurs.projet);
118
126
  const notes = `${valeurs.api}/projects/${projet}/merge_requests/${encodeURIComponent(valeurs.mergeRequest)}/notes`;
119
127
 
@@ -160,6 +168,12 @@ export async function rapportGitlab(arguments_, {
160
168
  if (existante) {
161
169
  await appeler(`${notes}/${existante.id}`, "remplacer la note du rapport", { method: "PUT", body: JSON.stringify({ body: corps }) });
162
170
  ecrire(`Rapport remplacé dans la note ${existante.id} de la merge request !${valeurs.mergeRequest}.`);
171
+ } else if (sansObjet) {
172
+ // Un rapport qui ne demande aucun geste remplace une note, il n'en ouvre
173
+ // jamais une. Une merge request étrangère à UCM reste vierge ; une merge
174
+ // request dont le refus a été corrigé voit son verdict remplacé plutôt
175
+ // que laissé périmé sous les yeux de qui la relit.
176
+ ecrire(`Cette merge request ne touche aucun fichier suivi par UCM : aucune note n'est publiée.`);
163
177
  } else {
164
178
  await appeler(notes, "écrire la note du rapport", { method: "POST", body: JSON.stringify({ body: corps }) });
165
179
  ecrire(`Rapport publié en note de la merge request !${valeurs.mergeRequest}.`);