From cb7d6fd937b06c12e14a4bbb0411f351d4c66b3d Mon Sep 17 00:00:00 2001 From: Ben Allfree Date: Sun, 23 Nov 2025 09:49:17 -0800 Subject: [PATCH] refactor: Simplify build hash computation by using flags directly and log GitHub dispatch payload. --- convex/actions.ts | 26 +++++++++++++---------- convex/builds.ts | 53 ++++++++++++----------------------------------- 2 files changed, 28 insertions(+), 51 deletions(-) diff --git a/convex/actions.ts b/convex/actions.ts index a6a57df..4e171b6 100644 --- a/convex/actions.ts +++ b/convex/actions.ts @@ -16,6 +16,20 @@ export const dispatchGithubBuild = action({ throw new Error("GITHUB_TOKEN is not set"); } + const payload = { + ref: "main", // or make this configurable + inputs: { + target: args.target, + flags: args.flags, + version: args.version, + build_id: args.buildId, + build_hash: args.buildHash, + convex_url: process.env.CONVEX_SITE_URL, + }, + }; + + console.log("Dispatching GitHub build with payload:", JSON.stringify(payload, null, 2)); + try { const response = await fetch( "https://api.github.com/repos/MeshEnvy/configurable-web-flasher/actions/workflows/custom_build.yml/dispatches", @@ -26,17 +40,7 @@ export const dispatchGithubBuild = action({ Accept: "application/vnd.github.v3+json", "Content-Type": "application/json", }, - body: JSON.stringify({ - ref: "main", // or make this configurable - inputs: { - target: args.target, - flags: args.flags, - version: args.version, - build_id: args.buildId, - build_hash: args.buildHash, - convex_url: process.env.CONVEX_SITE_URL, - }, - }), + body: JSON.stringify(payload), }, ); diff --git a/convex/builds.ts b/convex/builds.ts index 1d95e05..7cbf986 100644 --- a/convex/builds.ts +++ b/convex/builds.ts @@ -5,50 +5,19 @@ import { internalMutation, mutation, query } from "./_generated/server"; import modulesData from "./modules.json"; /** - * Normalizes a config object to a stable JSON string for hashing. - * Sorts keys and handles values consistently. - */ -function normalizeConfig(config: any): string { - const normalized: Record = {}; - - // Sort keys and process values - const sortedKeys = Object.keys(config || {}).sort(); - - for (const key of sortedKeys) { - const value = config[key]; - // Only include non-null, non-undefined values - if (value !== null && value !== undefined) { - // Normalize boolean, number, and string values - if (typeof value === "boolean") { - normalized[key] = value; - } else if (typeof value === "number") { - normalized[key] = value; - } else if (typeof value === "string") { - // Only include non-empty strings - if (value.trim() !== "") { - normalized[key] = value.trim(); - } - } - } - } - - return JSON.stringify(normalized); -} - -/** - * Computes a stable SHA-256 hash from version, target, and config. - * This hash uniquely identifies a build configuration. + * Computes a stable SHA-256 hash from version, target, and flags. + * This hash uniquely identifies a build configuration based on what is actually executed. */ async function computeBuildHash( version: string, target: string, - config: any, + flags: string, ): Promise { - const normalizedConfig = normalizeConfig(config); + // Input is now the exact parameters used for the build const input = JSON.stringify({ version, target, - config: normalizedConfig, + flags, }); // Use Web Crypto API for SHA-256 hashing @@ -110,12 +79,14 @@ export const triggerBuild = mutation({ // Create build records for each target for (const target of profile.targets) { - // Compute build hash + // Compute build hash using the generated flags const buildHash = await computeBuildHash( profile.version, target, - profile.config, + flagsString, ); + + console.log(`Computed build hash for ${target}: ${buildHash} (Flags: ${flagsString})`); // Check cache for existing build const cached = await ctx.db @@ -252,12 +223,14 @@ export const retryBuild = mutation({ const flagsString = flags.join(" "); - // Compute build hash for retry + // Compute build hash for retry using flags const buildHash = await computeBuildHash( profile.version, build.target, - profile.config, + flagsString, ); + + console.log(`Computed retry hash: ${buildHash} (Flags: ${flagsString})`); await ctx.scheduler.runAfter(0, api.actions.dispatchGithubBuild, { buildId: args.buildId,