Skip to content

Commit

Permalink
Merge pull request #27 from KeesGeerligs/kees-dev
Browse files Browse the repository at this point in the history
Kees dev
  • Loading branch information
laurensV authored Nov 27, 2024
2 parents ca5f2ac + c74acdd commit b7a505a
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 20 deletions.
17 changes: 9 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
},
"type": "module",
"dependencies": {
"@nosana/sdk": "^0.3.32"
"@nosana/sdk": "^0.3.42"
}
}
75 changes: 65 additions & 10 deletions scripts/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,70 @@ import { validateJobDefinition } from '@nosana/sdk';
import * as fs from 'fs';
import * as path from 'path';

fs.readdirSync('./templates').filter(folder => {
const template = fs.readFileSync(path.join('./templates/' + folder, 'job-definition.json'));
const jobDefinition = template.toString();
const result = validateJobDefinition(JSON.parse(jobDefinition));
if (result.success) {
console.log(`${folder} job definition is valid!`)
} else {
const error = result.errors[0];
throw new Error(`${folder}: ${error.path} - expected ${error.expected}, but found ${JSON.stringify(error.value)}`);
// Store all IDs to check for uniqueness
const allIds = new Set();

// Validate a single template directory
function validateTemplate(folder) {
const templatePath = path.join('./templates', folder);

// Check if README.md exists
if (!fs.existsSync(path.join(templatePath, 'README.md'))) {
throw new Error(`${folder}: Missing README.md file`);
}

// Check if info.json exists
if (!fs.existsSync(path.join(templatePath, 'info.json'))) {
throw new Error(`${folder}: Missing info.json file`);
}

// Validate info.json format and content
const infoContent = fs.readFileSync(path.join(templatePath, 'info.json'));
let info;
try {
info = JSON.parse(infoContent);
} catch (e) {
throw new Error(`${folder}: Invalid JSON in info.json`);
}

// Check required fields in info.json
const requiredFields = ['id', 'name', 'description', 'category', 'icon'];
for (const field of requiredFields) {
if (!info[field]) {
throw new Error(`${folder}: Missing required field '${field}' in info.json`);
}
}
);

// Validate icon URL length
if (info.icon.length > 256) {
throw new Error(`${folder}: Icon URL exceeds 256 characters`);
}

// Check for unique IDs
if (allIds.has(info.id)) {
throw new Error(`${folder}: Duplicate ID '${info.id}' found in info.json`);
}
allIds.add(info.id);

// Validate category is an array
if (!Array.isArray(info.category)) {
throw new Error(`${folder}: 'category' must be an array in info.json`);
}

// Validate job definition
const template = fs.readFileSync(path.join(templatePath, 'job-definition.json'));
const jobDefinition = template.toString();
const result = validateJobDefinition(JSON.parse(jobDefinition));
if (!result.success) {
const error = result.errors[0];
throw new Error(`${folder}: ${error.path} - expected ${error.expected}, but found ${JSON.stringify(error.value)}`);
}

console.log(`✓ ${folder} template is valid!`);
}

// Process all template directories
const templateDirs = fs.readdirSync('./templates');
templateDirs.forEach(validateTemplate);

console.log('\n✓ All templates validated successfully!');
2 changes: 1 addition & 1 deletion templates/AUTOMATIC1111-stable-diffusion-1.5/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"name": "AUTOMATIC1111 Stable Diffusion 1.5",
"description": "Stable Diffusion is a latent text-to-image diffusion model",
"category": ["Web UI", "Image Generation"],
"icon": "https://raw.githubusercontent.com/nosana-ci/templates/refs/heads/main/templates/AUTOMATIC1111-stable-diffusion-1.5/AUTOMATIC.png"
"icon": "https://user-images.githubusercontent.com/36368048/196056941-aace0837-473a-4aa5-9067-505b17797aa1.png"
}
File renamed without changes

0 comments on commit b7a505a

Please sign in to comment.