From 7ce14a0b4607e35c0c834c712ea1e93d5bb8395b Mon Sep 17 00:00:00 2001 From: Fernthedev <15272073+Fernthedev@users.noreply.github.com> Date: Thu, 17 Jul 2025 15:26:28 -0400 Subject: [PATCH 1/3] Add Deno check workflow and validation script for core mods --- .github/workflows/check.yml | 19 +++++++++++ .vscode/settings.json | 3 ++ check.ts | 68 +++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 .github/workflows/check.yml create mode 100644 .vscode/settings.json create mode 100644 check.ts diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..c595972 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,19 @@ +name: Deno Check + +on: + push: + branches: + - main + pull_request: + +jobs: + deno-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Deno + uses: denoland/setup-deno@v1 + # with: + # deno-version: v1.x + - name: Run deno check + run: deno run -R -N -E check.ts \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b943dbc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "deno.enable": true +} \ No newline at end of file diff --git a/check.ts b/check.ts new file mode 100644 index 0000000..85867bc --- /dev/null +++ b/check.ts @@ -0,0 +1,68 @@ +// Deno script to ensure the core mods are valid + +interface CoreModListing { + [version: string]: GameCoreMods; +} + +interface GameCoreMods { + lastUpdated: string; + mods: CoreMod[]; +} + +interface CoreMod { + id: string; + version: string; + downloadLink: string; +} + +const json: CoreModListing = JSON.parse( + await Deno.readTextFile("./core_mods.json") +); + +// ensure all have valid time +Object.entries(json).forEach(([version, coreMods]) => { + console.log(`Checking version ${version}`); + if (!isValidTime(coreMods.lastUpdated)) { + throw new Error( + `Invalid lastUpdated time for version ${version}: ${coreMods.lastUpdated}` + ); + } + + coreMods.mods.forEach(async (mod) => { + if (!isValidSemver(mod.version)) { + throw new Error( + `Invalid version for mod ${mod.id} in version ${version}: ${mod.version}` + ); + } + const validURL = await isValidUrl(mod.downloadLink); + if (!validURL) { + throw new Error( + `Invalid download link for mod ${mod.id} in version ${version}: ${mod.downloadLink}` + ); + } + // Green color for valid mods using "colorette" + console.log(`%cMod ${mod.id} is valid`, "color: green"); + }); +}); + +function isValidTime(timeStr: string) { + // Use Date parsing to check for valid ISO 8601 timestamp + const d = new Date(timeStr); + return !isNaN(d.getTime()); +} + +function isValidSemver(version: string) { + // assert string is semver + return /^\d+\.\d+\.\d+$/.test(version); +} + +async function isValidUrl(url: string) { + // assert string is a valid URL + try { + const res = await fetch(url, { method: "HEAD" }); + if (!res.ok) return false; + return true; + } catch { + return false; + } +} From 15a8a6382bcae94d0b63681a50d478f2f3082562 Mon Sep 17 00:00:00 2001 From: Fernthedev <15272073+Fernthedev@users.noreply.github.com> Date: Thu, 17 Jul 2025 15:27:56 -0400 Subject: [PATCH 2/3] Reorder --- check.ts | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/check.ts b/check.ts index 85867bc..ff38c00 100644 --- a/check.ts +++ b/check.ts @@ -15,6 +15,29 @@ interface CoreMod { downloadLink: string; } + +function isValidTime(timeStr: string) { + // Use Date parsing to check for valid ISO 8601 timestamp + const d = new Date(timeStr); + return !isNaN(d.getTime()); +} + +function isValidSemver(version: string) { + // assert string is semver + return /^\d+\.\d+\.\d+$/.test(version); +} + +async function isValidUrl(url: string) { + // assert string is a valid URL + try { + const res = await fetch(url, { method: "HEAD" }); + if (!res.ok) return false; + return true; + } catch { + return false; + } +} + const json: CoreModListing = JSON.parse( await Deno.readTextFile("./core_mods.json") ); @@ -44,25 +67,3 @@ Object.entries(json).forEach(([version, coreMods]) => { console.log(`%cMod ${mod.id} is valid`, "color: green"); }); }); - -function isValidTime(timeStr: string) { - // Use Date parsing to check for valid ISO 8601 timestamp - const d = new Date(timeStr); - return !isNaN(d.getTime()); -} - -function isValidSemver(version: string) { - // assert string is semver - return /^\d+\.\d+\.\d+$/.test(version); -} - -async function isValidUrl(url: string) { - // assert string is a valid URL - try { - const res = await fetch(url, { method: "HEAD" }); - if (!res.ok) return false; - return true; - } catch { - return false; - } -} From 842f2cb3b9cb5ed5dec964ee896448136425b7ff Mon Sep 17 00:00:00 2001 From: Fernthedev <15272073+Fernthedev@users.noreply.github.com> Date: Thu, 17 Jul 2025 15:30:59 -0400 Subject: [PATCH 3/3] Remove schema reference from core mods JSON --- check.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/check.ts b/check.ts index ff38c00..539986d 100644 --- a/check.ts +++ b/check.ts @@ -42,6 +42,8 @@ const json: CoreModListing = JSON.parse( await Deno.readTextFile("./core_mods.json") ); +delete json["$schema"]; // Remove schema reference if present + // ensure all have valid time Object.entries(json).forEach(([version, coreMods]) => { console.log(`Checking version ${version}`);