From 3d89bff6b82866a9cf534138c570996d8514e387 Mon Sep 17 00:00:00 2001 From: "@odemolliens" Date: Fri, 2 May 2025 17:11:38 +0200 Subject: [PATCH 1/2] Create auto-extract-steps-from-codemagic-yaml.py --- .../auto-extract-steps-from-codemagic-yaml.py | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 dev_scripts/auto-extract-steps-from-codemagic-yaml.py diff --git a/dev_scripts/auto-extract-steps-from-codemagic-yaml.py b/dev_scripts/auto-extract-steps-from-codemagic-yaml.py new file mode 100644 index 0000000..6756b43 --- /dev/null +++ b/dev_scripts/auto-extract-steps-from-codemagic-yaml.py @@ -0,0 +1,75 @@ +""" +This script extracts script steps defined with anchors from a `codemagic.yaml` file +and exports each as a separate `step.yml` file in structured subfolders. + +Usage: +1. Place this script in the **same directory** as your `codemagic.yaml`. +2. Ensure your `codemagic.yaml` contains script steps with anchors (e.g. `- &build_step`). +3. Run the script with Python: `python auto-extract-steps-from-codemagic-yaml.py`. +4. For each anchored step, a folder will be created at: `steps_to_export//codemagic/step.yml`. + +Each `step.yml` will include: +- The name of the step +- A fixed `ignore_failure: true` field +- The script content from the original YAML + +Requirements: +- Python 3 +- PyYAML (`pip install pyyaml`) +""" + +import os +import yaml +import re + +INPUT_FILE = "codemagic.yaml" +EXPORT_BASE_DIR = "steps_to_export" + +def extract_anchors(file_path): + """Return a list of (anchor_name, index_in_scripts) tuples.""" + anchors = [] + with open(file_path, 'r', encoding='utf-8') as f: + for idx, line in enumerate(f): + match = re.match(r"\s*-\s*&(\S+)", line) + if match: + anchors.append((match.group(1), len(anchors))) + return anchors + +def main(): + with open(INPUT_FILE, "r", encoding="utf-8") as f: + yaml_data = yaml.safe_load(f) + + anchors = extract_anchors(INPUT_FILE) + scripts = yaml_data.get("scripts", []) + + for anchor_name, index in anchors: + try: + step_data = scripts[index] + except IndexError: + print(f"⚠️ Warning: No step found at index {index} for anchor '{anchor_name}'") + continue + + if not isinstance(step_data, dict): + continue + + step_name = step_data.get("name") + script_content = step_data.get("script") + + if not step_name or not script_content: + continue + + output_dir = os.path.join(EXPORT_BASE_DIR, anchor_name, "codemagic") + os.makedirs(output_dir, exist_ok=True) + + step_yaml_path = os.path.join(output_dir, "step.yml") + with open(step_yaml_path, "w", encoding="utf-8") as f: + f.write(f'name: "{step_name}"\n') + f.write("ignore_failure: true\n") + f.write("script: |\n") + for line in script_content.splitlines(): + f.write(f" {line.rstrip()}\n") # 3 spaces here + + print(f"✅ Exported: {step_yaml_path}") + +if __name__ == "__main__": + main() From d2f86c020fe8347ecd07414ad99b3e35e48fd2fe Mon Sep 17 00:00:00 2001 From: "@odemolliens" Date: Fri, 2 May 2025 17:13:10 +0200 Subject: [PATCH 2/2] Update .npmignore --- .npmignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.npmignore b/.npmignore index eb32d63..b885e5d 100644 --- a/.npmignore +++ b/.npmignore @@ -1,6 +1,7 @@ src/ docs/ assets/ +dev_scripts/ scripts shell **/__tests__/ @@ -51,4 +52,4 @@ test.sh CHANGELOG.md CONTRIBUTING.md REFERENCE_API.md -README.md \ No newline at end of file +README.md