From ec01c0912ced022d85a193cc4b225a7672682b9c Mon Sep 17 00:00:00 2001 From: Craig Condit Date: Thu, 15 Feb 2024 15:20:51 -0600 Subject: [PATCH] [YUNIKORN-2425] Use 'go mod edit' to replace internal module references Instead of manual file editing, use the go standard tooling to replace references to yunikorn-core and yunikorn-scheduler-interface in go.mod files. --- tools/build-release.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/tools/build-release.py b/tools/build-release.py index fba52aa..8331855 100755 --- a/tools/build-release.py +++ b/tools/build-release.py @@ -210,12 +210,15 @@ def update_dep_ref_k8shim(local_repo_path): mod_file = os.path.join(local_repo_path, "go.mod") if not os.path.isfile(mod_file): fail("k8shim go.mod does not exist") - with open(mod_file, "a") as file_object: - file_object.write("\n") - file_object.write("replace github.com/apache/yunikorn-core => ../core \n") - file_object.write( - "replace github.com/apache/yunikorn-scheduler-interface => ../scheduler-interface \n") - + path = os.getcwd() + os.chdir(local_repo_path) + command = ['go', 'mod', 'edit'] + command.extend(['-replace', 'github.com/apache/yunikorn-core=../core']) + command.extend(['-replace', 'github.com/apache/yunikorn-scheduler-interface=../scheduler-interface']) + retcode = subprocess.call(command) + if retcode: + fail("failed to update k8shim go.mod references") + os.chdir(path) # core depends on scheduler-interface def update_dep_ref_core(local_repo_path): @@ -223,10 +226,14 @@ def update_dep_ref_core(local_repo_path): mod_file = os.path.join(local_repo_path, "go.mod") if not os.path.isfile(mod_file): fail("core go.mod does not exist") - with open(mod_file, "a") as file_object: - file_object.write("\n") - file_object.write( - "replace github.com/apache/yunikorn-scheduler-interface => ../scheduler-interface \n") + path = os.getcwd() + os.chdir(local_repo_path) + command = ['go', 'mod', 'edit'] + command.extend(['-replace', 'github.com/apache/yunikorn-scheduler-interface=../scheduler-interface']) + retcode = subprocess.call(command) + if retcode: + fail("failed to update core go.mod references") + os.chdir(path) # update go mod in the repos