From 538ee7e3a7daa83b6fb1caeffa88afb28fe9d136 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Tue, 8 Nov 2022 09:48:33 +0800 Subject: [PATCH] [pipeline] remove outdated samples in pipeline (#27324) * remove outdated samples * remove outdated samples --- .../packaging_tools/sdk_generator.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/azure-sdk-tools/packaging_tools/sdk_generator.py b/tools/azure-sdk-tools/packaging_tools/sdk_generator.py index 1fdd1c75cffc..0d5d8529a08b 100644 --- a/tools/azure-sdk-tools/packaging_tools/sdk_generator.py +++ b/tools/azure-sdk-tools/packaging_tools/sdk_generator.py @@ -3,6 +3,8 @@ import logging from pathlib import Path from subprocess import check_call +import shutil +import re from .swaggertosdk.SwaggerToSdkCore import ( CONFIG_FILE, @@ -22,6 +24,29 @@ _LOGGER = logging.getLogger(__name__) +def del_outdated_samples(readme: str): + python_readme = Path(readme).parent / "readme.python.md" + if not python_readme.exists(): + _LOGGER.info(f"do not find python configuration: {python_readme}") + return + + with open(python_readme, "r") as file_in: + content = file_in.readlines() + pattern = "$(python-sdks-folder)" + for line in content: + if pattern in line: + sdk_folder = re.findall("[a-z]+/[a-z]+-[a-z]+-[a-z]+", line)[0] + sample_folder = Path(f"sdk/{sdk_folder}/generated_samples") + if sample_folder.exists(): + shutil.rmtree(sample_folder) + _LOGGER.info(f"remove sample folder: {sample_folder}") + else: + _LOGGER.info(f"sample folder does not exist: {sample_folder}") + return + + _LOGGER.info(f"do not find {pattern} in {python_readme}") + + def main(generate_input, generate_output): with open(generate_input, "r") as reader: data = json.load(reader) @@ -53,6 +78,7 @@ def main(generate_input, generate_output): _LOGGER.info(f"[CODEGEN]({input_readme})codegen begin") if "resource-manager" in input_readme: relative_path_readme = str(Path(spec_folder, input_readme)) + del_outdated_samples(relative_path_readme) config = generate( CONFIG_FILE, sdk_folder,