From 958e531cc54b944476f5d15986959741dea4f996 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Tue, 19 Nov 2024 02:19:56 -0800 Subject: [PATCH] ci: always build images when core ci files change (#15229) --- .buildkite/ci.mjs | 21 +++++++++++++++++++-- scripts/utils.mjs | 6 +++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.buildkite/ci.mjs b/.buildkite/ci.mjs index 4901c7b6ce5594..5b59f897618ea5 100755 --- a/.buildkite/ci.mjs +++ b/.buildkite/ci.mjs @@ -664,9 +664,9 @@ async function main() { let changedFiles; if (!isFork() && !isMainBranch()) { console.log("Checking changed files..."); - const baseRef = getCommit(); + const baseRef = lastBuild?.commit_id || getTargetBranch() || getMainBranch(); console.log(" - Base Ref:", baseRef); - const headRef = lastBuild?.commit_id || getTargetBranch() || getMainBranch(); + const headRef = getCommit(); console.log(" - Head Ref:", headRef); changedFiles = await getChangedFiles(undefined, baseRef, headRef); @@ -684,6 +684,7 @@ async function main() { console.log("Checking if CI should be forced..."); let forceBuild; + let ciFileChanged; { const message = getCommitMessage(); const match = /\[(force ci|ci force|ci force build)\]/i.exec(message); @@ -692,6 +693,13 @@ async function main() { console.log(" - Yes, because commit message contains:", reason); forceBuild = true; } + for (const coref of [".buildkite/ci.mjs", "scripts/utils.mjs", "scripts/bootstrap.sh", "scripts/machine.mjs"]) { + if (changedFiles.includes(coref)) { + console.log(" - Yes, because the list of changed files contains:", coref); + forceBuild = true; + ciFileChanged = true; + } + } } console.log("Checking if CI should be skipped..."); @@ -719,6 +727,10 @@ async function main() { console.log(" - Yes, because commit message contains:", reason); buildImages = true; } + if (ciFileChanged) { + console.log(" - Yes, because a core CI file changed"); + buildImages = true; + } } console.log("Checking if CI should publish images..."); @@ -732,6 +744,11 @@ async function main() { publishImages = true; buildImages = true; } + if (ciFileChanged && isMainBranch()) { + console.log(" - Yes, because a core CI file changed and this is main branch"); + publishImages = true; + buildImages = true; + } } console.log("Checking if build should be skipped..."); diff --git a/scripts/utils.mjs b/scripts/utils.mjs index 41196942b0ea20..5f2f2ee3c35687 100755 --- a/scripts/utils.mjs +++ b/scripts/utils.mjs @@ -898,10 +898,10 @@ export function which(command, options = {}) { */ export async function getChangedFiles(cwd, base, head) { const repository = getRepository(cwd); - base ||= getCommit(cwd); - head ||= `${base}^1`; + head ||= getCommit(cwd); + base ||= `${head}^1`; - const url = `https://api.github.com/repos/${repository}/compare/${head}...${base}`; + const url = `https://api.github.com/repos/${repository}/compare/${base}...${head}`; const { error, body } = await curl(url, { json: true }); if (error) {