Address code review feedback and improve platform detection
Co-authored-by: jmiller-moko <230051081+jmiller-moko@users.noreply.github.com>
This commit is contained in:
15
.github/workflows/release_pipeline.yml
vendored
15
.github/workflows/release_pipeline.yml
vendored
@@ -657,19 +657,10 @@ else:
|
||||
DIST_DIR="${GITHUB_WORKSPACE}/dist"
|
||||
mkdir -p "${DIST_DIR}"
|
||||
|
||||
# Detect platform and extension type using Python utility
|
||||
PLATFORM_INFO=$(python3 -c "
|
||||
import sys
|
||||
sys.path.insert(0, '${GITHUB_WORKSPACE}/scripts/lib')
|
||||
import extension_utils
|
||||
ext_info = extension_utils.get_extension_info('${GITHUB_WORKSPACE}/src')
|
||||
if ext_info:
|
||||
print(f'{ext_info.platform.value}|{ext_info.extension_type}')
|
||||
else:
|
||||
sys.exit(1)
|
||||
")
|
||||
# Detect platform and extension type using dedicated script
|
||||
PLATFORM_INFO=$(python3 "${GITHUB_WORKSPACE}/scripts/release/detect_platform.py" "${GITHUB_WORKSPACE}/src")
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
if [ $? -ne 0 ] || [ -z "${PLATFORM_INFO}" ]; then
|
||||
echo "ERROR: Could not detect extension platform and type" >> "${GITHUB_STEP_SUMMARY}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -123,7 +123,7 @@ def detect_dolibarr_manifest(src_dir: Union[str, Path]) -> Optional[Path]:
|
||||
"""
|
||||
src_path = Path(src_dir)
|
||||
|
||||
# Dolibarr module descriptors follow pattern: core/modules/modMyModule.class.php
|
||||
# Dolibarr module descriptors follow pattern: core/modules/mod*.class.php
|
||||
descriptor_patterns = [
|
||||
"core/modules/mod*.class.php",
|
||||
"*/modules/mod*.class.php",
|
||||
@@ -218,8 +218,13 @@ def parse_dolibarr_descriptor(descriptor_path: Path) -> Optional[ExtensionInfo]:
|
||||
try:
|
||||
content = descriptor_path.read_text(encoding="utf-8")
|
||||
|
||||
# Extract module name from class name
|
||||
# Extract module name from class name (try multiple patterns)
|
||||
# Pattern 1: class ModMyModule
|
||||
name_match = re.search(r'class\s+(Mod\w+)', content)
|
||||
if not name_match:
|
||||
# Pattern 2: class mod_mymodule (lowercase)
|
||||
name_match = re.search(r'class\s+(mod_\w+)', content, re.IGNORECASE)
|
||||
|
||||
name = name_match.group(1) if name_match else "unknown"
|
||||
|
||||
# Extract version
|
||||
|
||||
98
scripts/release/detect_platform.py
Executable file
98
scripts/release/detect_platform.py
Executable file
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Detect extension platform and type.
|
||||
|
||||
Copyright (C) 2025 Moko Consulting <hello@mokoconsulting.tech>
|
||||
|
||||
This file is part of a Moko Consulting project.
|
||||
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program (./LICENSE.md).
|
||||
|
||||
FILE INFORMATION
|
||||
DEFGROUP: Script.Release
|
||||
INGROUP: Extension.Detection
|
||||
REPO: https://github.com/mokoconsulting-tech/moko-cassiopeia
|
||||
PATH: /scripts/release/detect_platform.py
|
||||
VERSION: 01.00.00
|
||||
BRIEF: Detect extension platform and type for build workflow
|
||||
USAGE: ./scripts/release/detect_platform.py [src_dir]
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add lib directory to path
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent / "lib"))
|
||||
|
||||
try:
|
||||
import extension_utils
|
||||
except ImportError:
|
||||
print("ERROR: Cannot import extension_utils library", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
"""Main entry point."""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Detect extension platform and type",
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"src_dir",
|
||||
nargs="?",
|
||||
default="src",
|
||||
help="Source directory (default: src)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--format",
|
||||
choices=["pipe", "json"],
|
||||
default="pipe",
|
||||
help="Output format (default: pipe)"
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
ext_info = extension_utils.get_extension_info(args.src_dir)
|
||||
|
||||
if not ext_info:
|
||||
print(f"ERROR: No extension detected in {args.src_dir}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
if args.format == "pipe":
|
||||
# Format: platform|ext_type
|
||||
print(f"{ext_info.platform.value}|{ext_info.extension_type}")
|
||||
elif args.format == "json":
|
||||
import json
|
||||
data = {
|
||||
"platform": ext_info.platform.value,
|
||||
"extension_type": ext_info.extension_type,
|
||||
"name": ext_info.name,
|
||||
"version": ext_info.version
|
||||
}
|
||||
print(json.dumps(data))
|
||||
|
||||
return 0
|
||||
|
||||
except Exception as e:
|
||||
print(f"ERROR: {e}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user