From 28396f790aae181e2f625cdea62cbbad06e49931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= Date: Mon, 4 Nov 2024 11:13:34 +0100 Subject: [PATCH] Add wasm-bindgen version check to CI (#7983) --- .github/workflows/labels.yml | 39 ++++++++++++++ rerun_js/web-viewer/build-wasm.mjs | 86 ++++++------------------------ rerun_js/web-viewer/hashes.json | 1 - 3 files changed, 56 insertions(+), 70 deletions(-) delete mode 100644 rerun_js/web-viewer/hashes.json diff --git a/.github/workflows/labels.yml b/.github/workflows/labels.yml index a0e7ac40f10c..d298808073ee 100644 --- a/.github/workflows/labels.yml +++ b/.github/workflows/labels.yml @@ -40,3 +40,42 @@ jobs: mode: minimum count: 1 labels: "πŸ“Š analytics, 🟦 blueprint, πŸͺ³ bug, 🌊 C++ API, CLI, codegen/idl, πŸ§‘β€πŸ’» dev experience, dependencies, πŸ“– documentation, πŸ’¬ discussion, examples, exclude from changelog, πŸͺ΅ Log & send APIs, πŸ“‰ performance, 🐍 Python API, ⛃ re_datastore, πŸ” re_query, πŸ“Ί re_viewer, πŸ”Ί re_renderer, 🚜 refactor, β›΄ release, πŸ¦€ Rust API, πŸ”¨ testing, ui, πŸ•ΈοΈ web" + + wasm-bindgen-check: + name: Check wasm-bindgen version + if: ${{ github.event_name == 'pull_request' }} + runs-on: ubuntu-latest + continue-on-error: true + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: prefix-dev/setup-pixi@v0.8.1 + with: + pixi-version: v0.34.0 + + - name: Get current wasm-bindgen version + id: current-version + run: | + version=$(pixi run taplo get -f crates/viewer/re_viewer/Cargo.toml "target.*.dependencies.wasm-bindgen") + echo "current_version=$version" >> $GITHUB_OUTPUT + + - name: Get previous wasm-bindgen version + id: previous-version + run: | + prev_ref=$(git rev-parse --abbrev-ref HEAD) + git checkout main + + version=$(pixi run taplo get -f crates/viewer/re_viewer/Cargo.toml "target.*.dependencies.wasm-bindgen") + echo "previous_version=$version" >> $GITHUB_OUTPUT + + git checkout $prev_ref + + - name: Require label if versions changed + if: ${{ steps.current-version.outputs.current_version != steps.previous-version.outputs.previous_version }} + uses: mheap/github-action-required-labels@v3 + with: + mode: exactly + count: 1 + labels: "wasm-bindgen version update" diff --git a/rerun_js/web-viewer/build-wasm.mjs b/rerun_js/web-viewer/build-wasm.mjs index 81ca9d67c5ea..70522e6f59b0 100644 --- a/rerun_js/web-viewer/build-wasm.mjs +++ b/rerun_js/web-viewer/build-wasm.mjs @@ -31,9 +31,8 @@ function buildWebViewer(mode) { } } -async function re_viewer_js(mode) { +function re_viewer_js() { let code = fs.readFileSync(path.join(__dirname, "re_viewer.js"), "utf-8"); - await checkHash(mode, "re_viewer.js", code); // this transforms the module, wrapping it in a default-exported function. // calling the function produces a new "instance" of the module, because @@ -89,9 +88,8 @@ return Object.assign(__wbg_init, { initSync, deinit }, __exports); fs.writeFileSync(path.join(__dirname, "re_viewer.js"), code); } -async function re_viewer_d_ts(mode) { +function re_viewer_d_ts() { let code = fs.readFileSync(path.join(__dirname, "re_viewer.d.ts"), "utf-8"); - await checkHash(mode, "re_viewer.d.ts", code); // this transformation just re-exports WebHandle and adds a default export inside the `.d.ts` file @@ -104,77 +102,27 @@ export default function(): wasm_bindgen; fs.writeFileSync(path.join(__dirname, "re_viewer.d.ts"), code); } -async function hash(data) { - const buffer = await crypto.subtle.digest("sha-256", data); - return Array.from(new Uint8Array(buffer)) - .map((b) => b.toString(16).padStart(2, "0")) - .join(""); -} - -async function checkHash(mode, id, data) { - const storedHash = hashes?.[mode]?.[id]; - const computedHash = await hash(new TextEncoder().encode(data)); - - if (updateHashes) { - hashes[mode] ??= {}; - hashes[mode][id] = computedHash; - return; - } +function main() { + const args = util.parseArgs({ + options: { + mode: { + type: "string", + }, + }, + }); + const mode = args.values.mode; - if (storedHash !== computedHash) { - console.error(` -============================================================== -Output of "${id}" changed. -Update the \`build-wasm.mjs\` script to handle the new output, -then run \`pixi run node build-wasm.mjs --update-hashes\`. -============================================================== -`); - process.exit(1); + if (!mode) { + throw new Error("Missing required argument: mode"); } -} -async function run(mode) { buildWebViewer(mode); - await re_viewer_js(mode); - await re_viewer_d_ts(mode); -} - -const args = util.parseArgs({ - options: { - mode: { - type: "string", - }, - "update-hashes": { - type: "boolean", - }, - }, -}); - -let updateHashes = !!args.values["update-hashes"]; -let hashes; -try { - hashes = JSON.parse( - fs.readFileSync(path.join(__dirname, "hashes.json"), "utf-8"), - ); -} catch (e) { - hashes = {}; + re_viewer_js(); + re_viewer_d_ts(); } try { - if (updateHashes) { - await run("release"); - await run("debug"); - fs.writeFileSync( - path.join(__dirname, "hashes.json"), - JSON.stringify(hashes), - ); - } else { - if (!args.values.mode) { - throw new Error("Missing required argument: mode"); - } - - await run(args.values.mode); - } + main(); } catch (e) { - console.error(e.message); + console.error(e); } diff --git a/rerun_js/web-viewer/hashes.json b/rerun_js/web-viewer/hashes.json deleted file mode 100644 index 6dd33989c499..000000000000 --- a/rerun_js/web-viewer/hashes.json +++ /dev/null @@ -1 +0,0 @@ -{"release":{"re_viewer.js":"9548c50002f6c6844e50ceb154641a4ca547413a54eb3214b18909848776492f","re_viewer.d.ts":"d533906cbd59ac7b2f4a962a24daad55c5df854343414b8b6db08e2d956fdee3"},"debug":{"re_viewer.js":"74ec126e7deeb831c72c7a2ccffb98c3c63fb7268f27feffdfb2da286db65816","re_viewer.d.ts":"c642a7f1990d414d9953f0b215d8114418502b3b9f0240ca81b039766d5236b0"}} \ No newline at end of file