Skip to content

Commit c9b3490

Browse files
author
Marius Posta
authored
airbyte-ci: improve installer version switching behavior (#43963)
1 parent 9e4ff9e commit c9b3490

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

airbyte-ci/connectors/pipelines/pipelines/external_scripts/airbyte_ci_install.py

+17-12
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,31 @@ def main(version: str = "latest") -> None:
9090
destination_dir = os.path.expanduser("~/.local/bin")
9191
os.makedirs(destination_dir, exist_ok=True)
9292

93-
# Download the binary to a temporary folder
94-
with tempfile.TemporaryDirectory() as tmp_dir:
95-
tmp_file = os.path.join(tmp_dir, "airbyte-ci")
93+
# Set the path of the versioned binary
94+
versioned_path = os.path.join(destination_dir, f"airbyte-ci-{version}")
9695

96+
# If the version is not explicit, delete any existing versioned binary
97+
if version == "latest" and os.path.exists(versioned_path):
98+
os.remove(versioned_path)
99+
100+
# Download the versioned binary if it doesn't exist
101+
if not os.path.exists(versioned_path):
97102
# Download the file using urllib.request
98103
print(f"Downloading from {url}")
99104
ssl_context = get_ssl_context()
100-
with urllib.request.urlopen(url, context=ssl_context) as response, open(tmp_file, "wb") as out_file:
105+
with urllib.request.urlopen(url, context=ssl_context) as response, open(versioned_path, "wb") as out_file:
101106
shutil.copyfileobj(response, out_file)
102107

103-
# Check if the destination path is a symlink and delete it if it is
104-
destination_path = os.path.join(destination_dir, "airbyte-ci")
105-
if os.path.islink(destination_path):
106-
os.remove(destination_path)
108+
# Make the versioned binary executable
109+
os.chmod(versioned_path, 0o755)
107110

108-
# Copy the file from the temporary folder to the destination
109-
shutil.copy(tmp_file, destination_path)
111+
# Ensure that the destination path does not exist.
112+
destination_path = os.path.join(destination_dir, "airbyte-ci")
113+
if os.path.exists(destination_path):
114+
os.remove(destination_path)
110115

111-
# Make the binary executable
112-
os.chmod(destination_path, 0o755)
116+
# Symlink the versioned binary to the destination path
117+
os.symlink(versioned_path, destination_path)
113118

114119
# ASCII Art and Completion Message
115120
install_complete_message = f"""

0 commit comments

Comments
 (0)