Skip to content

Commit

Permalink
jenkins: fix files diff (commaai#33819)
Browse files Browse the repository at this point in the history
* fix diff

* better

* print

* clean

* this is groovy
  • Loading branch information
maxime-desroches authored Oct 19, 2024
1 parent 0ec1c87 commit c9f7e39
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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])
}
Expand All @@ -104,29 +105,13 @@ def deviceStage(String stageName, String deviceType, List extra_env, def steps)
}
}

@NonCPS
def hasPathChanged(List<String> 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<String> 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() {
Expand Down

0 comments on commit c9f7e39

Please sign in to comment.