Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CM-31141 - Zip onedir CLI to attach to GitHub releases #191

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions process_executable_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import hashlib
import os
import platform
import shutil
from pathlib import Path
from string import Template
from typing import List, Tuple, Union

_ARCHIVE_FORMAT = 'zip'
_HASH_FILE_EXT = '.sha256'
_OS_TO_CLI_DIST_TEMPLATE = {
'darwin': Template('cycode-mac$suffix$ext'),
Expand Down Expand Up @@ -125,6 +127,14 @@ def get_cli_hash_path(output_path: Path, is_onedir: bool) -> str:
return os.path.join(output_path, get_cli_hash_filename(is_onedir))


def get_cli_archive_filename(is_onedir: bool) -> str:
return get_cli_file_name(suffix=get_cli_file_suffix(is_onedir))


def get_cli_archive_path(output_path: Path, is_onedir: bool) -> str:
return os.path.join(output_path, get_cli_archive_filename(is_onedir))


def process_executable_file(input_path: Path, is_onedir: bool) -> str:
output_path = input_path.parent
hash_file_path = get_cli_hash_path(output_path, is_onedir)
Expand All @@ -133,6 +143,10 @@ def process_executable_file(input_path: Path, is_onedir: bool) -> str:
hashes = get_hashes_of_every_file_in_the_directory(input_path)
normalized_hashes = normalize_hashes_db(hashes, input_path)
write_hashes_db_to_file(normalized_hashes, hash_file_path)

archived_file_path = get_cli_archive_path(output_path, is_onedir)
shutil.make_archive(archived_file_path, _ARCHIVE_FORMAT, input_path)
shutil.rmtree(input_path)
else:
file_hash = get_hash_of_file(input_path)
write_hash_to_file(file_hash, hash_file_path)
Expand Down