diff --git a/alphaplan_fwr.py b/alphaplan_fwr.py index 7cee5129c66ed670cb06aaa6685b5dbbb0712915..16ba3f8b7367a6cf41b9bbb48432c1efd98ceab9 100755 --- a/alphaplan_fwr.py +++ b/alphaplan_fwr.py @@ -1,13 +1,17 @@ #!/usr/bin/env python3 +import argparse import json import os import shutil import sys import requests +import glob from alphaplan_keys import ApKeys, ApSubKeys, get_ap_dict def ap_send_json(jsonobj): + print("##### Currently in debug mode: No data is send to AlphaPlan webservice") + return """Sends the generated files to the Alphaplan webservice""" url = os.environ.get("AP_WEBSERVICE_URL") usr = os.environ.get("AP_WEBSERVICE_USR") @@ -263,3 +267,79 @@ def generate_fwr_articles( shutil.copyfile(jsonfile_local, jsonfile_output, follow_symlinks=True) # Send data object to AlphaPlan webservice ap_send_json(data) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument( + "--images-dir", + help="""Yocto images directory""", + dest="images_dir", + ) + parser.add_argument( + "--outputdir-upload", + help="""Base directory name for uploaded artifacts""", + dest="outputdir_upload", + ) + parser.add_argument( + "--outputdir-local", + help="""Base directory for locally deployed artifacts, should contain absolut path.""", + dest="outputdir_local", + ) + args, _ = parser.parse_known_args() + + if args.outputdir_upload is None or args.outputdir_local is None: + sys.exit( + "ERROR: outputdir-local and outputdir-upload needs to be specified." + ) + + # Get bitbake variables from testdata.json file + testdata_files = [] + if args.images_dir is not None: + testdata_files += glob.glob(os.path.join(args.images_dir, "*.testdata.json")) + + with open(testdata_files[0], "r", encoding="utf-8") as f: + buildvars = json.load(f) + + machine = buildvars["MACHINE"] + version = buildvars["DISTRO_VERSION"] + artifacts_all = buildvars["DISTRO_RELEASE_ARTEFACTS"].split() + artifacts_all.append("BUILD_SRCREVS.log") + + if version.startswith("fngsystem"): + release_name_local = version.replace("fngsystem", "FNGSystem") + release_name = release_name_local + else: + release_name = "GUF-Yocto-%s" % version + release_name_local = "Yocto-%s" % version + + output_dir = os.path.join(args.outputdir_upload, release_name) + outlocal_dir = os.path.join(args.outputdir_local, release_name_local) + if not os.path.isdir(outlocal_dir): + sys.exit("ERROR: ouputdir-local does not exist") + if not os.path.isdir(output_dir): + sys.exit("ERROR: ouputdir-upload does not exist") + + # Get md5sums.txt + md5sums_file = os.path.join(output_dir, machine, "md5sums.txt") + md5sums = {} + with open(md5sums_file) as f: + for line in f: + # Assuming line format: "<md5sum> <filename>\n" + name = line.split(" ")[1].rstrip() + sum = line.split(" ")[0] + md5sums[name] = sum + + # Generate alphaplan FWR articles + generate_fwr_articles( + output_dir, + outlocal_dir, + machine, + release_name_local, + artifacts_all, + md5sums, + ) + + +if __name__ == "__main__": + main() diff --git a/manifest-build.yml b/manifest-build.yml index 3dace5802be2f3990caff2be23a39283a588b23f..b0987e7c7309ef59e1e21f66853439ec75d8ce4e 100644 --- a/manifest-build.yml +++ b/manifest-build.yml @@ -130,12 +130,6 @@ variables: outdir="${OUTDIR_BASE}-fngsystem/CI_Builds" fi - # Generate AlphaPlan FWR articles if release tag is set - if [ -n "$CI_COMMIT_TAG" ] && \ - [[ "${CI_PARAM_PACKAGE_FTP}" == "false" ]];then - UPLOAD_PARAM="${UPLOAD_PARAM} --generate-fwr-articles" - fi - script=".gitlab-ci/package_release.py" [ ! -x "$script" ] && script=".repo/manifests/$script" [ ! -x "$script" ] && echo "Failed to find package_release script" @@ -156,6 +150,25 @@ variables: --outputdir-local="${outdir}" fi + # Generate AlphaPlan FWR articles if release tag is set + apscript=".gitlab-ci/alphaplan_fwr.py" + + #if [ -n "$CI_COMMIT_TAG" ] && \ + echo "CI AP debug mode" + if true && \ + [ -d "${ARTIFACTS_IMAGE_PATH}" ] && \ + [[ "${CI_PARAM_PACKAGE_FTP}" == "false" ]];then + # Check if alphaplan fwr script is available + [ ! -x "${apscript}" ] && \ + echo "Failed to find alphaplan_fwr script" && \ + exit 1 + # Call script + ${apscript} \ + --images-dir="${ARTIFACTS_IMAGE_PATH}" \ + --outputdir-local=${outdir} \ + --outputdir-upload=release + fi + .prepare_test: before_script: - *setup_ssh diff --git a/package_release.py b/package_release.py index e141bc5f63f2b0d18db3d4542cff2d2fa3094d54..1625ec864a7752705d39a8d9d1f4924275cce84a 100755 --- a/package_release.py +++ b/package_release.py @@ -7,7 +7,6 @@ import sys import shutil import hashlib import tempfile -import alphaplan_fwr from datetime import datetime from convert_md2html import convertmd2html @@ -185,13 +184,6 @@ def main(): help="""Documentation directory""", dest="doc_dir", ) - parser.add_argument( - "--generate-fwr-articles", - help="""Enable AlphaPlan FWR generation""", - dest="generate_fwr_articles", - action="store_true", - ) - parser.set_defaults(generate_fwr_articles=False) args, _ = parser.parse_known_args() if args.outputdir_upload is None and args.outputdir_local is None: @@ -290,17 +282,6 @@ def main(): artifacts_all.append("license.manifest") - # Generate alphaplan FWR articles - if args.generate_fwr_articles: - alphaplan_fwr.generate_fwr_articles( - output_dir, - outlocal_dir, - machine, - release_name_local, - artifacts_all, - md5sums, - ) - # Generate metadata if args.sdk_dir is None: generate_metadata(