mirror of https://github.com/mongodb/mongo
SERVER-78687 Set up copybara syncing between 10gen/mongo and 10gen/mongo-copybara
(cherry picked from commit750406e4af) SERVER-81377 Adapt sync to allow copybara failure when there are no new commits to sync (cherry picked from commit032b931e4c)
This commit is contained in:
parent
40c22ee008
commit
c7f75d0616
|
|
@ -0,0 +1,79 @@
|
|||
"""Module for syncing a repo with Copybara and setting up configurations."""
|
||||
import subprocess
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def run_command(command): # noqa: D406,D407
|
||||
"""
|
||||
Execute a shell command and return its standard output (`stdout`).
|
||||
|
||||
Args:
|
||||
command (str): The shell command to be executed.
|
||||
|
||||
Returns:
|
||||
str: The standard output of the executed command.
|
||||
|
||||
Raises:
|
||||
subprocess.CalledProcessError: If the command execution fails.
|
||||
|
||||
"""
|
||||
try:
|
||||
return subprocess.run(command, shell=True, check=True, text=True,
|
||||
capture_output=True).stdout
|
||||
except subprocess.CalledProcessError as err:
|
||||
print(f"Error while executing: '{command}'.\n{err}\nStandard Error: {err.stderr}")
|
||||
raise
|
||||
|
||||
|
||||
def create_mongodb_bot_gitconfig():
|
||||
"""Create the mongodb-bot.gitconfig file with the desired content."""
|
||||
|
||||
content = """
|
||||
[user]
|
||||
name = MongoDB Bot
|
||||
email = mongo-bot@mongodb.com
|
||||
"""
|
||||
|
||||
gitconfig_path = os.path.expanduser("~/mongodb-bot.gitconfig")
|
||||
|
||||
with open(gitconfig_path, 'w') as file:
|
||||
file.write(content)
|
||||
|
||||
print("mongodb-bot.gitconfig file created.")
|
||||
|
||||
|
||||
def main():
|
||||
"""Clone the Copybara repo, build its Docker image, and set up and run migrations."""
|
||||
# Check if the copybara directory already exists
|
||||
if os.path.exists('copybara'):
|
||||
print("Copybara directory already exists.")
|
||||
else:
|
||||
run_command("git clone https://github.com/10gen/copybara.git")
|
||||
|
||||
# Navigate to the Copybara directory and build the Copybara Docker image
|
||||
run_command("cd copybara && docker build --rm -t copybara .")
|
||||
|
||||
# Create the mongodb-bot.gitconfig file as necessary.
|
||||
create_mongodb_bot_gitconfig()
|
||||
|
||||
# Set up the Docker command and execute it
|
||||
current_dir = os.getcwd()
|
||||
|
||||
docker_cmd = [
|
||||
"docker run", "-v ~/.ssh:/root/.ssh", "-v ~/mongodb-bot.gitconfig:/root/.gitconfig",
|
||||
f'-v "{current_dir}/copybara.staging.sky":/usr/src/app/copy.bara.sky',
|
||||
"-e COPYBARA_CONFIG='copy.bara.sky'", "-e COPYBARA_SUBCOMMAND='migrate'",
|
||||
"-e COPYBARA_OPTIONS='-v'", "copybara copybara"
|
||||
]
|
||||
|
||||
try:
|
||||
run_command(" ".join(docker_cmd))
|
||||
except subprocess.CalledProcessError as err:
|
||||
# Handle the specific error case for "No new changes..." between two repos
|
||||
if "No new changes to import for resolved ref" not in str(err.stderr):
|
||||
raise
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
# This configuration is for migrating code from one Git repository to another using Copybara.
|
||||
# It selectively copies content, excluding specific paths and preserving authorship.
|
||||
sourceUrl = "git@github.com:10gen/mongo.git"
|
||||
destinationUrl = "git@github.com:10gen/mongo-copybara.git"
|
||||
|
||||
core.workflow(
|
||||
name = "default",
|
||||
origin = git.origin(
|
||||
url = sourceUrl,
|
||||
ref = "v4.4",
|
||||
# VersionSelector
|
||||
),
|
||||
destination = git.destination(
|
||||
url = destinationUrl,
|
||||
fetch = "v4.4",
|
||||
push = "v4.4",
|
||||
),
|
||||
# Change path to the folder you want to publish publicly
|
||||
origin_files = glob(["**"], exclude=["src/mongo/db/modules/**"]),
|
||||
|
||||
authoring = authoring.pass_thru("MongoDB <mongodb@mongodb.com>"),
|
||||
|
||||
mode = "ITERATIVE",
|
||||
# Change the path here to the folder you want to publish publicly
|
||||
# transformations = [
|
||||
# core.move("path/to/folder/you/want/exported", ""),
|
||||
# ],
|
||||
)
|
||||
|
|
@ -3710,6 +3710,18 @@ functions:
|
|||
files:
|
||||
- wiki_page_location.json
|
||||
|
||||
"sync repo with copybara":
|
||||
- command: shell.exec
|
||||
params:
|
||||
binary: bash
|
||||
add_expansions_to_env: true
|
||||
working_dir: src
|
||||
script: |
|
||||
set -o verbose
|
||||
set -o errexit
|
||||
|
||||
${activate_virtualenv}
|
||||
$python buildscripts/sync_repo_with_copybara.py
|
||||
|
||||
# Pre task steps
|
||||
pre:
|
||||
|
|
@ -5320,6 +5332,15 @@ tasks:
|
|||
- func: "setup jstestfuzz"
|
||||
- func: "lint fuzzer sanity all"
|
||||
|
||||
- name: sync_repo_with_copybara
|
||||
tags: []
|
||||
commands:
|
||||
- command: manifest.load
|
||||
- *git_get_project
|
||||
- *set_task_expansion_macros
|
||||
- *set_up_virtualenv
|
||||
- func: "sync repo with copybara"
|
||||
|
||||
## integration test suites ##
|
||||
|
||||
- <<: *task_template
|
||||
|
|
@ -12450,3 +12471,18 @@ buildvariants:
|
|||
distros:
|
||||
- rhel62-large
|
||||
- name: validate_commit_message
|
||||
|
||||
###########################################
|
||||
# Copybara buildvariants #
|
||||
###########################################
|
||||
|
||||
- name: copybara-sync-between-repos
|
||||
modules:
|
||||
- enterprise
|
||||
display_name: "* Copybara Sync Between Repos"
|
||||
cron: "0 4 * * *" # From the ${project_nightly_cron} parameter.
|
||||
run_on:
|
||||
- ubuntu2204-small
|
||||
stepback: false
|
||||
tasks:
|
||||
- name: sync_repo_with_copybara
|
||||
|
|
|
|||
Loading…
Reference in New Issue