Skip to content

Commit

Permalink
Merge pull request #22 from MikroElektronika/topic/bsp-packages-as-as…
Browse files Browse the repository at this point in the history
…sets

Topic/bsp packages as assets
  • Loading branch information
StrahinjaJacimovic authored Aug 29, 2024
2 parents e5469cc + 78dfa67 commit 26c830e
Show file tree
Hide file tree
Showing 9 changed files with 442 additions and 36 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/updateChangelogs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ jobs:
- name: Commit and Push Changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "Updating with new CHANGELOG.md";
git add CHANGELOG.md
git commit -m "Updated main CHANGELOG.md file with latest merged release."
if [ -n "$(git status --porcelain changelog*)" ]; then
echo "Updating with new changelog files";
git add changelog*
git commit -m "Updated changelog files with latest merged release."
git push
else
echo "No changes made to CHANGELOG.md";
echo "No changes made to changelog files";
fi
File renamed without changes.
5 changes: 4 additions & 1 deletion changelog/v2.11.2/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@

### NEW HARDWARE

> NOTE:
>> If any new hardware was added to current version, it will be listed here.
Support added for following hardware:

+ [Mikromedia 3 for PIC32MZ RESISTIVE](https://www.mikroe.com/mikromedia-3-for-pic32mz-resistive)
+ **[2024-08-23](./new_hw/2024-08-23.md)**

---

Expand Down
29 changes: 29 additions & 0 deletions changelog/v2.11.2/new_hw/2024-08-23.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<p align="center">
<img src="http://www.mikroe.com/img/designs/beta/logo_small.png?raw=true" alt="MikroElektronika"/>
</p>

---

**[BACK TO PREVIOUS FILE](../changelog.md)**

---

# `2024-08-23`

## Changes

- [`2024-08-23`](#2024-08-23)
- [Changes](#changes)
- [NEW HARDWARE](#new-hardware)

### NEW HARDWARE

Support added for following hardware:

+ [Mikromedia 3 for PIC32MZ RESISTIVE](https://www.mikroe.com/mikromedia-3-for-pic32mz-resistive)

---

**[BACK TO PREVIOUS FILE](../changelog.md)**

---
97 changes: 78 additions & 19 deletions scripts/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,39 @@ def fetch_json_data(download_link, token):
print(f"Error fetching JSON data: {e}")
return None, str(e)

# Function to find an item by name
def find_item_by_name(items, name):
for item in items:
if item['name'] == name:
return item
return None
def check_from_index(es: Elasticsearch, index_name, asset):
# Search query to use
query_search = {
"size": 5000,
"query": {
"match_all": {}
}
}

# Search the base with provided query
num_of_retries = 1
while num_of_retries <= 10:
try:
response = es.search(index=index_name, body=query_search)
if not response['timed_out']:
break
except:
print("Executing search query - retry number %i" % num_of_retries)
num_of_retries += 1

version = '1.0.0'
for eachHit in response['hits']['hits']:
if not 'name' in eachHit['_source']:
continue ## TODO - Check newly created bare metal package (is it created correctly)
name = eachHit['_source']['name']
if name == asset:
version = eachHit['_source']['version']

return version

def increment_version(version):
major, minor, patch = map(int, version.split('.'))
return f"{major}.{minor}.{patch + 1}"

# Function to index release details into Elasticsearch
def index_release_to_elasticsearch(es : Elasticsearch, index_name, release_details, token):
Expand All @@ -73,20 +100,23 @@ def index_release_to_elasticsearch(es : Elasticsearch, index_name, release_detai
metadata_download_url = metadata_asset['url']
metadata_content.append(fetch_json_data(metadata_download_url, token)[0])

version = None
## 0 is new one being indexed, 1 in previously indexed release
for asset in release_details[0].get('assets', []):
if 'mikrosdk.7z' == asset['name']:
# Download the current mikroSDK asset in order to read the version
support.extract_archive_from_url(
asset['url'],
os.path.join(os.path.dirname(__file__), 'tmp'),
token
)

# Then fetch version from manifest file
version = support.fetch_version_from_asset(os.path.join(os.path.dirname(__file__), 'tmp'))
break
if 'mikrosdk' in metadata_content[0]:
version = metadata_content[0]['mikrosdk']['version']
else:
for asset in release_details[0].get('assets', []):
if 'mikrosdk.7z' == asset['name']:
# Download the current mikroSDK asset in order to read the version
support.extract_archive_from_url(
asset['url'],
os.path.join(os.path.dirname(__file__), 'tmp'),
token
)

# Then fetch version from manifest file
version = support.fetch_version_from_asset(os.path.join(os.path.dirname(__file__), 'tmp'))
break

for asset in release_details[0].get('assets', []):
doc = None
name_without_extension = os.path.splitext(os.path.basename(asset['name']))[0]
Expand Down Expand Up @@ -137,6 +167,35 @@ def index_release_to_elasticsearch(es : Elasticsearch, index_name, release_detai
"install_location" : "%APPLICATION_DATA_DIR%/resources/images",
"package_changed": package_changed
}
elif asset['name'].startswith('board') or asset['name'].startswith('mikromedia'):
board_version_new = '1.0.0'
board_version_previous = '0.0.0'
if 'packages' in metadata_content[1]:
if name_without_extension in metadata_content[1]['packages']:
if 'hash' in metadata_content[1]['packages'][name_without_extension]:
board_version_previous = check_from_index(es, index_name, asset['name'])
board_version_new = board_version_previous
if metadata_content[0]['packages'][name_without_extension]['hash'] != metadata_content[1]['packages'][name_without_extension]['hash']:
board_version_new = increment_version(board_version_previous)
for each_package in metadata_content[0]['packages']:
if metadata_content[0]['packages'][each_package]['package_name'] == name_without_extension:
package_name = metadata_content[0]['packages'][each_package]['display_name']
break
doc = {
'name': metadata_content[0]['packages'][package_name]['package_name'],
'display_name': metadata_content[0]['packages'][package_name]['display_name'],
'author': 'MIKROE',
'hidden': False,
"icon": metadata_content[0]['packages'][package_name]['icon'],
'type': metadata_content[0]['packages'][package_name]['type'],
'version': board_version_new,
'created_at' : asset['created_at'],
'updated_at' : asset['updated_at'],
'category': metadata_content[0]['packages'][package_name]['category'],
'download_link': asset['url'], # Adjust as needed for actual URL
"install_location" : metadata_content[0]['packages'][package_name]['install_location'],
'package_changed': board_version_previous != board_version_new
}

# Index the document
if doc:
Expand Down
51 changes: 46 additions & 5 deletions scripts/log_changes.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import os, re
from packaging import version
from datetime import datetime

import support as utility

# Function to extract date from filename
def extract_date(filename):
# Extract the date part (assuming format 'YYYY-MM-DD')
date_str = filename.split('.')[0]
# Convert to a datetime object for proper sorting
return datetime.strptime(date_str, '%Y-%m-%d')

changelog_root = os.path.join(os.getcwd(), 'changelog')
all_changelog_dirs = os.listdir(changelog_root)

## Get all currently present changelog versions
all_versions = sorted(
[x for x in os.listdir(os.path.join(os.getcwd(), 'changelog'))],
[x for x in all_changelog_dirs],
key=lambda x: version.parse(x), reverse=True
)

## Get file content first
with open(os.path.join(os.getcwd(),'CHANGELOG.md'), 'r') as main_changelog_file:
with open(os.path.join(os.getcwd(),'changelog.md'), 'r') as main_changelog_file:
main_changelog = main_changelog_file.readlines()
main_changelog_file.close()

Expand All @@ -22,10 +33,40 @@
## Create new links
array_of_links.append(f'+ **[{each_version}](./changelog/{each_version}/changelog.md)**')

## Then write the new main CHANGELOG.md content
with open(os.path.join(os.getcwd(),'CHANGELOG.md'), 'w') as main_changelog_file:
## Then write the new main changelog.md content
with open(os.path.join(os.getcwd(),'changelog.md'), 'w') as main_changelog_file:
main_changelog_file.writelines(''.join(main_changelog).replace('**VERSIONS:**', '\n'.join(array_of_links)))
main_changelog_file.close()

## And remove any occurrences of more than 1 sequential empty row
utility.filter_multiple_empty_rows(os.path.join(os.getcwd(),'CHANGELOG.md'))
utility.filter_multiple_empty_rows(os.path.join(os.getcwd(),'changelog.md'))

## Update CHANGELOG files with specific date releases
array_of_links = ['Support added for following hardware:\n']
for each_version in all_versions:
## Get file content first
with open(os.path.join(changelog_root, each_version, 'changelog.md'), 'r') as sub_changelog_file:
sub_changelog = sub_changelog_file.readlines()
sub_changelog_file.close()

## Remove lines that contain links
sub_changelog = [line for line in sub_changelog if not re.match(r'^\+ \*\*\[\d{4}-\d{2}-\d{2}\]\(\./new_hw/\d{4}-\d{2}-\d{2}\.md\)\*\*$', line)]

## Get file list
current_files = os.listdir(os.path.join(changelog_root, each_version))
if len(current_files) > 1:
print('Updated changelog file at: %s' % os.path.join(changelog_root, each_version))
if 'new_hw' in current_files:
## Sort the files based on date (newest go to top of the file)
all_sub_files = sorted(os.listdir(os.path.join(changelog_root, each_version, 'new_hw')), key=extract_date)
for each_sub_file in all_sub_files:
## Create new links
array_of_links.append(f'+ **[{each_sub_file.split('.')[0]}](./new_hw/{each_sub_file})**')

## Then write the new sub changelog.md content
with open(os.path.join(changelog_root, each_version, 'changelog.md'), 'w') as sub_changelog_file:
sub_changelog_file.writelines(''.join(sub_changelog).replace('Support added for following hardware:', '\n'.join(array_of_links)))
sub_changelog_file.close()

## And remove any occurrences of more than 1 sequential empty row
utility.filter_multiple_empty_rows(os.path.join(changelog_root, each_version, 'changelog.md'))
Loading

0 comments on commit 26c830e

Please sign in to comment.