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
63 changes: 63 additions & 0 deletions .github/scripts/check-yaml.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const fs = require("fs");
const yaml = require("js-yaml");
const glob = require("glob");

const SNAKE_CASE_REGEX = /^[a-z][a-z0-9_]*$/;

let hasError = false;
const parsedFiles = [];

function checkKeys(obj, file, path = "") {
if (typeof obj !== "object" || obj === null) return;

for (const key of Object.keys(obj)) {
const fullPath = path ? `${path}.${key}` : key;

if (!SNAKE_CASE_REGEX.test(key)) {
console.error(
`❌ ${file} → clé invalide "${fullPath}" (snake_case requis)`
);
hasError = true;
}

checkKeys(obj[key], file, fullPath);
}
}

const files = glob.sync("**/*.{yml,yaml}", {
ignore: ["node_modules/**"]
});

if (files.length === 0) {
console.log("ℹ️ Aucun fichier YAML trouvé");
process.exit(0);
}

for (const file of files) {
try {
const content = fs.readFileSync(file, "utf8");
const data = yaml.load(content);

checkKeys(data, file);

parsedFiles.push({
file,
data
});
} catch (err) {
console.error(`❌ Erreur YAML dans ${file}`);
console.error(err.message);
hasError = true;
}
}

if (hasError) {
console.error("\n⛔ Validation YAML échouée");
process.exit(1);
}

/**
* OUTPUT FINAL
* Tu peux le parser dans un autre step GitHub Actions
*/
console.log(JSON.stringify(parsedFiles, null, 2));
31 changes: 31 additions & 0 deletions .github/workflows/yaml-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: YAML format & snake_case check

on:
push:
paths:
- "**/*.yml"
- "**/*.yaml"
pull_request:
paths:
- "**/*.yml"
- "**/*.yaml"

jobs:
yaml-check:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm install js-yaml glob

- name: Validate YAML files and keys
run: node .github/scripts/check-yaml.cjs