Compare commits

...

5 Commits

Author SHA1 Message Date
Zhe Fang
2b3169e5f6 Update check-hash-collision.js 2026-01-10 13:32:08 -05:00
Zhe Fang
9d2e245a99 Rename releases-to-discord.yml to release-to-discord.yml 2026-01-10 13:25:17 -05:00
Zhe Fang
0513c3a128 Add GitHub Actions workflow for plugin registry check 2026-01-10 13:22:32 -05:00
Zhe Fang
5082c4c245 Create check-hash-collision.js 2026-01-10 13:20:59 -05:00
Zhe Fang
659b4d0e60 Create plugins-registry.json 2026-01-10 13:19:39 -05:00
4 changed files with 61 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
name: Plugin Registry Check
on:
pull_request:
paths:
- 'Community/plugins-registry.json'
jobs:
check-collision:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Run Hash Collision Check
run: node Community/scripts/check-hash-collision.js

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,40 @@
// Community/scripts/check-hash-collision.js
const fs = require('fs');
const path = require('path');
const registryPath = path.join(__dirname, '../plugins-registry.json');
const registry = JSON.parse(fs.readFileSync(registryPath, 'utf8'));
function getStableId(pluginId) {
let hash = 23;
for (let i = 0; i < pluginId.length; i++) {
hash = (hash * 31 + pluginId.charCodeAt(i)) | 0;
}
return Math.abs(hash) + 1000;
}
const seenIds = new Set();
let hasError = false;
console.log("🔍 Starting to check for plugin ID conflicts...");
registry.forEach(item => {
const stableId = getStableId(item.id);
console.log(`Checking [${item.id}] -> Hash: ${stableId}`);
if (seenIds.has(stableId)) {
console.error(`⛔ Fatel error! Conflict detected!`);
console.error(`The hash value (${stableId}) calculated from the plugin ID [${item.id}] is duplicated with an existing plugin.`);
hasError = true;
}
seenIds.add(stableId);
});
if (hasError) {
console.log("⛔ Check failed, please change the plugin ID.");
process.exit(1);
} else {
console.log("✅ The check passed; no conflicts were found.");
process.exit(0);
}