Skip to content

Commit

Permalink
Reverted release.py script
Browse files Browse the repository at this point in the history
Signed-off-by: enriquezgarc <[email protected]>
  • Loading branch information
jaenrig-ifx committed Jun 4, 2024
1 parent 61ed41e commit bd7a5a0
Showing 1 changed file with 16 additions and 31 deletions.
47 changes: 16 additions & 31 deletions .github/scripts/release.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import argparse, copy, hashlib, json, re, requests, os, shutil

version = '0.2.0'
version = '0.1.0'

xmc_ino_root_path = os.path.relpath(os.path.join(os.path.join(os.getcwd(), os.pardir), os.pardir))
build_dir_name = 'pkg_build'
Expand Down Expand Up @@ -60,54 +60,40 @@ def get_package_sha256(pkg):
def get_latest_package_index_json():
return requests.get('https://github.com/Infineon/XMC-for-Arduino/releases/latest/download/package_infineon_index.json').json()

def get_local_package_index_json():
with open(os.path.join(xmc_ino_root_path, 'package/package_infineon_index.template.json'), 'r') as f:
data = json.load(f)
return data

def get_platform_data_struct_copy(pkg_index):
return copy.deepcopy(pkg_index['packages'][0]['platforms'])
return copy.deepcopy(pkg_index['packages'][0]['platforms'][0])

def set_new_platform_data_fields(platform_data_index, pkg_name, version, repository):
def set_new_platform_data_fields(platform_data, pkg_name, version):
semver = strip_prefix_from_version(version)
platform_data = platform_data_index['packages'][0]['platforms'][0]
platform_data['version'] = str(semver)
archive_file_name = str(pkg_name) + ".zip"
platform_data['archiveFileName'] = archive_file_name
platform_data['url'] = "https://github.com/" + str(repository) + "/releases/download/" + str(version) + "/" + str(archive_file_name)
platform_data['url'] = "https://github.com/Infineon/XMC-for-Arduino/releases/download/" + str(version) + "/" + str(archive_file_name)
platform_data['checksum'] ="SHA-256:" + str(get_package_sha256(os.path.join(pkg_assets_build_path, archive_file_name)))
platform_data['size'] = str(get_package_size(os.path.join(pkg_assets_build_path, archive_file_name)))

def add_platform_to_package_index(pkg_index, platform):
pkg_index['packages'][0]['platforms'].insert(1, platform)
def add_new_platform_to_package_index(pkg_index, new_platform):
pkg_index['packages'][0]['platforms'].insert(0, new_platform)

def make_package_index_file(pkg_index):
pkg_index_json_obj = json.dumps(pkg_index, indent=2)
pkg_index_w_path = os.path.join(pkg_assets_build_path, "package_infineon_index.json")
with open(pkg_index_w_path, "w") as pkg_file:
pkg_file.write(pkg_index_json_obj)

def build_package_index_json(pkg_name, version, repository):
# get online package index json
latest_package_index = get_latest_package_index_json()
# get local package index template
local_package_index = get_local_package_index_json()
# set data field in local template for newest package
set_new_platform_data_fields(local_package_index, pkg_name, version, repository)
# get old package array
old_platform_data = get_platform_data_struct_copy(latest_package_index)
# append to local package index
add_platform_to_package_index(local_package_index, old_platform_data)
make_package_index_file(local_package_index)

def build_release_assets(version, repository):
if os.path.exists(pkg_assets_build_path):
os.system("rm -rf "+pkg_assets_build_path)
def build_package_index_json(pkg_name, version):
package_index = get_latest_package_index_json()
new_platform_data = get_platform_data_struct_copy(package_index)
set_new_platform_data_fields(new_platform_data, pkg_name, version)
add_new_platform_to_package_index(package_index, new_platform_data)
make_package_index_file(package_index)

def build_release_assets(version):
os.mkdir(pkg_assets_build_path)
pkg_name = mkdir_package_dir(version)
build_package(pkg_name)
zip_package(pkg_name)
build_package_index_json(pkg_name, version, repository)
build_package_index_json(pkg_name, version)

def parser():

Expand All @@ -119,7 +105,7 @@ def parser_build_release_assets_func(args):
global pkg_build_path
xmc_ino_root_path = args.root_path
pkg_build_path = args.build_path
build_release_assets(args.version, args.repository)
build_release_assets(args.version)

class ver_action(argparse.Action):
def __init__(self, option_strings, dest, **kwargs):
Expand All @@ -137,7 +123,6 @@ def __call__(self, parser, namespace, values, option_string, **kwargs):

# Release parser
parser_release = subparser.add_parser('build-release', description='Build package release assets')
parser_release.add_argument('repository', type=str, help='Repository name')
parser_release.add_argument('version', type=str, help='Package release version (format: Vx.y.z)')
parser_release.add_argument('-r','--root-path', type=str, default=xmc_ino_root_path, help='Path to the XMC-for-Arduino root path')
parser_release.add_argument('-b','--build-path', type=str, default=pkg_assets_build_path, help='Path to build package')
Expand Down

0 comments on commit bd7a5a0

Please sign in to comment.