Skip to content

Commit

Permalink
ci: always build images when core ci files change (#15229)
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro authored Nov 19, 2024
1 parent 206d2ed commit 958e531
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
21 changes: 19 additions & 2 deletions .buildkite/ci.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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...");
Expand Down Expand Up @@ -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...");
Expand All @@ -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...");
Expand Down
6 changes: 3 additions & 3 deletions scripts/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 958e531

Please sign in to comment.