mainnet #270
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Validate JSON | |
| on: | |
| pull_request: | |
| paths: | |
| - '*.json' | |
| push: | |
| branches: | |
| - main | |
| - shinhwi | |
| paths: | |
| - '*.json' | |
| jobs: | |
| validate-json: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '18' | |
| - name: Install dependencies | |
| run: npm install ajv ajv-formats | |
| - name: Validate dapps.json | |
| run: | | |
| node -e " | |
| const fs = require('fs'); | |
| const Ajv = require('ajv'); | |
| const addFormats = require('ajv-formats'); | |
| const ajv = new Ajv({ | |
| allErrors: true, | |
| verbose: true, | |
| strict: false // disable strict mode | |
| }); | |
| addFormats(ajv); | |
| try { | |
| // Load and parse dapps.json | |
| const dappsData = fs.readFileSync('./dapps.json', 'utf8'); | |
| const dapps = JSON.parse(dappsData); | |
| // Load dapps-schema.json | |
| const schema = JSON.parse(fs.readFileSync('./dapps-schema.json', 'utf8')); | |
| // Check monad_exclusive field for each item (for debugging) | |
| dapps.forEach((dapp, index) => { | |
| if (dapp.monad_exclusive !== undefined) { | |
| console.log(\`Info: dapp[\${index}].monad_exclusive value: \${JSON.stringify(dapp.monad_exclusive)}, type: \${typeof dapp.monad_exclusive}\`); | |
| } | |
| }); | |
| // Check for duplicate names | |
| const names = dapps.map(d => d.name); | |
| const duplicateNames = names.filter((name, index) => names.indexOf(name) !== index); | |
| if (duplicateNames.length > 0) { | |
| console.error('Error: Duplicate dapp names found:', [...new Set(duplicateNames)]); | |
| process.exit(1); | |
| } | |
| // Check for duplicate contract addresses (case-insensitive) | |
| const allContracts = dapps.flatMap(d => d.contracts); | |
| const normalizedContracts = allContracts.map(c => c.toLowerCase()); | |
| const duplicateContracts = normalizedContracts.filter((contract, index) => | |
| normalizedContracts.indexOf(contract) !== index | |
| ); | |
| if (duplicateContracts.length > 0) { | |
| console.error('Error: Duplicate contract addresses found:', [...new Set(duplicateContracts)]); | |
| process.exit(1); | |
| } | |
| // Schema validation | |
| const validate = ajv.compile(schema); | |
| const valid = validate(dapps); | |
| if (!valid) { | |
| console.error('dapps.json validation errors:'); | |
| console.error(JSON.stringify(validate.errors, null, 2)); | |
| process.exit(1); | |
| } | |
| console.log('dapps.json is valid.'); | |
| } catch (error) { | |
| console.error('Error occurred:', error.message); | |
| process.exit(1); | |
| } | |
| " | |
| - name: Validate nfts.json | |
| run: | | |
| node -e " | |
| const fs = require('fs'); | |
| const Ajv = require('ajv'); | |
| const addFormats = require('ajv-formats'); | |
| const ajv = new Ajv({ | |
| allErrors: true, | |
| verbose: true, | |
| strict: false // disable strict mode | |
| }); | |
| addFormats(ajv); | |
| try { | |
| // Load and parse nfts.json | |
| const nftsData = fs.readFileSync('./nfts.json', 'utf8'); | |
| const nfts = JSON.parse(nftsData); | |
| // Load nfts-schema.json | |
| const schema = JSON.parse(fs.readFileSync('./nfts-schema.json', 'utf8')); | |
| // Check for duplicate names | |
| const names = nfts.map(n => n.name); | |
| const duplicateNames = names.filter((name, index) => names.indexOf(name) !== index); | |
| if (duplicateNames.length > 0) { | |
| console.error('Error: Duplicate NFT names found:', [...new Set(duplicateNames)]); | |
| process.exit(1); | |
| } | |
| // Check for duplicate contract addresses (case-insensitive) | |
| const allContracts = nfts.flatMap(n => n.contracts); | |
| const normalizedContracts = allContracts.map(c => c.toLowerCase()); | |
| const duplicateContracts = normalizedContracts.filter((contract, index) => | |
| normalizedContracts.indexOf(contract) !== index | |
| ); | |
| if (duplicateContracts.length > 0) { | |
| console.error('Error: Duplicate contract addresses found:', [...new Set(duplicateContracts)]); | |
| process.exit(1); | |
| } | |
| // Schema validation | |
| const validate = ajv.compile(schema); | |
| const valid = validate(nfts); | |
| if (!valid) { | |
| console.error('nfts.json validation errors:'); | |
| console.error(JSON.stringify(validate.errors, null, 2)); | |
| process.exit(1); | |
| } | |
| console.log('nfts.json is valid.'); | |
| } catch (error) { | |
| console.error('Error occurred:', error.message); | |
| process.exit(1); | |
| } | |
| " | |
| - name: Check cross file duplicates (informational only) | |
| run: | | |
| node -e " | |
| const fs = require('fs'); | |
| try { | |
| // Load both files | |
| const dapps = JSON.parse(fs.readFileSync('./dapps.json', 'utf8')); | |
| const nfts = JSON.parse(fs.readFileSync('./nfts.json', 'utf8')); | |
| // Extract all contract addresses | |
| const dappContracts = dapps.flatMap(d => d.contracts.map(c => c.toLowerCase())); | |
| const nftContracts = nfts.flatMap(n => n.contracts.map(c => c.toLowerCase())); | |
| // Check for duplicate addresses between files | |
| const duplicates = dappContracts.filter(c => nftContracts.includes(c)); | |
| if (duplicates.length > 0) { | |
| console.log('Note: Duplicate contract addresses found between dapps.json and nfts.json:', duplicates); | |
| // process.exit(1); - not treating as error | |
| } else { | |
| console.log('No duplicate contract addresses between files.'); | |
| } | |
| } catch (error) { | |
| console.error('Error during cross-file duplicate check:', error.message); | |
| // process.exit(1); - not treating as error | |
| } | |
| " |