Skip to content

Commit

Permalink
Added date as optional input parameter of workflow, and its usage (if…
Browse files Browse the repository at this point in the history
… passed) in release_calendar.py
  • Loading branch information
stevanzecic-mikroe committed Jan 17, 2025
1 parent 9b9e39b commit 18ab860
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/sdkAutomation_noBuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ on:
required: true
# The data type of the input
type: string
release_date:
# Release date from the release calendar
description: 'Release date from the release calendar. Takes current date if not changed.'
# Default value if no value is explicitly provided
default: '2000-01-01'
# Input has to be provided for the workflow to run
required: true
# The data type of the input
type: string
new_branch:
type: bool
description: 'To create a new branch for this run or use the last one'
Expand Down Expand Up @@ -100,9 +109,9 @@ jobs:
env:
RELEASES_SPREADSHEET: ${{ secrets.RELEASES_SPREADSHEET }}
run: |
branchInfo=$(python -u scripts/release_calendar.py --title "NECTO DAILY UPDATE" --doc_link $RELEASES_SPREADSHEET --chose_data "branches")
mcuInfo=$(python -u scripts/release_calendar.py --title "NECTO DAILY UPDATE" --doc_link $RELEASES_SPREADSHEET --chose_data "mcus")
cmakeInfo=$(python -u scripts/release_calendar.py --title "NECTO DAILY UPDATE" --doc_link $RELEASES_SPREADSHEET --chose_data "cmakes")
branchInfo=$(python -u scripts/release_calendar.py --title "NECTO DAILY UPDATE" --doc_link $RELEASES_SPREADSHEET --chose_data "branches" --release_date "${{ github.event.inputs.release_date }}")
mcuInfo=$(python -u scripts/release_calendar.py --title "NECTO DAILY UPDATE" --doc_link $RELEASES_SPREADSHEET --chose_data "mcus" --release_date "${{ github.event.inputs.release_date }}")
cmakeInfo=$(python -u scripts/release_calendar.py --title "NECTO DAILY UPDATE" --doc_link $RELEASES_SPREADSHEET --chose_data "cmakes" --release_date "${{ github.event.inputs.release_date }}")
branchInfoArray=($(echo "$branchInfo" | tr -d "[]'," | tr -s ' ' '\n'))
if [ "${branchInfoArray[0]}" == "NO_BRANCH_IN_SPREADSHEET" ]; then
Expand Down Expand Up @@ -134,7 +143,7 @@ jobs:
GH_TOKEN: ${{ secrets.MIKROE_ACTIONS_KEY }}
RELEASES_SPREADSHEET: ${{ secrets.RELEASES_SPREADSHEET }}
run: |
refManNumber=$(python -u scripts/release_calendar.py --title "NECTO DAILY UPDATE" --doc_link $RELEASES_SPREADSHEET --chose_data "ref_manual")
refManNumber=$(python -u scripts/release_calendar.py --title "NECTO DAILY UPDATE" --doc_link $RELEASES_SPREADSHEET --chose_data "ref_manual" --release_date "${{ github.event.inputs.release_date }}")
refManNumber="${refManNumber//\//_}"
gh release download --repo MikroElektronika/sdk_automation latest --pattern "extracted_${refManNumber}.zip"
echo "exit_code=$?" >> $GITHUB_OUTPUT
Expand All @@ -155,7 +164,7 @@ jobs:
run: |
currentBranch=$(git rev-parse --abbrev-ref HEAD)
echo "current branch is: $currentBranch"
refManNumber=$(python -u scripts/release_calendar.py --title "NECTO DAILY UPDATE" --doc_link $RELEASES_SPREADSHEET --chose_data "ref_manual")
refManNumber=$(python -u scripts/release_calendar.py --title "NECTO DAILY UPDATE" --doc_link $RELEASES_SPREADSHEET --chose_data "ref_manual" --release_date "${{ github.event.inputs.release_date }}")
systemPath=${refManNumber//rm/ds}
refManNumber="${refManNumber//\//_}"
sudo mv extracted_${refManNumber}.zip automatization/
Expand Down
39 changes: 27 additions & 12 deletions scripts/release_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,15 @@ def generate_file(file_data, file_out_path):
## Handle errors that may occur during file generation
print(f"Error generating file: {e}")

def find_listOf(selectedList):
def find_listOf(selectedList, release_date=''):
with open(os.path.join(os.path.dirname(__file__), 'releases.json')) as file:
json_data = json.load(file)
current_date = f'{datetime.today().year}-{datetime.today().month}-{datetime.today().day}'
used_date = release_date if release_date != '' else current_date

for indexRelease, release in enumerate(json_data['NECTO DAILY UPDATE']["events"]):
date = release["start_dt"]
if "2030-01-01" == date:
if used_date == date:
refManual = json.loads(release["additional"].replace('""','"').replace('"{','{').replace('}"','}'))["pdf_link"]
foundList = []
for nextRelease in json_data['NECTO DAILY UPDATE']["events"][indexRelease:]:
Expand All @@ -132,14 +133,15 @@ def find_listOf(selectedList):

return ["NO_BRANCH_IN_SPREADSHEET"]

def find_reference_manual():
def find_reference_manual(release_date=''):
with open(os.path.join(os.path.dirname(__file__), 'releases.json')) as file:
json_data = json.load(file)
current_date = f'{datetime.today().year}-{datetime.today().month}-{datetime.today().day}'
used_date = release_date if release_date != '' else current_date

for release in json_data['NECTO DAILY UPDATE']["events"]:
date = release["start_dt"]
if "2030-01-01" == date:
if used_date == date:
return json.loads(release["additional"].replace('""','"').replace('"{','{').replace('}"','}'))["pdf_link"].replace('.pdf', '')

return "none"
Expand All @@ -150,6 +152,7 @@ def find_reference_manual():
parser.add_argument("--title", type = str, help="Event title for calendar.", required=True)
parser.add_argument("--doc_link", type = str, help="Spreadsheet table with release details - link.",required=True)
parser.add_argument("--chose_data", type = str, default = "branches", help="Chose data from spreadsheet to return.",required=False)
parser.add_argument("--release_date", type=str, default="2000-01-01", help="Release date from the release calendar. Takes current date if not changed.")

## Parse the arguments
args = parser.parse_args()
Expand All @@ -159,17 +162,29 @@ def find_reference_manual():
## Then generate the input file for teamup API
generate_file(fileData, os.path.join(os.path.dirname(__file__), 'releases.json'))
if args.chose_data == 'branches':
## Find branch name from the jsom data for the current time
print(find_listOf('branch'))
## Find branch name from the jsom data for the current time or passed date
if args.release_date == "2000-01-01": # Default date value - use current date
print(find_listOf('branch'))
else: # Use passed date
print(find_listOf('branch', args.release_date))
elif args.chose_data == 'mcus':
## Find reference manual from the jsom data for the current time
print(find_listOf('mcu_list'))
## Find reference manual from the jsom data for the current time or passed date
if args.release_date == "2000-01-01": # Default date value - use current date
print(find_listOf('mcu_list'))
else: # Use passed date
print(find_listOf('mcu_list', args.release_date))
elif args.chose_data == 'cmakes':
## Find reference manual from the jsom data for the current time
print(find_listOf('cmake_name'))
## Find reference manual from the jsom data for the current time or passed date
if args.release_date == "2000-01-01": # Default date value - use current date
print(find_listOf('cmake_name'))
else: # Use passed date
print(find_listOf('cmake_name', args.release_date))
else:
## Find reference manual from the jsom data for the current time
print(find_reference_manual())
## Find reference manual from the jsom data for the current time or passed date
if args.release_date == "2000-01-01": # Default date value - use current date
print(find_reference_manual())
else: # Use passed date
print(find_reference_manual(args.release_date))



0 comments on commit 18ab860

Please sign in to comment.