Skip to content

Commit

Permalink
Finish git
Browse files Browse the repository at this point in the history
  • Loading branch information
aBozowski committed Jun 1, 2022
1 parent 23ca784 commit cac8616
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 123 deletions.
35 changes: 18 additions & 17 deletions examples/chef/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,32 @@ def check_python_version() -> None:


def check_zap(master=False) -> str:
"""Produces hash of ZAP submodule in branch master
This will need to be replaced with stateful shell once it supports output
The branch should be taken as a parameter
Old code to show intent:
# git_cmd = ["git", "ls-tree", "master", "third_party/zap/repo"]
# zap_commit = str(subprocess.check_output(git_cmd, cwd=_REPO_BASE_PATH))
# zap_commit = zap_commit.split(" ")[2]
# zap_commit = zap_commit[:zap_commit.index("\\")]
"""Produces hash of ZAP submodule
Args:
master: check branch master instead of current branch
Returns:
SHA of zap submodule
"""
shell.run_cmd(f"cd {_CHIP_ROOT}")
shell.run_cmd(f"cd {_REPO_BASE_PATH}")
if master:
shell.run_cmd(f"git fetch master")
branch = "master"
else:
branch = shell.run_cmd("git rev-parse --abbrev-ref HEAD", return_cmd_output=True)
zap_commit = shell.run_cmd(f"git ls-tree {branch} third_party/zap/repo")
branch = shell.run_cmd("git rev-parse --abbrev-ref HEAD",
return_cmd_output=True).replace("\n", "")
command = f"git ls-tree {branch} third_party/zap/repo"
zap_commit = shell.run_cmd(command, return_cmd_output=True)
zap_commit = zap_commit.split(" ")[2]
zap_commit = zap_commit[:zap_commit.index("\t")]
flush_print(f"zap commit: {zap_commit}")
return zap_commit


def generate_device_manifest(
include_zap_submod: bool = False,
write_manifest_file: bool = False) -> Dict[str, Any]:
write_manifest_file: bool = False,
zap_check_master: bool = False) -> Dict[str, Any]:
"""Produces dictionary containing md5 of device dir zap files.
Args:
Expand All @@ -147,10 +150,7 @@ def generate_device_manifest(
with open(device_zzz_md5_file, "w+", encoding="utf-8") as md5file:
md5file.write(device_file_md5)
if include_zap_submod:
if options.validate_zzz:
ci_manifest["zap_commit"] = check_zap(master=True)
elif options.generate_zzz:
ci_manifest["zap_commit"] = check_zap()
ci_manifest["zap_commit"] = check_zap(master=zap_check_master)
if write_manifest_file:
with open(_CI_MANIFEST_FILE_NAME, "w+", encoding="utf-8") as ci_manifest_file:
ci_manifest_file.write(json.dumps(ci_manifest, indent=4)+"\n")
Expand Down Expand Up @@ -296,7 +296,8 @@ def main(argv: Sequence[str]) -> None:
git add {_CHEF_ZZZ_ROOT}
git add {_CI_MANIFEST_FILE_NAME}
Ensure you are running with the latest version of ZAP from master!""")
ci_manifest = generate_device_manifest(include_zap_submod=True)
ci_manifest = generate_device_manifest(include_zap_submod=True,
zap_check_master=True)
with open(_CI_MANIFEST_FILE_NAME, "r", encoding="utf-8") as ci_manifest_file:
cached_manifest = json.loads(ci_manifest_file.read())
cached_device_manifest = cached_manifest["devices"]
Expand Down
2 changes: 1 addition & 1 deletion examples/chef/ci_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"devices": {
"lighting-app": "81a1262e611fab1a71ac4129b91cec0f"
},
"zap_commit": "TEMP DISABLED"
"zap_commit": "6594a9257ce96ee6d852eed052939849b31259fc"
}
Loading

0 comments on commit cac8616

Please sign in to comment.