Files
MokoCassiopeia/scripts/validate/version_alignment.sh
copilot-swe-agent[bot] 5779dcb73e Fix CI validation scripts: correct heredoc quoting, CRLF robustness, and path detection
- Replace version_alignment.sh with simplified version using quoted heredoc (<<'PY')
- Replace tabs.sh with bash-native implementation using safe loops and grep
- Replace paths.sh with git ls-files -z based implementation for binary-safe processing
- All scripts now handle CRLF line endings correctly
- Quoted heredocs prevent shell interpolation issues
- Scripts successfully detect their target conditions (tabs, windows paths, version mismatches)

Co-authored-by: jmiller-moko <230051081+jmiller-moko@users.noreply.github.com>
2026-01-03 20:57:59 +00:00

71 lines
1.9 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
# Validate that the package/manifest version is present in CHANGELOG.md
# This script uses a safe, quoted heredoc for the embedded Python to avoid
# shell interpolation and CRLF termination issues.
if ! command -v python3 >/dev/null 2>&1; then
echo "ERROR: python3 not found" >&2
exit 1
fi
python3 - <<'PY'
import sys, re, json
# Locate a likely manifest under src
candidates = [
'src/templateDetails.xml',
'src/manifest.xml'
]
manifest = None
for p in candidates:
try:
with open(p, 'r', encoding='utf-8') as fh:
manifest = fh.read()
break
except FileNotFoundError:
pass
if manifest is None:
# Fallback: search for an XML file under src that contains a version attribute
import glob
for fn in glob.glob('src/**/*.xml', recursive=True):
try:
with open(fn, 'r', encoding='utf-8') as fh:
txt = fh.read()
if 'version=' in txt:
manifest = txt
break
except Exception:
continue
if manifest is None:
print('WARNING: No manifest found, skipping version alignment check')
sys.exit(0)
# Try attribute first (version="X.Y.Z"), then element (<version>X.Y.Z</version>)
m = re.search(r'version=["\']([0-9]+\.[0-9]+\.[0-9]+)["\']', manifest)
if not m:
m = re.search(r'<version>([0-9]+\.[0-9]+\.[0-9]+)</version>', manifest)
if not m:
print('ERROR: could not find semantic version in manifest')
sys.exit(2)
manifest_version = m.group(1)
try:
with open('CHANGELOG.md', 'r', encoding='utf-8') as fh:
changelog = fh.read()
except FileNotFoundError:
print('ERROR: CHANGELOG.md not found')
sys.exit(2)
if f'## [{manifest_version}]' not in changelog:
print(f'ERROR: version {manifest_version} missing from CHANGELOG.md')
sys.exit(2)
print(json.dumps({'status': 'ok', 'version': manifest_version}))
sys.exit(0)
PY