From 15ffe5cdbff18bf7d8178a29c16264db88a103f4 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Wed, 18 Dec 2024 19:41:02 -0500 Subject: [PATCH] [ci] Validate downloaded build artifact Adds validation to download-build-artifacts to confirm that the downloaded artifact matches what was requested. --- .../shared-commands/download-build-artifacts.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/release/shared-commands/download-build-artifacts.js b/scripts/release/shared-commands/download-build-artifacts.js index 18c2b80543..a0837b01db 100644 --- a/scripts/release/shared-commands/download-build-artifacts.js +++ b/scripts/release/shared-commands/download-build-artifacts.js @@ -3,7 +3,7 @@ const {join} = require('path'); const theme = require('../theme'); const {exec} = require('child-process-promise'); -const {existsSync} = require('fs'); +const {existsSync, readFileSync} = require('fs'); const {logPromise} = require('../utils'); if (process.env.GH_TOKEN == null) { @@ -80,7 +80,7 @@ async function getArtifact(workflowRunId, artifactName) { return artifact; } -async function processArtifact(artifact, releaseChannel) { +async function processArtifact(artifact, commit, releaseChannel) { // Download and extract artifact const cwd = join(__dirname, '..', '..', '..'); await exec(`rm -rf ./build`, {cwd}); @@ -117,6 +117,14 @@ async function processArtifact(artifact, releaseChannel) { await exec(`cp -r ./build/${sourceDir} ./build/node_modules`, { cwd, }); + + // Validate artifact + const buildSha = readFileSync('./build/COMMIT_SHA', 'utf8'); + if (buildSha !== commit) { + throw new Error( + `Requested commit sha does not match downloaded artifact. Expected: ${commit}, got: ${buildSha}` + ); + } } async function downloadArtifactsFromGitHub(commit, releaseChannel) { @@ -141,7 +149,7 @@ async function downloadArtifactsFromGitHub(commit, releaseChannel) { workflowRun.id, 'artifacts_combined' ); - await processArtifact(artifact, releaseChannel); + await processArtifact(artifact, commit, releaseChannel); return; } else { console.log(