From c9f7e39d37e5ce228069d22547a62e5838ce5fd6 Mon Sep 17 00:00:00 2001 From: Maxime Desroches Date: Fri, 18 Oct 2024 19:12:43 -0700 Subject: [PATCH] jenkins: fix files diff (#33819) * fix diff * better * print * clean * this is groovy --- Jenkinsfile | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 42db027f328aac..737c68588c4d6d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -81,6 +81,7 @@ def deviceStage(String stageName, String deviceType, List extra_env, def steps) def extra = extra_env.collect { "export ${it}" }.join('\n'); def branch = env.BRANCH_NAME ?: 'master'; + def gitDiff = sh returnStdout: true, script: 'curl -s -H "Authorization: Bearer ${GITHUB_COMMENTS_TOKEN}" https://api.github.com/repos/commaai/openpilot/compare/master...${GIT_BRANCH} | jq .files[].filename', label: 'Getting changes' lock(resource: "", label: deviceType, inversePrecedence: true, variable: 'device_ip', quantity: 1, resourceSelectStrategy: 'random') { docker.image('ghcr.io/commaai/alpine-ssh').inside('--user=root') { @@ -91,9 +92,9 @@ def deviceStage(String stageName, String deviceType, List extra_env, def steps) device(device_ip, "git checkout", extra + "\n" + readFile("selfdrive/test/setup_device_ci.sh")) } steps.each { item -> - if (branch != "master" && item.size() == 3 && !hasPathChanged(item[2])) { + if (branch != "master" && item.size() == 3 && !hasPathChanged(gitDiff, item[2])) { println "Skipping ${item[0]}: no changes in ${item[2]}." - return; + return } else { device(device_ip, item[0], item[1]) } @@ -104,29 +105,13 @@ def deviceStage(String stageName, String deviceType, List extra_env, def steps) } } -@NonCPS -def hasPathChanged(List paths) { - changedFiles = [] - for (changeLogSet in currentBuild.changeSets) { - for (entry in changeLogSet.getItems()) { - for (file in entry.getAffectedFiles()) { - changedFiles.add(file.getPath()) - } - } - } - - env.CHANGED_FILES = changedFiles.join(" ") - if (currentBuild.number > 1) { - env.CHANGED_FILES += currentBuild.previousBuild.getBuildVariables().get("CHANGED_FILES") - } - +def hasPathChanged(String gitDiff, List paths) { for (path in paths) { - if (env.CHANGED_FILES.contains(path)) { - return true; + if (gitDiff.contains(path)) { + return true } } - - return false; + return false } def setupCredentials() {