Skip to content

Commit

Permalink
Clone repos to work on
Browse files Browse the repository at this point in the history
Signed-off-by: Dean Roehrich <[email protected]>
  • Loading branch information
roehrich-hpe committed Aug 26, 2024
1 parent 979f6fd commit 1a7b1e3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
7 changes: 4 additions & 3 deletions tools/crd-bumper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ Clone a fresh copy of the repository that contains the CRDs and controllers, che
The following example will create a new API version `v1beta2` for the lustre-fs-operator repository, where `v1beta1` is the existing hub and `v1alpha1` is the most recent existing spoke. It begins by creating a new branch off "master" named `api-v1beta2`, where it will do all of its work.

```console
git clone [email protected]:NearNodeFlash/lustre-fs-operator.git
cd lustre-fs-operator
crd-bumper.py --most-recent-spoke v1alpha1 --prev-ver v1beta1 --new-ver v1beta2 all
[email protected]:NearNodeFlash/lustre-fs-operator.git
crd-bumper.py --repo $REPO --most-recent-spoke v1alpha1 --prev-ver v1beta1 --new-ver v1beta2 all
```

The repository with its new API will be found under a directory named `workingspace/lustre-fs-operator`.

The new `api-v1beta2` branch will have a series of commits showing a progression of steps. Some of these commit messages will have an **ACTION** comment describing something that must be manually verified, and possibly adjusted, before the tests will succeed.

### Verification
Expand Down
20 changes: 19 additions & 1 deletion tools/crd-bumper/crd-bumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from pkg.conversion_gen import ConversionGen
from pkg.make_cmd import MakeCmd

WORKING_DIR = "workingspace"

PARSER = argparse.ArgumentParser()
PARSER.add_argument(
"--prev-ver",
Expand All @@ -50,6 +52,13 @@
required=False,
help="If you have an existing, most recent spoke that is just before the version in --prev-ver, then tell me what it is.",
)
PARSER.add_argument(
"--repo",
"-r",
type=str,
required=True,
help="Git repository URL which has the APIs to be bumped.",
)
PARSER.add_argument(
"--branch",
"-b",
Expand Down Expand Up @@ -83,6 +92,13 @@
dest="nocommit",
help="Skip git-commit. Implies only one step.",
)
PARSER.add_argument(
"--workdir",
type=str,
required=False,
default=WORKING_DIR,
help=f"Name for working directory. All repos will be cloned below this directory. Default: {WORKING_DIR}.",
)

SUBPARSERS = PARSER.add_subparsers(help="COMMANDS", dest="cmd", required=True)

Expand Down Expand Up @@ -118,6 +134,9 @@ def main():
if args.dryrun or args.nocommit:
args.cmd = "step"

gitcli = GitCLI(args.dryrun, args.nocommit)
gitcli.clone_and_cd(args.repo, args.workdir)

project = Project(args.dryrun)
cgen = ConversionGen(
args.dryrun, project, args.prev_ver, args.new_ver, args.most_recent_spoke
Expand All @@ -126,7 +145,6 @@ def main():

validate_args(args, cgen)

gitcli = GitCLI(args.dryrun, args.nocommit)
if args.branch is None:
args.branch = f"api-{args.new_ver}"
if args.this_branch:
Expand Down
30 changes: 30 additions & 0 deletions tools/crd-bumper/pkg/git_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,33 @@ def expect_previous(self, next_operation, operation_order):
raise ValueError(
f"Operation {next_operation} wants to build on {expect_token}, but found that the previous operation was {prev_cmd_token}."
)

def clone_and_cd(self, repo, workdir):
"""Clone the specified repo and 'cd' into it."""

if os.path.isdir(workdir) is False:
os.mkdir(workdir)
os.chdir(workdir)

newdir = os.path.basename(repo).removesuffix(".git")
if os.path.isdir(newdir) is False:
cmd = f"git clone {repo}"
if self._dryrun:
print(f"Dryrun: {cmd}")
print(f"Dryrun: cd {newdir}")
else:
print(f"Run: {cmd}")
res = subprocess.run(
shlex.split(cmd),
capture_output=True,
text=True,
check=False,
)
if res.returncode != 0:
raise RuntimeError(f"Unable to clone repo {repo}: {res.stderr}")

if os.path.isdir(newdir) is False:
raise FileNotFoundError(
f"Expected to find directory ({newdir}) after clone."
)
os.chdir(newdir)

0 comments on commit 1a7b1e3

Please sign in to comment.