Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,36 @@ integrés au monorepo (`bundled`) ou installables depuis leur propre dépôt

## Modules

| id | source | emplacement | env |
| --- | --- | --- | --- |
| `accreditations` | bundled | `modules/accreditations` | `GROQ_API_KEY` |
| `calendar` | bundled | `modules/calendar` | Google |
| `concerts` | bundled | `modules/concerts` | `OPENWEATHERMAP_API_KEY` |
| `daily-brief` | bundled | `modules/daily-brief` | — |
| `emails` | bundled | `modules/emails` | Google |
| `followups` | bundled | `modules/followups` | — |
| `github` | bundled | `modules/github` | `GITHUB_TOKEN`, `GITHUB_REPO` |
| `photo` | bundled | `modules/photo` | — |
| `reminders` | bundled | `modules/reminders` | — |
| `schedule` | bundled | `modules/schedule` | `CESAR_USERNAME`, `CESAR_PASSWORD` |
| `weather` | bundled | `modules/weather` | `OPENWEATHERMAP_API_KEY` |
| `web` | bundled | `modules/web` | `BRAVE_SEARCH_API_KEY` |
| `watch-later` | external | `mprnl/BS-watch-later` `v1.0.1` | — |
| `daily-quote` | external | `mprnl/BS-daily-quote` `v1.0.0` | — |
| id | source | emplacement | distribue | env |
| --- | --- | --- | --- | --- |
| `accreditations` | bundled | `modules/accreditations` | `v1.0.0` | `GROQ_API_KEY` |
| `calendar` | bundled | `modules/calendar` | — | Google |
| `concerts` | bundled | `modules/concerts` | — | `OPENWEATHERMAP_API_KEY` |
| `daily-brief` | bundled | `modules/daily-brief` | — | — |
| `emails` | bundled | `modules/emails` | — | Google |
| `followups` | bundled | `modules/followups` | — | — |
| `github` | bundled | `modules/github` | — | `GITHUB_TOKEN`, `GITHUB_REPO` |
| `photo` | bundled | `modules/photo` | — | — |
| `reminders` | bundled | `modules/reminders` | — | — |
| `schedule` | bundled | `modules/schedule` | — | `CESAR_USERNAME`, `CESAR_PASSWORD` |
| `weather` | bundled | `modules/weather` | — | `OPENWEATHERMAP_API_KEY` |
| `web` | bundled | `modules/web` | — | `BRAVE_SEARCH_API_KEY` |
| `watch-later` | external | `mprnl/BS-watch-later` `v1.0.1` | oui | — |
| `daily-quote` | external | `mprnl/BS-daily-quote` `v1.0.0` | oui | — |

## Regles

- `bundled` : le module vit dans `mprnl/backstage`, il se désactive mais ne
s'installe pas.
- `external` : le module vit dans son dépôt `mprnl/BS-*` et s'installe avec une
ref figée (tag ou commit), jamais une branche mobile.
- `source: bundled` : le module vit dans `mprnl/backstage`.
- `source: external` : le module vit dans son dépôt `mprnl/BS-*`.
- `distributable` : `true` quand un dépôt distant existe et porte une ref figée,
`repo`, `ref` et `visibility` renseignés. Un module peut être `bundled` **et**
`distributable` : c'est le cas d'`accreditations`, encore chargé par le
monorepo mais déjà installable depuis son dépôt.
- `ref` ne change qu'après une release du dépôt du module, jamais une branche
mobile.
- `id` unique, égal à l'identifiant déclaré par le module.
- `ref` ne change qu'après une release du dépôt du module.
- Le catalogue n'est pas une source de confiance : l'application revérifie
l'`id`, la ref figée et la compatibilité du kit avant d'installer.
- Un module `bundled` qui importe `@/lib/*` n'est pas distribuable : il ne
bascule pas en `external` avant que ce point soit tranché (#255).

## Validation

Expand Down
56 changes: 45 additions & 11 deletions catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,29 @@
"id": "accreditations",
"source": "bundled",
"path": "modules/accreditations",
"repo": null,
"ref": null,
"repo": "https://github.com/mprnl/BS-accreditations",
"ref": "v1.0.0",
"distributable": true,
"description": "Scan des emails d'accréditation, fiches de demande et relance J+7.",
"kit": "^0.1.0",
"env": ["GROQ_API_KEY"],
"visibility": null
"env": [
"GROQ_API_KEY"
],
"visibility": "public"
},
{
"id": "calendar",
"source": "bundled",
"path": "modules/calendar",
"repo": null,
"ref": null,
"distributable": false,
"description": "Google Calendar : création externe, recherche non fiable.",
"kit": "^0.1.0",
"env": ["GOOGLE_CLIENT_ID", "GOOGLE_CLIENT_SECRET"],
"env": [
"GOOGLE_CLIENT_ID",
"GOOGLE_CLIENT_SECRET"
],
"visibility": null
},
{
Expand All @@ -27,9 +34,12 @@
"path": "modules/concerts",
"repo": null,
"ref": null,
"distributable": false,
"description": "Concerts suivis et préparation terrain.",
"kit": "^0.1.0",
"env": ["OPENWEATHERMAP_API_KEY"],
"env": [
"OPENWEATHERMAP_API_KEY"
],
"visibility": null
},
{
Expand All @@ -38,6 +48,7 @@
"path": "modules/daily-brief",
"repo": null,
"ref": null,
"distributable": false,
"description": "Job du brief du jour. Aucune page, aucun outil.",
"kit": "^0.1.0",
"env": [],
Expand All @@ -49,9 +60,13 @@
"path": "modules/emails",
"repo": null,
"ref": null,
"distributable": false,
"description": "Gmail : lecture non fiable, envoi confirmé.",
"kit": "^0.1.0",
"env": ["GOOGLE_CLIENT_ID", "GOOGLE_CLIENT_SECRET"],
"env": [
"GOOGLE_CLIENT_ID",
"GOOGLE_CLIENT_SECRET"
],
"visibility": null
},
{
Expand All @@ -60,6 +75,7 @@
"path": "modules/followups",
"repo": null,
"ref": null,
"distributable": false,
"description": "Relances datées, écriture vérifiée par relecture.",
"kit": "^0.1.0",
"env": [],
Expand All @@ -71,9 +87,13 @@
"path": "modules/github",
"repo": null,
"ref": null,
"distributable": false,
"description": "Issues GitHub : lecture non fiable, création externe.",
"kit": "^0.1.0",
"env": ["GITHUB_TOKEN", "GITHUB_REPO"],
"env": [
"GITHUB_TOKEN",
"GITHUB_REPO"
],
"visibility": null
},
{
Expand All @@ -82,6 +102,7 @@
"path": "modules/photo",
"repo": null,
"ref": null,
"distributable": false,
"description": "Shootings photo, écritures vérifiées par relecture.",
"kit": "^0.1.0",
"env": [],
Expand All @@ -93,6 +114,7 @@
"path": "modules/reminders",
"repo": null,
"ref": null,
"distributable": false,
"description": "Rappels : module pilote du noyau modulaire.",
"kit": "^0.1.0",
"env": [],
Expand All @@ -104,9 +126,13 @@
"path": "modules/schedule",
"repo": null,
"ref": null,
"distributable": false,
"description": "Emploi du temps CESAR en lecture.",
"kit": "^0.1.0",
"env": ["CESAR_USERNAME", "CESAR_PASSWORD"],
"env": [
"CESAR_USERNAME",
"CESAR_PASSWORD"
],
"visibility": null
},
{
Expand All @@ -115,9 +141,12 @@
"path": "modules/weather",
"repo": null,
"ref": null,
"distributable": false,
"description": "Météo, lecture externe non fiable.",
"kit": "^0.1.0",
"env": ["OPENWEATHERMAP_API_KEY"],
"env": [
"OPENWEATHERMAP_API_KEY"
],
"visibility": null
},
{
Expand All @@ -126,9 +155,12 @@
"path": "modules/web",
"repo": null,
"ref": null,
"distributable": false,
"description": "Recherche web et métadonnées de page, non fiable.",
"kit": "^0.1.0",
"env": ["BRAVE_SEARCH_API_KEY"],
"env": [
"BRAVE_SEARCH_API_KEY"
],
"visibility": null
},
{
Expand All @@ -137,6 +169,7 @@
"path": null,
"repo": "https://github.com/mprnl/BS-watch-later",
"ref": "v1.0.1",
"distributable": true,
"description": "Lien à regarder plus tard, avec page, rail, panneau et carte d'accueil.",
"kit": "^0.1.0",
"env": [],
Expand All @@ -148,6 +181,7 @@
"path": null,
"repo": "https://github.com/mprnl/BS-daily-quote",
"ref": "v1.0.0",
"distributable": true,
"description": "Une citation par jour, locale et déterministe. Module de référence.",
"kit": "^0.1.0",
"env": [],
Expand Down
82 changes: 57 additions & 25 deletions scripts/validate.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { readFileSync } from "node:fs";

const REQUIRED = ["id", "source", "path", "repo", "ref", "description", "kit", "env", "visibility"];
const REQUIRED = [
"id",
"source",
"path",
"repo",
"ref",
"distributable",
"description",
"kit",
"env",
"visibility",
];
const SOURCES = new Set(["bundled", "external"]);
const VISIBILITY = new Set(["public", "private"]);
const MOVING_REF = /^(main|master|develop|dev|HEAD)$/;
Expand All @@ -11,14 +22,50 @@ const seen = new Set();

if (!Array.isArray(entries)) errors.push("catalog.json doit contenir un tableau");

for (const [index, entry] of entries.entries()) {
const where = entry?.id ? `${entry.id}` : `entree ${index}`;
function checkSource(where, entry) {
if (!SOURCES.has(entry.source)) errors.push(`${where} : source doit etre bundled ou external`);

if (entry.source === "bundled" && (typeof entry.path !== "string" || !entry.path.startsWith("modules/"))) {
errors.push(`${where} : un module bundled declare son path dans modules/`);
}
if (entry.source === "external" && entry.path !== null) {
errors.push(`${where} : un module external n'a pas de path`);
}
if (entry.source === "external" && entry.distributable !== true) {
errors.push(`${where} : un module external est toujours distribuable`);
}
}

function checkDistribution(where, entry) {
if (entry.distributable === false) {
if (entry.repo !== null || entry.ref !== null || entry.visibility !== null) {
errors.push(`${where} : un module non distribuable n'a ni repo, ni ref, ni visibility`);
}
return;
}

if (entry.distributable !== true) {
errors.push(`${where} : distributable doit etre un booleen`);
return;
}

if (typeof entry.repo !== "string" || !entry.repo.startsWith("https://github.com/mprnl/BS-")) {
errors.push(`${where} : repo doit etre une URL https://github.com/mprnl/BS-*`);
}
if (typeof entry.ref !== "string" || entry.ref.length === 0 || MOVING_REF.test(entry.ref)) {
errors.push(`${where} : ref doit etre un tag ou un commit, pas une branche`);
}
if (!VISIBILITY.has(entry.visibility)) errors.push(`${where} : visibility doit etre public ou private`);
}

for (const [index, entry] of entries.entries()) {
if (typeof entry !== "object" || entry === null) {
errors.push(`${where} : objet attendu`);
errors.push(`entree ${index} : objet attendu`);
continue;
}

const where = typeof entry.id === "string" && entry.id.length > 0 ? entry.id : `entree ${index}`;

for (const key of REQUIRED) {
if (!(key in entry)) errors.push(`${where} : champ manquant ${key}`);
}
Expand All @@ -27,26 +74,8 @@ for (const [index, entry] of entries.entries()) {
else if (seen.has(entry.id)) errors.push(`${where} : id duplique`);
else seen.add(entry.id);

if (!SOURCES.has(entry.source)) errors.push(`${where} : source doit etre bundled ou external`);

if (entry.source === "bundled") {
if (typeof entry.path !== "string" || !entry.path.startsWith("modules/")) {
errors.push(`${where} : un module bundled declare son path dans modules/`);
}
if (entry.repo !== null || entry.ref !== null) errors.push(`${where} : un module bundled n'a ni repo ni ref`);
if (entry.visibility !== null) errors.push(`${where} : un module bundled a visibility null`);
}

if (entry.source === "external") {
if (entry.path !== null) errors.push(`${where} : un module external n'a pas de path`);
if (typeof entry.repo !== "string" || !entry.repo.startsWith("https://github.com/mprnl/BS-")) {
errors.push(`${where} : repo doit etre une URL https://github.com/mprnl/BS-*`);
}
if (typeof entry.ref !== "string" || entry.ref.length === 0 || MOVING_REF.test(entry.ref)) {
errors.push(`${where} : ref doit etre un tag ou un commit, pas une branche`);
}
if (!VISIBILITY.has(entry.visibility)) errors.push(`${where} : visibility doit etre public ou private`);
}
checkSource(where, entry);
checkDistribution(where, entry);

if (!Array.isArray(entry.env) || entry.env.some((name) => typeof name !== "string")) {
errors.push(`${where} : env doit etre un tableau de chaines`);
Expand All @@ -55,10 +84,13 @@ for (const [index, entry] of entries.entries()) {

const bundled = entries.filter((entry) => entry.source === "bundled").length;
const external = entries.length - bundled;
const distributable = entries.filter((entry) => entry.distributable === true).length;

if (errors.length > 0) {
for (const error of errors) console.error(`- ${error}`);
process.exit(1);
}

console.log(`catalog.json valide : ${entries.length} module(s), ${bundled} integres, ${external} externes`);
console.log(
`catalog.json valide : ${entries.length} module(s), ${bundled} integres, ${external} externes, ${distributable} distribuable(s)`
);
Loading