Skip to content

Commit

Permalink
[pipeline] remove outdated samples in pipeline (Azure#27324)
Browse files Browse the repository at this point in the history
* remove outdated samples

* remove outdated samples
  • Loading branch information
msyyc authored Nov 8, 2022
1 parent 5753c19 commit 538ee7e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tools/azure-sdk-tools/packaging_tools/sdk_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 538ee7e

Please sign in to comment.