-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(move-stable): track the deployments (#526)
feat(move-stable): track the deployments Current state can be seen at https://github.com/packit/production-monorepo Reviewed-by: Laura Barcziová Reviewed-by: František Lachman <[email protected]> Reviewed-by: Matej Focko
- Loading branch information
Showing
1 changed file
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
STABLE_BRANCH: str = "stable" | ||
ROLLING_BRANCH: str = "main" | ||
DEFAULT_REPO_STORE: str = "move_stable_repositories" | ||
MONOREPO: str = "production-monorepo" | ||
|
||
# Copr settings | ||
COPR_OWNER, COPR_PROJECT = "packit", "packit-stable" | ||
|
@@ -80,6 +81,17 @@ def init(repo_store: str) -> None: | |
cwd=repo_store_path, | ||
) | ||
|
||
# clone the monorepo with references for tracking deployments | ||
subprocess.run( | ||
[ | ||
"git", | ||
"clone", | ||
"--recurse-submodules", | ||
f"[email protected]:{NAMESPACE}/{MONOREPO}.git", | ||
], | ||
cwd=repo_store_path, | ||
) | ||
|
||
|
||
@cli.command( | ||
short_help=f"Moves {STABLE_BRANCH} of requested repository interactively", | ||
|
@@ -112,7 +124,16 @@ def init(repo_store: str) -> None: | |
type=click.Path(exists=True, dir_okay=True, file_okay=False), | ||
help="Path to dir where the repositories are stored", | ||
) | ||
def move_repository(repository: str, remote: str, repo_store: str) -> None: | ||
@click.option( | ||
"--update-monorepo", | ||
default=True, | ||
show_default=True, | ||
type=click.BOOL, | ||
help=f"Update the monorepo with references to all {STABLE_BRANCH} branches", | ||
) | ||
def move_repository( | ||
repository: str, remote: str, repo_store: str, update_monorepo: bool | ||
) -> None: | ||
click.secho(f"==> Moving {repository}", fg="yellow") | ||
path_to_repository = Path(repo_store, repository).absolute() | ||
|
||
|
@@ -128,6 +149,7 @@ def move_repository(repository: str, remote: str, repo_store: str) -> None: | |
) | ||
return | ||
|
||
click.echo("===> Waiting for Copr dependencies") | ||
wait_for_copr_dependencies(repository, remote, repo_store) | ||
|
||
get_git_log(path_to_repository, remote, stable_hash, main_hash) | ||
|
@@ -140,6 +162,15 @@ def move_repository(repository: str, remote: str, repo_store: str) -> None: | |
push_stable_branch(path_to_repository, remote, new_stable_hash) | ||
click.echo() | ||
|
||
if update_monorepo: | ||
click.secho(f"===> Updating {repository}'s reference in monorepo", fg="yellow") | ||
update_monorepo( | ||
repo_store, | ||
remote, | ||
commit_msg=f"chore: production move of {repository}", | ||
repo=repository, | ||
) | ||
|
||
|
||
@cli.command( | ||
short_help=f"Moves all {STABLE_BRANCH}s interactively", | ||
|
@@ -188,9 +219,17 @@ def move_all(ctx, remote: str, repo_store: str) -> None: | |
|
||
for repository in REPOSITORIES: | ||
ctx.invoke( | ||
move_repository, repository=repository, remote=remote, repo_store=repo_store | ||
move_repository, | ||
repository=repository, | ||
remote=remote, | ||
repo_store=repo_store, | ||
update_monorepo=False, | ||
) | ||
|
||
# update monorepo | ||
click.secho(f"==> Updating references to {STABLE_BRANCH} in monorepo", fg="yellow") | ||
update_monorepo(repo_store, remote, commit_msg="chore: weekly deployment") | ||
|
||
ctx.invoke(create_blogpost, remote=remote, repo_store=repo_store) | ||
|
||
|
||
|
@@ -429,6 +468,34 @@ def wait_for_copr_dependencies(repository: str, remote: str, repo_store: str): | |
queue.append(item) | ||
|
||
|
||
def update_monorepo( | ||
repo_store: str, remote: str, commit_msg: str, repository: Optional[str] = None | ||
): | ||
update_command = ["git", "submodule", "update", "--remote"] | ||
path_to_monorepo = Path(repo_store, MONOREPO) | ||
|
||
if repository: | ||
update_command.append(repository) | ||
|
||
# update the references | ||
subprocess.run( | ||
update_command, | ||
cwd=path_to_monorepo, | ||
) | ||
|
||
# commit the changes | ||
subprocess.run( | ||
["git", "commit", "-a", "-S", "-m", commit_msg], | ||
cwd=path_to_monorepo, | ||
) | ||
|
||
# push the change | ||
subprocess.run( | ||
["git", "push", remote, "main"], | ||
cwd=path_to_monorepo, | ||
) | ||
|
||
|
||
@cli.command( | ||
short_help=f"Stalks Copr dependencies of a requested repository", | ||
help=f"""Wait for the Copr dependencies of REPOSITORY. | ||
|