From 9c8c62a89a93e34467562667f00c42c8e9aae9f0 Mon Sep 17 00:00:00 2001 From: Pavol Noha Date: Wed, 13 Sep 2023 15:34:08 -1000 Subject: [PATCH] Turbo cache SHA --- scripts/build-math.mjs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/build-math.mjs b/scripts/build-math.mjs index 5cbe76ea..21e6d917 100644 --- a/scripts/build-math.mjs +++ b/scripts/build-math.mjs @@ -2,6 +2,7 @@ import { existsSync, mkdirSync, writeFileSync } from 'fs'; const PARAM_PREFIX = '--'; +const GITHUB_API = 'https://api.github.com/repos/galacticcouncil/HydraDX-wasm/git/trees/main?recursive=1'; const WASM_REPO = 'https://raw.githubusercontent.com/galacticcouncil/HydraDX-wasm'; const WASM_BRANCH = 'main'; const WASM_BUILD = 'build'; @@ -24,6 +25,12 @@ const fetchResource = async (math, target, file) => { return Buffer.from(arrayBuffer); }; +const fetchTree = async () => { + const resp = await fetch(GITHUB_API); + const json = await resp.json(); + return json.tree; +}; + const main = async () => { const args = process.argv.slice(2); const params = parseArgs(args); @@ -34,12 +41,18 @@ const main = async () => { mkdirSync(BUILD_FOLDER, { recursive: true }); } + const gitTree = await fetchTree(); + for (const conf of BUILD_MATRIX) { const [target, input, output] = conf; + + const confPath = [BUILD_FOLDER, mathParam, target, input].join('/'); + const confItem = gitTree.find((record) => record.path === confPath); + const confSha = confItem.sha; const file = await fetchResource(mathParam, target, input); const outPath = [BUILD_FOLDER, output]; writeFileSync(outPath.join('/'), file); - console.log(`${input} fetched`); + console.log(`${input} [${confSha.slice(0, 8)}] fetched`); } console.log(`Math ${mathParam} ready ✅`); };