diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 38e16d463533..c7d978b48184 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -13,4 +13,9 @@ jobs: exempt-issue-labels: enhancement stale-pr-message: 'This PR has no activity in a while - it will be closed soon.' days-before-stale: 42 - days-before-close: 7 \ No newline at end of file + days-before-close: 7 + exempt-pr-labels: 'do-not-stale' + stale-issue-label: 'stale' + stale-pr-label: 'stale' + close-issue-message: 'This issue is now closed due to inactivity.' + close-pr-message: 'This PR is now closed due to inactivity.' diff --git a/.github/workflows/validate_json.yml b/.github/workflows/validate_json.yml index 493033306a23..d186168b1757 100644 --- a/.github/workflows/validate_json.yml +++ b/.github/workflows/validate_json.yml @@ -21,4 +21,4 @@ jobs: working-directory: ./tools run: |- npm install - node schemaCheck.js \ No newline at end of file + node schemaCheck.js diff --git a/README.md b/README.md index 860179e70469..b8f7950c94d9 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,19 @@ npx prettier --write _data/*/*.json * Make sure CI is green. There will likely be no review when the CI is red. * When making changes that fix the CI problems - please re-request a review - otherwise it is too much work to track such changes with so many PRs daily +## Automated Validation Process + +We use GitHub Actions workflows to automate the validation process for the chain JSON files. The following workflows are used: + +* **validate_json.yml**: This workflow runs the `tools/schemaCheck.js` script to validate the JSON schema of the chain files on each push or pull request. +* **stale.yml**: This workflow manages stale issues and PRs, ensuring that unresolved issues are closed after a certain period of inactivity. + +To format the JSON files according to the style defined in `.prettierrc.json`, use the `prettier` tool. Run the following command to format all existing JSON files: + +``` +npx prettier --write _data/*/*.json +``` + ## Usages ### Tools * [MESC](https://paradigmxyz.github.io/mesc) diff --git a/tools/schemaCheck.js b/tools/schemaCheck.js index f9553d9cf9e0..da016d6d1551 100644 --- a/tools/schemaCheck.js +++ b/tools/schemaCheck.js @@ -7,6 +7,7 @@ const path = require('path') const resolve = (_path) => path.resolve(__dirname, _path) const chainFiles = fs.readdirSync(resolve("../_data/chains/")) +const iconFiles = fs.readdirSync(resolve("../_data/icons/")) // https://chainagnostic.org/CAIPs/caip-2 const parseChainId = (chainId) => @@ -15,6 +16,9 @@ const parseChainId = (chainId) => ) const filesWithErrors = [] +const shortNames = new Set() +const names = new Set() + for (const chainFile of chainFiles) { const fileLocation = resolve(`../_data/chains/${chainFile}`) const fileData = fs.readFileSync(fileLocation, "utf8") @@ -30,8 +34,28 @@ for (const chainFile of chainFiles) { console.error(ajv.errors) filesWithErrors.push(chainFile) } -} + // Check for unique shortName and name + if (shortNames.has(fileDataJson.shortName)) { + console.error(`Duplicate shortName found: ${fileDataJson.shortName} in ${chainFile}`) + filesWithErrors.push(chainFile) + } else { + shortNames.add(fileDataJson.shortName) + } + + if (names.has(fileDataJson.name)) { + console.error(`Duplicate name found: ${fileDataJson.name} in ${chainFile}`) + filesWithErrors.push(chainFile) + } else { + names.add(fileDataJson.name) + } + + // Check for icon existence and format + if (fileDataJson.icon && !iconFiles.includes(`${fileDataJson.icon}.json`)) { + console.error(`Icon not found: ${fileDataJson.icon} in ${chainFile}`) + filesWithErrors.push(chainFile) + } +} if (filesWithErrors.length > 0) { filesWithErrors.forEach(file => { console.error(`Invalid JSON Schema in ${file}`) @@ -41,4 +65,4 @@ if (filesWithErrors.length > 0) { else { console.info("Schema check completed successfully"); exit(0); -} \ No newline at end of file +}