diff --git a/.github/workflows/checkIndexes.yaml b/.github/workflows/checkIndexes.yaml index f9ba906c6..a36bd6fad 100644 --- a/.github/workflows/checkIndexes.yaml +++ b/.github/workflows/checkIndexes.yaml @@ -24,7 +24,7 @@ on: - main # This will trigger on every push (merge) to the 'main' branch schedule: - - cron: "*/30 * * * *" # This will run every 30 minutes + - cron: "0/30 7-16 * * 1-5" # Every 30 minutes, between 07:00 AM and 04:59 PM, Monday through Friday jobs: manual_run: diff --git a/scripts/check_indexes.py b/scripts/check_indexes.py index 93e1b8131..7671b7f5d 100644 --- a/scripts/check_indexes.py +++ b/scripts/check_indexes.py @@ -13,7 +13,8 @@ parser.add_argument("es_password", help="ES instance password value", type=str) parser.add_argument("es_index", help="ES instance index value", type=str) parser.add_argument("--es_regex", help="Regex to use to fetch indexed items", type=str, default=".+") - parser.add_argument("--log_only", help="Regex to use to fetch indexed items", type=bool, default=False) + parser.add_argument("--log_only", help="If True, will not fix broken links, just log them to std out", type=bool, default=False) + parser.add_argument("--index_package_names", help="If True, will add \"gh_package_name\" to indexed item", type=bool, default=True) args = parser.parse_args() es_instance = es.index( @@ -36,11 +37,24 @@ err = True print("%sERROR: Asset \"%s\" download link is incorrect. - %s" % (es_instance.Colors.FAIL, indexed_item['source']['name'], indexed_item['source']['download_link'])) if not args.log_only: - package_name = (json.loads(asset_status.text))['name'] - url = gh_instance.asset_fetch_url_api(package_name, loose=False) - indexed_item['source']['download_link'] = url - es_instance.update(indexed_item['doc']['type'], indexed_item['doc']['id'], indexed_item['source']) + if 'gh_package_name' in indexed_item['source']: + url = gh_instance.asset_fetch_url_api(indexed_item['source']['gh_package_name'], loose=False) + indexed_item['source']['download_link'] = url + es_instance.update(indexed_item['doc']['type'], indexed_item['doc']['id'], indexed_item['source']) + else: + print("%sWARNING: Asset \"%s\" has no \"gh_package_name\" in the index." % (es_instance.Colors.WARNING, indexed_item['source']['name'])) else: ## code 200 - success, no need to reindex + if args.index_package_names: + package_name = (json.loads(asset_status.text))['name'] + if 'gh_package_name' not in indexed_item['source']: + indexed_item['source'].update({"gh_package_name": package_name}) + es_instance.update(indexed_item['doc']['type'], indexed_item['doc']['id'], indexed_item['source']) + print("%sINFO: Added \"gh_package_name\" to %s" % (es_instance.Colors.UNDERLINE, indexed_item['source']['name'])) + else: + if package_name != indexed_item['source']['gh_package_name']: + indexed_item['source']['gh_package_name'] = package_name + es_instance.update(indexed_item['doc']['type'], indexed_item['doc']['id'], indexed_item['source']) + print("%sINFO: Updated \"gh_package_name\" for %s" % (es_instance.Colors.UNDERLINE, indexed_item['source']['name'])) print("%sOK: Asset \"%s\" download link is correct. - %s" % (es_instance.Colors.OKBLUE, indexed_item['source']['name'], indexed_item['source']['download_link'])) if err and args.log_only: diff --git a/scripts/index.py b/scripts/index.py index e53d4c4ed..84f464f99 100644 --- a/scripts/index.py +++ b/scripts/index.py @@ -272,8 +272,9 @@ def index_release_to_elasticsearch(es : Elasticsearch, index_name, release_detai 'published_at': published_at, 'category': 'Software Development Kit', 'download_link': asset['url'], # Adjust as needed for actual URL - "install_location" : "%APPLICATION_DATA_DIR%/packages/sdk", - 'package_changed': version != version_index + 'install_location' : "%APPLICATION_DATA_DIR%/packages/sdk", + 'package_changed': version != version_index, + 'gh_package_name': "mikrosdk.7z" } elif 'templates' == name_without_extension: package_changed = True @@ -291,7 +292,8 @@ def index_release_to_elasticsearch(es : Elasticsearch, index_name, release_detai "type" : "application", "download_link" : asset['url'], "install_location" : "%APPLICATION_DATA_DIR%/templates", - "package_changed": package_changed + "package_changed": package_changed, + "gh_package_name": "templates.7z" } elif 'images' == name_without_extension: package_changed = True @@ -308,7 +310,8 @@ def index_release_to_elasticsearch(es : Elasticsearch, index_name, release_detai "type" : "images", "download_link" : asset['url'], "install_location" : "%APPLICATION_DATA_DIR%/resources/images", - "package_changed": True + "package_changed": True, + "gh_package_name": "images.7z" } elif asset['name'].startswith('board') or \ asset['name'].startswith('mikromedia') or \ @@ -387,7 +390,8 @@ def index_release_to_elasticsearch(es : Elasticsearch, index_name, release_detai "install_location" : metadata_content[0]['packages'][package_name]['install_location'], 'package_changed': asset_version_previous != asset_version_new, 'show_package_info': show_package, - 'hash': hash_new + 'hash': hash_new, + 'gh_package_name': os.path.splitext(os.path.basename(asset['name']))[0] } check_types = ['board', 'card']