Skip to content

Commit 9bf73ca

Browse files
Added BSP asset packing and upload
1 parent e181eb9 commit 9bf73ca

File tree

2 files changed

+66
-9
lines changed

2 files changed

+66
-9
lines changed

scripts/package.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,26 @@ def get_release_id(repo, tag_name, token):
5050
response.raise_for_status()
5151
return response.json()['id']
5252

53+
def zip_bsp_related_files(archive_path, repo_dir):
54+
support.copy_files_with_structure(
55+
os.path.join(repo_dir, 'bsp'),
56+
os.path.join(repo_dir, 'output/bsps'),
57+
[
58+
'board.h',
59+
'mcu_card.h'
60+
]
61+
)
62+
support.copy_files_with_structure(
63+
repo_dir,
64+
os.path.join(repo_dir, 'output/bsps'),
65+
[
66+
'mcu_definitions.h',
67+
'can_definitions.h',
68+
'dma_definitions.h'
69+
]
70+
)
71+
create_template_archive('output', archive_path)
72+
5373
if __name__ == '__main__':
5474
parser = argparse.ArgumentParser(description="Upload directories as release assets.")
5575
parser.add_argument("token", help="GitHub Token")
@@ -64,26 +84,28 @@ def get_release_id(repo, tag_name, token):
6484
# Set copyright year for all files to current year
6585
support.update_copyright_year(repo_dir)
6686

87+
# Get the release ID used to upload assets
88+
release_id = get_release_id(args.repo, f'mikroSDK-{version}', args.token)
89+
6790
if manifest_folder:
6891
archive_path = os.path.join(repo_dir, 'mikrosdk.7z')
6992
print('Creating archive: %s' % archive_path)
7093
create_7z_archive(version, repo_dir, archive_path)
7194
print('Archive created successfully: %s' % archive_path)
72-
73-
# Get the release ID and upload the asset
74-
release_id = get_release_id(args.repo, f'mikroSDK-{version}', args.token)
7595
upload_result = upload_asset_to_release(args.repo, release_id, archive_path, args.token)
76-
7796
print('Asset "%s" uploaded successfully to release ID: %s' % ('mikrosdk', release_id))
7897

7998
if os.path.exists(os.path.join(repo_dir, 'templates')):
8099
archive_path = os.path.join(repo_dir, 'templates.7z')
81100
print('Creating archive: %s' % archive_path)
82101
create_template_archive('templates', archive_path)
83102
print('Archive created successfully: %s' % archive_path)
84-
85-
# Get the release ID and upload the asset
86-
release_id = get_release_id(args.repo, f'mikroSDK-{version}', args.token)
87103
upload_result = upload_asset_to_release(args.repo, release_id, archive_path, args.token)
88-
89104
print('Asset "%s" uploaded successfully to release ID: %s' % ('templates', release_id))
105+
106+
# BSP asset
107+
archive_path = os.path.join(repo_dir, 'bsps.7z')
108+
print('Creating archive: %s' % archive_path)
109+
zip_bsp_related_files(archive_path, repo_dir)
110+
upload_result = upload_asset_to_release(args.repo, release_id, archive_path, args.token)
111+
print('Asset "%s" uploaded successfully to release ID: %s' % ('bsps', release_id))

scripts/support.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import requests, py7zr, zipfile, io, os, re, json
1+
import requests, py7zr, zipfile, io, os, re, json, shutil
22
import chardet # For detecting file encoding
33
from datetime import datetime
44

@@ -123,3 +123,38 @@ def update_copyright_year(directory):
123123
else:
124124
print('Updating file "%s"' % file_path)
125125
replace_copyright_year(file_path)
126+
127+
def copy_files_with_structure(src_root, dst_root, filenames):
128+
"""
129+
Copy files named in `filenames` from `src_root` to `dst_root` while preserving the folder structure.
130+
131+
Args:
132+
src_root (str): Source root directory to search for files.
133+
dst_root (str): Destination root directory where files will be copied.
134+
filenames (list of str): List of filenames to copy.
135+
"""
136+
# Ensure filenames is a list
137+
if not isinstance(filenames, list):
138+
raise TypeError("filenames should be a list of strings")
139+
140+
# Iterate over each directory in the source root
141+
for dirpath, _, files in os.walk(src_root):
142+
if dst_root in dirpath:
143+
continue
144+
for filename in filenames:
145+
if filename in files:
146+
# Construct full file path
147+
src_file = os.path.join(dirpath, filename)
148+
# Construct destination path preserving the folder structure
149+
relative_path = os.path.relpath(dirpath, src_root)
150+
dst_dir = os.path.join(dst_root, relative_path)
151+
152+
# Ensure the destination directory exists
153+
if not os.path.exists(dst_dir):
154+
os.makedirs(dst_dir)
155+
156+
# Construct destination file path
157+
dst_file = os.path.join(dst_dir, filename)
158+
# Copy the file
159+
shutil.copy2(src_file, dst_file)
160+
print(f"Copied {src_file} to {dst_file}")

0 commit comments

Comments
 (0)