Skip to content

Commit

Permalink
fix(hardware-testing): Improve hw testing patch update (#12964)
Browse files Browse the repository at this point in the history
* add argument to update-patches-gravimetric make target to account for non-edge branches

* add a script to automatically do the patching magic

* update readme

* format/lint
  • Loading branch information
ryanthecoder committed Jun 22, 2023
1 parent 1e17f1c commit e84a5b4
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 12 deletions.
9 changes: 5 additions & 4 deletions hardware-testing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,14 @@ apply-patches-gravimetric:
remove-patches-gravimetric:
cd ../ && git apply ./hardware-testing/hardware_testing/gravimetric/overrides/*.patch --reverse --allow-empty

upstream ?= origin/edge
.PHONY: update-patches-gravimetric
update-patches-gravimetric:
rm ./hardware_testing/gravimetric/overrides/*.patch
cd ../ && git diff origin/edge ./hardware/** > ./hardware-testing/hardware_testing/gravimetric/overrides/hardware.patch
cd ../ && git diff origin/edge ./api/** > ./hardware-testing/hardware_testing/gravimetric/overrides/api.patch
cd ../ && git diff origin/edge ./shared-data/** > ./hardware-testing/hardware_testing/gravimetric/overrides/shared-data.patch
cd ../ && git diff origin/edge ./robot-server/** > ./hardware-testing/hardware_testing/gravimetric/overrides/robot-server.patch
cd ../ && git diff $(upstream) ./hardware/** > ./hardware-testing/hardware_testing/gravimetric/overrides/hardware.patch
cd ../ && git diff $(upstream) ./api/** > ./hardware-testing/hardware_testing/gravimetric/overrides/api.patch
cd ../ && git diff $(upstream) ./shared-data/** > ./hardware-testing/hardware_testing/gravimetric/overrides/shared-data.patch
cd ../ && git diff $(upstream) ./robot-server/** > ./hardware-testing/hardware_testing/gravimetric/overrides/robot-server.patch
$(MAKE) remove-patches-gravimetric

.PHONY: push-photometric-ot2
Expand Down
13 changes: 5 additions & 8 deletions hardware-testing/hardware_testing/gravimetric/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ If you would like to remove those patches you can run `make remove-patches-gravi

### Updating the Patches

In order to change the patches for testing first make sure you have checked out your branch
use the `make apply-patches-gravimetric` to load the old changes first
Now you can edit the source code and when you are ready you can run `make update-patches-gravimetric`

the changes you made will now be updated in the hardware_testing/gravimetric/overrides/\*.patch files
and you can commit those changes to your branch with a clean source code.
the `make update-patches-gravimetric` will remove the patches so after creating your commit simply run
`make apply-patches-gravimetric` again to resume working on your changes.
There is a script that will automatically update the patches. from the base of the repository run
`python hardware-testing/hardware_testing/scripts/update_patches.py`
if you ware merging your branch onto something other than `origin/edge` you can use the following form
and substitute `internal-release` for whatever branch you're merging in to.
`python hardware-testing/hardware_testing/scripts/update_patches.py --upstream origin/internal-release`

## Photometric tests

Expand Down
74 changes: 74 additions & 0 deletions hardware-testing/hardware_testing/scripts/update_patches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env python3
"""Script for updating the gravimetric patches."""
import argparse
import subprocess
from typing import List


def _run_cmd(cmd_str_list: List[str]) -> str:
print(f"running: {' '.join(cmd_str_list)}")
result = subprocess.run(cmd_str_list, check=True, stdout=subprocess.PIPE)
print(result.stdout.decode("utf-8"))
return result.stdout.decode("utf-8")


def _get_current_branch() -> str:
return _run_cmd("git rev-parse --abbrev-ref HEAD".split())


def _get_current_hash() -> str:
return _run_cmd("git rev-parse --short HEAD".split())


def _update_patches(upstream: str) -> None:
branch = _get_current_branch()
cur_hash = _get_current_hash()
_run_cmd(f"git checkout {upstream}".split())
_run_cmd("make -C hardware-testing apply-patches-gravimetric".split())
_run_cmd("git add -A".split())
_run_cmd(
["git", "commit", "-m", "temp commit, will reverted (can be rebased away)"]
)
auto_hash = _get_current_hash()
_run_cmd(f"git checkout {branch}".split())
_run_cmd(f"git cherry-pick --strategy=recursive -X theirs {auto_hash}".split())
cp_hash = _get_current_hash()
_run_cmd(
f"make -C hardware-testing update-patches-gravimetric upstream={cur_hash}".split()
)
_run_cmd(
"git add hardware-testing/hardware_testing/gravimetric/overrides/*".split()
)
_run_cmd(
[
"git",
"commit",
"-m",
"chore(hardware-testing): update gravimetric patch files",
]
)
_run_cmd("git checkout -f".split())
_run_cmd(f"git revert {cp_hash} --no-edit".split())
revert_hash = _get_current_hash()
print("Patches applyed, if you'd like to clean up the git history you can run:")
print(f"git rebase -i {upstream}")
print(f"and delete the lines with the shortsha \n{cp_hash}and \n{revert_hash}")


def _main() -> None:
parser = argparse.ArgumentParser(
prog="update patches",
description="updates the patches for hardware testing",
)
parser.add_argument(
"--upstream",
type=str,
default="origin/edge",
help="upstream branch if not edge",
)
args = parser.parse_args()
return _update_patches(args.upstream)


if __name__ == "__main__":
_main()

0 comments on commit e84a5b4

Please sign in to comment.