@ucm-kit/cli 0.1.41 → 0.1.44

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.41 init
19
+ npx --yes @ucm-kit/cli@0.1.44 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.41 init
27
27
  To run the check locally:
28
28
 
29
29
  ```sh
30
- npx --yes @ucm-kit/cli@0.1.41 check --report ci-report.md
30
+ npx --yes @ucm-kit/cli@0.1.44 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.41 init --components Sources/DesignSystem --implementation '{dir}/{id}.swift'
81
+ npx --yes @ucm-kit/cli@0.1.44 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
@@ -159,7 +159,7 @@ global key, so the project's other jobs keep their rules. `ucm` runs the check
159
159
  in merge request pipelines and on the default branch; `ucm-rapport` posts the
160
160
  note in merge request pipelines. Both take the default `test` stage. A new
161
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
162
+ command prints the `include` line to add. It also prints the settings it
163
163
  cannot make:
164
164
 
165
165
  - create the CI/CD variable `UCM_GITLAB_TOKEN`, masked and not protected,
@@ -172,8 +172,14 @@ cannot make:
172
172
  - tick "Pipelines must succeed" in the merge request settings. Without it, a red
173
173
  report does not block the merge it says is blocked;
174
174
  - keep `test` in `stages:` when `.gitlab-ci.yml` declares them: GitLab refuses a
175
- pipeline whose job names a missing stage.
176
-
175
+ pipeline whose job names a missing stage;
176
+ - put `- if: $CI_PIPELINE_SOURCE == "merge_request_event"` first in
177
+ `workflow:rules` when `.gitlab-ci.yml` declares rules without it: GitLab then
178
+ creates no merge request pipeline, and `ucm` checks no export.
179
+
180
+ Both jobs set `inherit: default: false`. A project `default:` block does not
181
+ reach them: its `before_script` would run before the token is unset, and would
182
+ fail in `ucm-rapport`, which has no clone. Global variables are still inherited.
177
183
  `ucm` unsets `UCM_GITLAB_TOKEN` before `npm ci`, so install scripts do not
178
184
  inherit it on executors that set variables in the job script. `ucm-rapport`
179
185
  runs no code from the repository: it clones nothing, receives `ci-report.md`
@@ -182,7 +188,7 @@ directory. It writes a minimal report when the check stopped before writing
182
188
  one, then posts the report:
183
189
 
184
190
  ```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"
191
+ npx --yes @ucm-kit/cli@0.1.44 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
192
  ```
187
193
 
188
194
  | Option | Effect |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ucm-kit/cli",
3
- "version": "0.1.41",
3
+ "version": "0.1.44",
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.37"
32
+ "@ucm-kit/core": "0.1.38"
33
33
  },
34
34
  "devDependencies": {
35
35
  "yaml": "^2.9.1"
package/src/init.mjs CHANGED
@@ -566,6 +566,10 @@ function workflowGitlab(version) {
566
566
  "# Écrit par `ucm init`. Adaptez-le : il ne sera jamais réécrit par-dessus.",
567
567
  "ucm:",
568
568
  " image: node:22",
569
+ " # Le before_script d'un default: du projet tournerait avec le jeton de la",
570
+ " # note. Les variables globales, elles, restent héritées.",
571
+ " inherit:",
572
+ " default: false",
569
573
  " variables:",
570
574
  " # Le diff avec la base délimite les états informatifs du rapport.",
571
575
  ' GIT_DEPTH: "0"',
@@ -591,6 +595,9 @@ function workflowGitlab(version) {
591
595
  "",
592
596
  "ucm-rapport:",
593
597
  " image: node:22",
598
+ " # Sans clone, le before_script d'un default: du projet échouerait.",
599
+ " inherit:",
600
+ " default: false",
594
601
  " needs:",
595
602
  " - job: ucm",
596
603
  " artifacts: true",
@@ -622,9 +629,22 @@ function workflowGitlab(version) {
622
629
  ].join("\n");
623
630
  }
624
631
 
632
+ /**
633
+ * Le texte d'une clé de premier niveau d'un YAML, lignes indentées comprises,
634
+ * ou `null` quand la clé est absente.
635
+ *
636
+ * La CLI n'a aucune dépendance YAML : ce découpage lit la forme qu'écrit un
637
+ * `.gitlab-ci.yml` courant. Une clé venue d'un `include:` n'est pas vue.
638
+ */
639
+ function blocDeRacine(yaml, cle) {
640
+ const bloc = new RegExp(`^${cle}:([^\\n]*(?:\\n(?:[ \\t]+[^\\n]*|-[^\\n]*|#[^\\n]*|[ \\t]*)(?=\\n|$))*)`, "m").exec(yaml);
641
+ return bloc ? bloc[1] : null;
642
+ }
643
+
625
644
  /**
626
645
  * Les lignes qu'`init` ne peut pas écrire pour GitLab : des réglages du projet,
627
- * et un `stages:` qui refuserait le job.
646
+ * un `stages:` qui refuserait le job, et un `workflow:rules` qui ne crée aucun
647
+ * pipeline de merge request.
628
648
  */
629
649
  function lignesGitlab(racine) {
630
650
  const lignes = [
@@ -639,13 +659,20 @@ function lignesGitlab(racine) {
639
659
  ];
640
660
  try {
641
661
  const ci = readFileSync(join(racine, ".gitlab-ci.yml"), "utf8");
642
- const stages = /^stages:([^\n]*(?:\n[ \t]+[^\n]*|\n-[^\n]*)*)/m.exec(ci);
643
- if (stages && !/\btest\b/.test(stages[1])) {
662
+ const stages = blocDeRacine(ci, "stages");
663
+ if (stages !== null && !/\btest\b/.test(stages)) {
644
664
  lignes.push({
645
665
  fichier: ".gitlab-ci.yml",
646
666
  ligne: "ajoutez `test` à `stages:`. Le job ucm s'y range, et GitLab refuse un pipeline dont un job vise un stage absent.",
647
667
  });
648
668
  }
669
+ const workflow = blocDeRacine(ci, "workflow");
670
+ if (workflow !== null && /^[ \t]+rules:/m.test(workflow) && !workflow.includes("merge_request_event")) {
671
+ lignes.push({
672
+ fichier: ".gitlab-ci.yml",
673
+ ligne: "ajoutez `- if: $CI_PIPELINE_SOURCE == \"merge_request_event\"` en tête de `workflow:rules`. Sans cette règle, GitLab ne crée aucun pipeline de merge request et le job ucm ne contrôle aucun export.",
674
+ });
675
+ }
649
676
  } catch {
650
677
  // Sans .gitlab-ci.yml, celui qu'`init` écrit ne déclare aucun stage.
651
678
  }
package/src/ucm.mjs CHANGED
@@ -192,6 +192,11 @@ function executerCommande(arguments_, {
192
192
  }
193
193
 
194
194
  if (commande === "icons") {
195
+ if (arguments_.length > 1) {
196
+ const alerter = sorties.alerter ?? console.error;
197
+ alerter(`Argument inconnu : ${arguments_[1]}\n\nucm icons`);
198
+ return 2;
199
+ }
195
200
  const { configuration, erreur } = lireConfiguration(racine);
196
201
  if (erreur) {
197
202
  // La configuration est refusée ici comme ailleurs : retomber sur les