Add CI improvements and version management scripts

Co-authored-by: jmiller-moko <230051081+jmiller-moko@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-04 01:24:38 +00:00
parent de6b40413d
commit d89744df28
6 changed files with 721 additions and 0 deletions

View File

@@ -0,0 +1,134 @@
#!/usr/bin/env bash
# ============================================================================
# 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.Validate
# INGROUP: Version.Management
# REPO: https://github.com/mokoconsulting-tech/moko-cassiopeia
# PATH: /scripts/validate/version_hierarchy.sh
# VERSION: 01.00.00
# BRIEF: Validate version hierarchy across branch prefixes
# NOTE: Checks for version conflicts across dev/, rc/, and version/ branches
# ============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
. "${SCRIPT_DIR}/lib/common.sh"
# ----------------------------------------------------------------------------
# Functions
# ----------------------------------------------------------------------------
check_version_hierarchy() {
log_info "Checking version hierarchy across branch prefixes..."
local violations=0
# Get all branches with version-like names
local branches
branches=$(git ls-remote --heads origin 2>/dev/null | awk '{print $2}' | sed 's|refs/heads/||' || echo "")
if [ -z "$branches" ]; then
log_warn "No remote branches found or unable to fetch branches"
return 0
fi
# Extract versions from branches
local dev_versions=()
local rc_versions=()
local stable_versions=()
while IFS= read -r branch; do
if [[ "$branch" =~ ^dev/([0-9]{2}\.[0-9]{2}\.[0-9]{2})$ ]]; then
dev_versions+=("${BASH_REMATCH[1]}")
elif [[ "$branch" =~ ^rc/([0-9]{2}\.[0-9]{2}\.[0-9]{2})$ ]]; then
rc_versions+=("${BASH_REMATCH[1]}")
elif [[ "$branch" =~ ^version/([0-9]{2}\.[0-9]{2}\.[0-9]{2})$ ]]; then
stable_versions+=("${BASH_REMATCH[1]}")
fi
done <<< "$branches"
log_info "Found ${#dev_versions[@]} dev versions, ${#rc_versions[@]} RC versions, ${#stable_versions[@]} stable versions"
# Check for violations:
# 1. dev/ version that exists in rc/ or version/
for version in "${dev_versions[@]}"; do
# Check if exists in stable
for stable in "${stable_versions[@]}"; do
if [ "$version" = "$stable" ]; then
log_error "VIOLATION: Version $version exists in both dev/ and version/ branches"
violations=$((violations + 1))
fi
done
# Check if exists in RC
for rc in "${rc_versions[@]}"; do
if [ "$version" = "$rc" ]; then
log_error "VIOLATION: Version $version exists in both dev/ and rc/ branches"
violations=$((violations + 1))
fi
done
done
# 2. rc/ version that exists in version/
for version in "${rc_versions[@]}"; do
for stable in "${stable_versions[@]}"; do
if [ "$version" = "$stable" ]; then
log_error "VIOLATION: Version $version exists in both rc/ and version/ branches"
violations=$((violations + 1))
fi
done
done
if [ $violations -eq 0 ]; then
log_info "✓ No version hierarchy violations found"
return 0
else
log_error "✗ Found $violations version hierarchy violation(s)"
return 1
fi
}
# ----------------------------------------------------------------------------
# Main
# ----------------------------------------------------------------------------
log_info "Version Hierarchy Validation"
log_info "============================="
log_info ""
check_version_hierarchy
exit_code=$?
log_info ""
log_info "============================="
if [ $exit_code -eq 0 ]; then
log_info "Version hierarchy validation passed"
else
log_error "Version hierarchy validation failed"
fi
exit $exit_code

186
scripts/validate/workflows.sh Executable file
View File

@@ -0,0 +1,186 @@
#!/usr/bin/env bash
# ============================================================================
# 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.Validate
# INGROUP: CI.Validation
# REPO: https://github.com/mokoconsulting-tech/moko-cassiopeia
# PATH: /scripts/validate/workflows.sh
# VERSION: 01.00.00
# BRIEF: Validate GitHub Actions workflow files
# NOTE: Checks YAML syntax, structure, and best practices
# ============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
. "${SCRIPT_DIR}/lib/common.sh"
# ----------------------------------------------------------------------------
# Functions
# ----------------------------------------------------------------------------
validate_yaml_syntax() {
local file="$1"
if ! command -v python3 >/dev/null 2>&1; then
log_warn "python3 not found, skipping YAML syntax validation"
return 0
fi
python3 - "$file" <<'PYEOF'
import sys
import yaml
file_path = sys.argv[1]
try:
with open(file_path, 'r') as f:
yaml.safe_load(f)
print(f"✓ Valid YAML: {file_path}")
sys.exit(0)
except yaml.YAMLError as e:
print(f"✗ YAML Error in {file_path}: {e}", file=sys.stderr)
sys.exit(1)
except Exception as e:
print(f"✗ Error reading {file_path}: {e}", file=sys.stderr)
sys.exit(1)
PYEOF
}
check_no_tabs() {
local file="$1"
if grep -q $'\t' "$file"; then
log_error "✗ File contains tab characters: $file"
return 1
fi
return 0
}
check_workflow_structure() {
local file="$1"
local filename=$(basename "$file")
# Check for required top-level keys
if ! grep -q "^name:" "$file"; then
log_warn "Missing 'name:' in $filename"
fi
if ! grep -q "^on:" "$file"; then
log_error "✗ Missing 'on:' trigger in $filename"
return 1
fi
if ! grep -q "^jobs:" "$file"; then
log_error "✗ Missing 'jobs:' in $filename"
return 1
fi
return 0
}
validate_workflow_file() {
local file="$1"
local filename=$(basename "$file")
log_info "Validating: $filename"
local errors=0
# Check YAML syntax
if ! validate_yaml_syntax "$file"; then
errors=$((errors + 1))
fi
# Check for tabs
if ! check_no_tabs "$file"; then
errors=$((errors + 1))
fi
# Check structure
if ! check_workflow_structure "$file"; then
errors=$((errors + 1))
fi
if [ $errors -eq 0 ]; then
log_info "$filename passed all checks"
return 0
else
log_error "$filename failed $errors check(s)"
return 1
fi
}
# ----------------------------------------------------------------------------
# Main
# ----------------------------------------------------------------------------
log_info "GitHub Actions Workflow Validation"
log_info "==================================="
log_info ""
WORKFLOWS_DIR=".github/workflows"
if [ ! -d "$WORKFLOWS_DIR" ]; then
log_error "Workflows directory not found: $WORKFLOWS_DIR"
exit 1
fi
total=0
passed=0
failed=0
for workflow in "$WORKFLOWS_DIR"/*.yml "$WORKFLOWS_DIR"/*.yaml; do
if [ ! -f "$workflow" ]; then
continue
fi
total=$((total + 1))
if validate_workflow_file "$workflow"; then
passed=$((passed + 1))
else
failed=$((failed + 1))
fi
echo ""
done
log_info "==================================="
log_info "Summary:"
log_info " Total workflows: $total"
log_info " Passed: $passed"
log_info " Failed: $failed"
log_info "==================================="
if [ $failed -gt 0 ]; then
log_error "Workflow validation failed"
exit 1
fi
log_info "All workflows validated successfully"
exit 0