Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
changes to ensure zip does not include undesired start directories
Browse files Browse the repository at this point in the history
  • Loading branch information
ahernandez411 committed Dec 19, 2023
1 parent 8c9ae7e commit 2d6716a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ action_tester.py
.vscode
*.zip
temp
__pycache__
34 changes: 30 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,38 @@ runs:
# This python code has been written inline, instead of a standalone file, so it
# can be run without running into file system issues finding files and paths.
def get_root_paths(path: str) -> list:
root_paths = []
if isinstance(path, list):
for item in path:
if item.startswith("!"):
continue
elif os.path.isdir(item):
root_paths.append(item)
else:
root_paths.append(os.path.dirname(item))
else:
if os.path.isdir(path):
root_paths.append(path)
else:
root_paths.append(os.path.dirname(path))
return root_paths
def get_leading_path(current_path: str, root_paths: list) -> str:
for root_path in root_paths:
if current_path.startswith(root_path):
return root_path
def get_paths(path: str, list_type: str) -> list:
paths = []
print("")
print(f"Discover all {list_type} paths from {', '.join(path)}")
type_excluded = "excluded"
if isinstance(path, list):
for item in path:
path_value = None
# excluded paths start with !
if list_type == "excluded":
if list_type == type_excluded:
if item.startswith("!"):
path_value = item[1:].strip()
else:
Expand Down Expand Up @@ -81,6 +104,7 @@ runs:
file_path = os.environ['FILE_PATH'].splitlines()
print(f"- Path: {', '.join(file_path)}")
root_paths = get_root_paths(file_path)
included_paths = get_paths(file_path, list_type="included")
excluded_paths = get_paths(file_path, list_type="excluded")
Expand All @@ -89,9 +113,11 @@ runs:
print("")
print(f"Creating {zip_name}:")
for path in included_paths:
if path not in excluded_paths:
print(f"- Adding {path}")
zip_writer.write(path)
if path not in excluded_paths:
leading_path = get_leading_path(path, root_paths)
zip_path = os.path.relpath(path, start=leading_path)
print(f"- Adding {zip_path}")
zip_writer.write(path, arcname=zip_path)
print("")
print(f"DONE: Created {zip_name}.")
Expand Down

0 comments on commit 2d6716a

Please sign in to comment.