Skip to content

Commit 6be7646

Browse files
Copilothotlong
andcommitted
Address code review feedback: optimize validation workflow and fix stale message
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 983fff8 commit 6be7646

File tree

3 files changed

+102
-9
lines changed

3 files changed

+102
-9
lines changed

.github/workflows/stale.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ jobs:
3939
recent activity. It will be closed in 7 days if no further activity occurs.
4040
Please address any review comments or conflicts.
4141
close-pr-message: >
42-
This pull request was automatically closed because it has not had activity for 30 days.
42+
This pull request was automatically closed because it has not had activity for 37 days
43+
(marked stale after 30 days, then closed after 7 more days of inactivity).
4344
Please feel free to reopen and address the review comments if you wish to continue.
4445
days-before-pr-stale: 30
4546
days-before-pr-close: 7

.github/workflows/validate-metadata.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,9 @@ jobs:
4242
- name: Install dependencies
4343
run: pnpm install --frozen-lockfile
4444
timeout-minutes: 5
45-
46-
- name: Build packages
47-
run: pnpm run build
48-
timeout-minutes: 10
4945

5046
- name: Validate YAML syntax
5147
run: |
5248
echo "Checking YAML syntax for metadata files..."
53-
find . -type f \( -name "*.object.yml" -o -name "*.validation.yml" -o -name "*.permission.yml" -o -name "*.app.yml" -o -name "*.page.yml" -o -name "*.menu.yml" \) | while read file; do
54-
echo "Validating: $file"
55-
node -e "const yaml = require('js-yaml'); const fs = require('fs'); try { yaml.load(fs.readFileSync('$file', 'utf8')); console.log('✓ Valid'); } catch(e) { console.error('✗ Invalid:', e.message); process.exit(1); }"
56-
done
49+
pnpm exec node scripts/validate-yaml.js
5750
timeout-minutes: 5

scripts/validate-yaml.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Validate YAML syntax for ObjectQL metadata files
4+
*
5+
* This script validates all metadata files in the repository:
6+
* - *.object.yml
7+
* - *.validation.yml
8+
* - *.permission.yml
9+
* - *.app.yml
10+
* - *.page.yml
11+
* - *.menu.yml
12+
*/
13+
14+
const yaml = require('js-yaml');
15+
const fs = require('fs');
16+
const path = require('path');
17+
18+
// Define metadata file extensions
19+
const extensions = [
20+
'.object.yml',
21+
'.validation.yml',
22+
'.permission.yml',
23+
'.app.yml',
24+
'.page.yml',
25+
'.menu.yml'
26+
];
27+
28+
// Directories to exclude
29+
const excludeDirs = ['node_modules', 'dist', '.git'];
30+
31+
/**
32+
* Recursively find all files matching the specified extensions
33+
*/
34+
function findFiles(dir, fileList = []) {
35+
const files = fs.readdirSync(dir);
36+
37+
files.forEach(file => {
38+
const filePath = path.join(dir, file);
39+
const stat = fs.statSync(filePath);
40+
41+
if (stat.isDirectory()) {
42+
// Skip excluded directories
43+
if (!excludeDirs.includes(file)) {
44+
findFiles(filePath, fileList);
45+
}
46+
} else {
47+
// Check if file matches any of our extensions
48+
if (extensions.some(ext => file.endsWith(ext))) {
49+
fileList.push(filePath);
50+
}
51+
}
52+
});
53+
54+
return fileList;
55+
}
56+
57+
let hasErrors = false;
58+
let validCount = 0;
59+
let errorCount = 0;
60+
61+
console.log('🔍 Validating ObjectQL metadata YAML files...\n');
62+
63+
// Find and validate all metadata files
64+
const files = findFiles(process.cwd());
65+
66+
if (files.length === 0) {
67+
console.log('ℹ️ No metadata files found to validate.');
68+
process.exit(0);
69+
}
70+
71+
files.forEach(file => {
72+
try {
73+
const content = fs.readFileSync(file, 'utf8');
74+
yaml.load(content);
75+
console.log(`✓ ${path.relative(process.cwd(), file)}`);
76+
validCount++;
77+
} catch (error) {
78+
console.error(`✗ ${path.relative(process.cwd(), file)}`);
79+
console.error(` Error: ${error.message}`);
80+
if (error.mark) {
81+
console.error(` Line ${error.mark.line + 1}, Column ${error.mark.column + 1}`);
82+
}
83+
console.error('');
84+
hasErrors = true;
85+
errorCount++;
86+
}
87+
});
88+
89+
// Print summary
90+
console.log('\n' + '='.repeat(60));
91+
if (hasErrors) {
92+
console.error(`❌ Validation failed: ${errorCount} error(s) found`);
93+
console.log(`✓ Valid files: ${validCount}`);
94+
console.error(`✗ Invalid files: ${errorCount}`);
95+
process.exit(1);
96+
} else {
97+
console.log(`✅ All ${validCount} YAML metadata file(s) are valid!`);
98+
process.exit(0);
99+
}

0 commit comments

Comments
 (0)