mirror of https://github.com/mongodb/mongo
SERVER-94187 Switch git ssh to https in copybara (#27212)
GitOrigin-RevId: b7709884d7fd79ed7df2e80e1bcbbf0b3b95e8c9
This commit is contained in:
parent
7cd17df2fe
commit
1af38d0284
|
|
@ -1,5 +1,6 @@
|
||||||
"""Module for syncing a repo with Copybara and setting up configurations."""
|
"""Module for syncing a repo with Copybara and setting up configurations."""
|
||||||
import argparse
|
import argparse
|
||||||
|
import fileinput
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -112,25 +113,56 @@ def main():
|
||||||
# Read configurations
|
# Read configurations
|
||||||
expansions = read_config_file(args.expansion_file)
|
expansions = read_config_file(args.expansion_file)
|
||||||
|
|
||||||
access_token_copybara_syncer = get_installation_access_token(
|
token_mongodb_mongo = get_installation_access_token(
|
||||||
expansions["app_id_copybara_syncer"], expansions["private_key_copybara_syncer"],
|
expansions["app_id_copybara_syncer"],
|
||||||
expansions["installation_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"],
|
||||||
|
)
|
||||||
|
|
||||||
|
tokens_map = {
|
||||||
|
"https://github.com/mongodb/mongo.git": token_mongodb_mongo,
|
||||||
|
"https://github.com/10gen/mongo.git": token_10gen_mongo,
|
||||||
|
}
|
||||||
|
|
||||||
# Create the mongodb-bot.gitconfig file as necessary.
|
# Create the mongodb-bot.gitconfig file as necessary.
|
||||||
create_mongodb_bot_gitconfig()
|
create_mongodb_bot_gitconfig()
|
||||||
|
|
||||||
current_dir = os.getcwd()
|
current_dir = os.getcwd()
|
||||||
git_destination_url_with_token = f"https://x-access-token:{access_token_copybara_syncer}@github.com/mongodb/mongo.git"
|
config_file = f"{current_dir}/copy.bara.sky"
|
||||||
|
|
||||||
|
# Overwrite repo urls in copybara config in-place
|
||||||
|
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
|
||||||
|
|
||||||
|
if token:
|
||||||
|
print(
|
||||||
|
line.replace(
|
||||||
|
"https://github.com",
|
||||||
|
f"https://x-access-token:{token}@github.com",
|
||||||
|
),
|
||||||
|
end="",
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
print(line, end="")
|
||||||
|
|
||||||
# Set up the Docker command and execute it
|
# Set up the Docker command and execute it
|
||||||
docker_cmd = [
|
docker_cmd = [
|
||||||
"docker run",
|
"docker run",
|
||||||
"-v ~/.ssh:/root/.ssh",
|
"-v ~/.ssh:/root/.ssh",
|
||||||
"-v ~/mongodb-bot.gitconfig:/root/.gitconfig",
|
"-v ~/mongodb-bot.gitconfig:/root/.gitconfig",
|
||||||
f'-v "{current_dir}/copy.bara.sky":/usr/src/app/copy.bara.sky',
|
f'-v "{config_file}":/usr/src/app/copy.bara.sky',
|
||||||
"-e COPYBARA_CONFIG='copy.bara.sky'",
|
"-e COPYBARA_CONFIG='copy.bara.sky'",
|
||||||
"-e COPYBARA_SUBCOMMAND='migrate'",
|
"-e COPYBARA_SUBCOMMAND='migrate'",
|
||||||
f"-e COPYBARA_OPTIONS='-v --git-destination-url={git_destination_url_with_token}'",
|
"-e COPYBARA_OPTIONS='-v'",
|
||||||
"copybara copybara",
|
"copybara copybara",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
# sourceUrl = "/path/to/source"
|
# sourceUrl = "/path/to/source"
|
||||||
# destinationUrl = "/path/to/dest"
|
# destinationUrl = "/path/to/dest"
|
||||||
|
|
||||||
sourceUrl = "git@github.com:10gen/mongo.git"
|
sourceUrl = "https://github.com/10gen/mongo.git"
|
||||||
destinationUrl = "git@github.com:mongodb/mongo.git"
|
destinationUrl = "https://github.com/mongodb/mongo.git"
|
||||||
|
|
||||||
core.workflow(
|
core.workflow(
|
||||||
name = "default",
|
name = "default",
|
||||||
|
|
@ -25,7 +25,7 @@ core.workflow(
|
||||||
mode = "ITERATIVE",
|
mode = "ITERATIVE",
|
||||||
transformations = [
|
transformations = [
|
||||||
# (^.*?) - matches the first line (without the newline char)
|
# (^.*?) - matches the first line (without the newline char)
|
||||||
# \n - matches the first newline (or nothing at all if there is no newline). If there is no match then nopthing happens
|
# \n - matches the first newline (or nothing at all if there is no newline). If there is no match then nothing happens
|
||||||
# ((\n|.)*) - matches everything after
|
# ((\n|.)*) - matches everything after
|
||||||
# Overall, this copies only the first line of the commit rather than the body
|
# Overall, this copies only the first line of the commit rather than the body
|
||||||
metadata.scrubber("(^.*?)\n((\n|.)*)", replacement = "$1"),
|
metadata.scrubber("(^.*?)\n((\n|.)*)", replacement = "$1"),
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,13 @@
|
||||||
# This configuration is for migrating code from one Git repository to another using Copybara.
|
# This configuration is for migrating code from one Git repository to another using Copybara.
|
||||||
# It selectively copies content, excluding specific paths and preserving authorship.
|
# It selectively copies content, excluding specific paths and preserving authorship.
|
||||||
sourceUrl = "git@github.com:10gen/mongo.git"
|
sourceUrl = "https://github.com/10gen/mongo.git"
|
||||||
destinationUrl = "git@github.com:10gen/mongo-copybara.git"
|
destinationUrl = "https://github.com/10gen/mongo-copybara.git"
|
||||||
|
|
||||||
core.workflow(
|
core.workflow(
|
||||||
name = "default",
|
name = "default",
|
||||||
origin = git.origin(
|
origin = git.origin(
|
||||||
url = sourceUrl,
|
url = sourceUrl,
|
||||||
ref = "v7.0",
|
ref = "v7.0",
|
||||||
# VersionSelector
|
|
||||||
),
|
),
|
||||||
destination = git.destination(
|
destination = git.destination(
|
||||||
url = destinationUrl,
|
url = destinationUrl,
|
||||||
|
|
@ -22,7 +21,11 @@ core.workflow(
|
||||||
|
|
||||||
mode = "ITERATIVE",
|
mode = "ITERATIVE",
|
||||||
# Change the path here to the folder you want to publish publicly
|
# Change the path here to the folder you want to publish publicly
|
||||||
# transformations = [
|
transformations = [
|
||||||
# core.move("path/to/folder/you/want/exported", ""),
|
# (^.*?) - matches the first line (without the newline char)
|
||||||
# ],
|
# \n - matches the first newline (or nothing at all if there is no newline). If there is no match then nothing happens
|
||||||
|
# ((\n|.)*) - matches everything after
|
||||||
|
# Overall, this copies only the first line of the commit rather than the body
|
||||||
|
metadata.scrubber("(^.*?)\n((\n|.)*)", replacement = "$1"),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -4611,6 +4611,7 @@ tasks:
|
||||||
|
|
||||||
- name: sync_repo_with_copybara
|
- name: sync_repo_with_copybara
|
||||||
tags: []
|
tags: []
|
||||||
|
patchable: false
|
||||||
commands:
|
commands:
|
||||||
- command: manifest.load
|
- command: manifest.load
|
||||||
- func: "git get project and add git tag"
|
- func: "git get project and add git tag"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue