From 82255ad39e9d3fb206ca1f137852efe69f6eba56 Mon Sep 17 00:00:00 2001 From: Zack Winter <3457246+zackwintermdb@users.noreply.github.com> Date: Tue, 11 Nov 2025 18:26:31 -0800 Subject: [PATCH] SERVER-113773 Regenerate copybara access token after finishing the dry run (#43858) GitOrigin-RevId: 9ac7cb334a9d72a30fb32d2438c69eb5d5215c14 --- buildscripts/sync_repo_with_copybara.py | 42 +++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/buildscripts/sync_repo_with_copybara.py b/buildscripts/sync_repo_with_copybara.py index 330b954aca4..f26dceaea6f 100644 --- a/buildscripts/sync_repo_with_copybara.py +++ b/buildscripts/sync_repo_with_copybara.py @@ -650,6 +650,48 @@ def main(): error_message = f"Copybara failed with error: {err.returncode}" handle_failure(expansions, error_message, err.output) + # Write newly generated tokens to the config file to make sure + # the token isn't expired by the time the dry-run finishes + token_mongodb_mongo = get_installation_access_token( + expansions["app_id_copybara_syncer"], + expansions["private_key_copybara_syncer"], + expansions["installation_id_copybara_syncer"], + ) + token_10gen_mongo = get_installation_access_token( + expansions["app_id_copybara_syncer_10gen"], + expansions["private_key_copybara_syncer_10gen"], + expansions["installation_id_copybara_syncer_10gen"], + ) + + REDACTED_STRINGS += [token_mongodb_mongo, token_10gen_mongo] + + tokens_map = { + "mongodb/mongo.git": token_mongodb_mongo, + "10gen/mongo.git": token_10gen_mongo, + "10gen/mongo-copybara.git": token_10gen_mongo, + } + + with fileinput.FileInput(config_file, inplace=True) as file: + for line in file: + token = None + + for repo, value in tokens_map.items(): + if repo in line: + token = value + break + + if token: + print( + re.sub( + r"https://x-access-token:.*@github.com", + f"https://x-access-token:{token}@github.com", + line, + ), + end="", + ) + else: + print(line, end="") + # dry run successful, time to push try: run_command(" ".join(docker_cmd + test_args))