Skip to content

Commit 0757aef

Browse files
committed
Enhance package-distribution script
Add a main function, enhance some naming, add a description to the script help
1 parent ac6076d commit 0757aef

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

.github/workflows/scripts/package-distribution.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def dir_path(path):
3131

3232

3333
def build_archive(input_dir, destination_dir, archive_basename):
34-
input_files = os.listdir(args.input)
35-
print(f"packing mithril distribution {args.version}-{args.target} with files: {input_files}")
34+
input_files = os.listdir(input_dir)
35+
print(f"packing {archive_basename} with files: {input_files}")
3636

3737
if platform.system() == "Windows":
3838
import zipfile
@@ -53,10 +53,10 @@ def build_archive(input_dir, destination_dir, archive_basename):
5353
return archive_name
5454

5555

56-
def check_archive(archive, original_input_dir):
56+
def check_archive(archive_path, original_input_dir):
5757
print(f"checking archive ...")
5858
test_dir = "./unpack-test"
59-
shutil.unpack_archive(archive, test_dir)
59+
shutil.unpack_archive(archive_path, test_dir)
6060
original_checksum = sha256sum(original_input_dir)
6161
archive_content_checksum = sha256sum(test_dir)
6262
if original_checksum != archive_content_checksum:
@@ -69,23 +69,30 @@ def check_archive(archive, original_input_dir):
6969
shutil.rmtree(test_dir)
7070

7171

72-
def compute_sha256_checksum(archive):
72+
def compute_sha256_checksum(archive_path):
7373
print(f"computing archive checksum...")
74-
archive_checksum = sha256sum(archive)
75-
checksum_filename = f"{archive}.sha256"
74+
archive_checksum = sha256sum(archive_path)
75+
checksum_filename = f"{archive_path}.sha256"
7676
with open(checksum_filename, "x") as f:
7777
f.write(archive_checksum)
7878

7979

80+
def main(args):
81+
archive_path = build_archive(args.input, args.dest, archive_basename=f"mithril-{args.version}-{args.target}")
82+
check_archive(archive_path, args.input)
83+
compute_sha256_checksum(archive_path)
84+
85+
8086
if __name__ == '__main__':
81-
parser = argparse.ArgumentParser()
87+
parser = argparse.ArgumentParser(
88+
prog="Mithril distribution packager",
89+
description="Package the files in the given '--input' dir in a .tar.gz (linux, macOs) or .zip (windows)"
90+
" plus add a file with the value the sha256 of the generated package."
91+
)
8292
parser.add_argument("--input", type=dir_path, help="input folder which content will be archived", required=True)
8393
parser.add_argument("--dest", type=dir_path, help="destination folder for the archive, default to current folder",
8494
default="./")
8595
parser.add_argument("--version", help="version of the distribution to package", required=True)
8696
parser.add_argument("--target", help="target os & architecture of the package", required=True)
87-
args = parser.parse_args()
8897

89-
archive_path = build_archive(args.input, args.dest, archive_basename=f"mithril-{args.version}-{args.target}")
90-
check_archive(archive_path, args.input)
91-
compute_sha256_checksum(archive_path)
98+
main(parser.parse_args())

0 commit comments

Comments
 (0)