diff options
Diffstat (limited to 'src/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts')
3 files changed, 285 insertions, 0 deletions
diff --git a/src/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/extract_from_release_notes.py b/src/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/extract_from_release_notes.py new file mode 100644 index 000000000..3802d9211 --- /dev/null +++ b/src/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/extract_from_release_notes.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# + +""" +Extract the latest release notes content from RELEASE_NOTES.md +""" + +import argparse +import os +import sys +import traceback + + +def latest_content(release_notes_path): + """ + can't change the format of the original content + """ + content = "" + start_extract = False + with open(release_notes_path, encoding="utf-8") as f: + for line in f: + if line.startswith("## "): + if start_extract: + break + + start_extract = True + continue + + # hit a separated line + if line.startswith("---"): + break + + content += line + + content += os.linesep + return content + + +def main(): + """ + GO!GO!!GO!!! + """ + parser = argparse.ArgumentParser(description="run the sample and examine outputs") + parser.add_argument("release_notes_path", type=str) + args = parser.parse_args() + + ret = 1 + try: + print(latest_content(args.release_notes_path)) + ret = 0 + except AssertionError: + traceback.print_exc() + return ret + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/src/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/fetch_and_compare_version.py b/src/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/fetch_and_compare_version.py new file mode 100644 index 000000000..ac206cade --- /dev/null +++ b/src/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/fetch_and_compare_version.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# + +import re +import shlex +import subprocess +import sys + + +def fetch_version_from_code(): + """ + search the semantic version definition in core/version.h + """ + major, minor, patch = "", "", "" + with open("core/version.h", encoding="utf-8") as f: + for line in f: + if "WAMR_VERSION" not in line: + continue + + major_match = re.search(r"WAMR_VERSION_MAJOR (\d+)", line) + if major_match is not None: + major = major_match.groups()[0] + continue + + minor_match = re.search(r"WAMR_VERSION_MINOR (\d+)", line) + if minor_match is not None: + minor = minor_match.groups()[0] + continue + + patch_match = re.search(r"WAMR_VERSION_PATCH (\d+)", line) + if patch_match is not None: + patch = patch_match.groups()[0] + + if len(major) == 0 or len(minor) == 0 or len(patch) == 0: + raise Exception( + "can't find the semantic version definition likes WAMR_VERSION_*" + ) + return f"WAMR-{major}.{minor}.{patch}" + + +def fetch_latest_git_tag(): + list_tag_cmd = ( + 'git tag --list WAMR-*.*.* --sort=committerdate --format="%(refname:short)"' + ) + p = subprocess.run(shlex.split(list_tag_cmd), capture_output=True, check=True) + + all_tags = p.stdout.decode().strip() + latest_tag = all_tags.split("\n")[-1] + return latest_tag + + +def match_version_pattern(v): + pattern = r"WAMR-\d+\.\d+\.\d+" + m = re.match(pattern, v) + return m is not None + + +def split_version_string(v): + """ + return the semantic version as an integer list + """ + pattern = r"WAMR-(\d+)\.(\d+)\.(\d+)" + m = re.match(pattern, v) + return [int(x) for x in m.groups()] + + +def compare_version_string(v1, v2): + """ + return value: + - 1. if v1 > v2 + - -1. if v1 < v2 + - 0. if v1 == v2 + """ + if not match_version_pattern(v1): + raise Exception(f"{v1} doesn't match the version pattern") + + if not match_version_pattern(v2): + raise Exception(f"{v2} doesn't match the version pattern") + + v1_sem_ver = split_version_string(v1) + v2_sem_ver = split_version_string(v2) + + return 0 if v1_sem_ver == v2_sem_ver else (1 if v1_sem_ver > v2_sem_ver else -1) + + +def is_major_or_minor_changed(v1, v2): + """ + return true if change either major of v2 or minor of v2 + return false or else + """ + if not match_version_pattern(v1): + raise Exception(f"{v1} doesn't match the version pattern") + + if not match_version_pattern(v2): + raise Exception(f"{v2} doesn't match the version pattern") + + v1_major, v1_minor, _ = split_version_string(v1) + v2_major, v2_minor, _ = split_version_string(v2) + + return v2_major != v1_major or v2_minor != v1_minor + + +def next_version(): + definition = fetch_version_from_code() + tag = fetch_latest_git_tag() + + new_version = "" + minor_changed = False + if compare_version_string(definition, tag) == 1: + new_version = definition.split("-")[-1] + + if is_major_or_minor_changed(tag, definition): + minor_changed = True + + return new_version, "major_minor_change" if minor_changed else "patch_change" + + +if __name__ == "__main__": + print(f"{next_version()[0]},{next_version()[1]}") + sys.exit(0) diff --git a/src/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/reuse_latest_release_binaries.py b/src/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/reuse_latest_release_binaries.py new file mode 100644 index 000000000..0fe2d9766 --- /dev/null +++ b/src/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/reuse_latest_release_binaries.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# + +import argparse +import json +import os +import shlex +import subprocess +import sys +from urllib.error import HTTPError, URLError +import urllib.request + + +def get_last_commit(target_path, cwd): + last_commit_cmd = f"git log -n 1 --pretty=format:%H -- {target_path}" + p = subprocess.run( + shlex.split(last_commit_cmd), capture_output=True, check=True, cwd=cwd + ) + return p.stdout.decode().strip() + + +def fetch_git_tags(): + list_tag_cmd = ( + 'git tag --list WAMR-*.*.* --sort=committerdate --format="%(refname:short)"' + ) + p = subprocess.run(shlex.split(list_tag_cmd), capture_output=True, check=True) + + all_tags = p.stdout.decode().strip() + return all_tags.split("\n") + + +def download_binaries(binary_name_stem, cwd): + """ + 1. find the latest release name + 2. form assets download url: + """ + try: + all_tags = fetch_git_tags() + # *release_process.yml* will create a tag and release at first + second_last_tag = all_tags[-2] + latest_tag = all_tags[-1] + + latest_url = "https://api.github.com/repos/bytecodealliance/wasm-micro-runtime/releases/latest" + print(f"::notice::query the latest release with {latest_url}...") + with urllib.request.urlopen(latest_url) as response: + body = response.read() + + release_name = json.loads(body)["name"] + + # WAMR-X.Y.Z -> X.Y.Z + second_last_sem_ver = second_last_tag[5:] + latest_sem_ver = latest_tag[5:] + assert latest_sem_ver in binary_name_stem + name_stem_in_release = binary_name_stem.replace( + latest_sem_ver, second_last_sem_ver + ) + + # download and rename + for file_ext in (".zip", ".tar.gz"): + assets_url = f"https://github.com/bytecodealliance/wasm-micro-runtime/releases/download/{release_name}/{name_stem_in_release}{file_ext}" + local_path = f"{binary_name_stem}{file_ext}" + print(f"::notice::download from {assets_url} and save as {local_path}...") + urllib.request.urlretrieve(assets_url, local_path) + return True + except HTTPError as error: + print(error.status, error.reason) + except URLError as error: + print(error.reason) + except TimeoutError: + print("Request timeout") + + return False + + +def main(): + parser = argparse.ArgumentParser( + description="Reuse binaries of the latest release if no more modification on the_path since last_commit" + ) + parser.add_argument("working_directory", type=str) + parser.add_argument("--binary_name_stem", type=str) + parser.add_argument("--last_commit", type=str) + parser.add_argument("--the_path", type=str) + args = parser.parse_args() + + last_commit = get_last_commit(args.the_path, args.working_directory) + if last_commit == args.last_commit: + return download_binaries(args.binary_name_stem, args.working_directory) + else: + return False + + +if __name__ == "__main__": + # use output to indicate results + # echo "result=${result}" >> "$GITHUB_OUTPUT" + with open(os.environ.get("GITHUB_OUTPUT"), 'a') as output_file: + output_file.write("result=hit\n" if main() else "result=not-hit\n") + + # always return 0 + sys.exit(0) |