Fix copying MODULE.bazel with no write permission (#1844)
Addressing
https://github.com/bazelbuild/bazel-central-registry/pull/1265#issuecomment-1878530215
diff --git a/buildkite/bazel-central-registry/bcr_presubmit.py b/buildkite/bazel-central-registry/bcr_presubmit.py
index 2fe8c9c..60289d2 100755
--- a/buildkite/bazel-central-registry/bcr_presubmit.py
+++ b/buildkite/bazel-central-registry/bcr_presubmit.py
@@ -237,7 +237,11 @@
# Make sure the checked-in MODULE.bazel file is used.
checked_in_module_dot_bazel = get_module_dot_bazel(module_name, module_version)
bazelci.eprint("\n* Copy checked-in MODULE.bazel file to source root:\n%s\n" % read(checked_in_module_dot_bazel))
- shutil.copy(checked_in_module_dot_bazel, source_root.joinpath("MODULE.bazel"))
+ module_dot_bazel = source_root.joinpath("MODULE.bazel")
+ # In case the existing MODULE.bazel has no write permission.
+ if module_dot_bazel.exists():
+ os.remove(module_dot_bazel)
+ shutil.copy(checked_in_module_dot_bazel, module_dot_bazel)
# Generate the presubmit.yml file for the test module, it should be the content under "bcr_test_module"
orig_presubmit = yaml.safe_load(open(get_presubmit_yml(module_name, module_version), "r"))