Skip to content

Commit 9fcd4ca

Browse files
authored
CM-31141 - Zip onedir CLI to attach to GitHub releases (#191)
1 parent 64e2f28 commit 9fcd4ca

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

process_executable_file.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
import hashlib
1313
import os
1414
import platform
15+
import shutil
1516
from pathlib import Path
1617
from string import Template
1718
from typing import List, Tuple, Union
1819

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

127129

130+
def get_cli_archive_filename(is_onedir: bool) -> str:
131+
return get_cli_file_name(suffix=get_cli_file_suffix(is_onedir))
132+
133+
134+
def get_cli_archive_path(output_path: Path, is_onedir: bool) -> str:
135+
return os.path.join(output_path, get_cli_archive_filename(is_onedir))
136+
137+
128138
def process_executable_file(input_path: Path, is_onedir: bool) -> str:
129139
output_path = input_path.parent
130140
hash_file_path = get_cli_hash_path(output_path, is_onedir)
@@ -133,6 +143,10 @@ def process_executable_file(input_path: Path, is_onedir: bool) -> str:
133143
hashes = get_hashes_of_every_file_in_the_directory(input_path)
134144
normalized_hashes = normalize_hashes_db(hashes, input_path)
135145
write_hashes_db_to_file(normalized_hashes, hash_file_path)
146+
147+
archived_file_path = get_cli_archive_path(output_path, is_onedir)
148+
shutil.make_archive(archived_file_path, _ARCHIVE_FORMAT, input_path)
149+
shutil.rmtree(input_path)
136150
else:
137151
file_hash = get_hash_of_file(input_path)
138152
write_hash_to_file(file_hash, hash_file_path)

0 commit comments

Comments
 (0)