Files
dance-lessons-coach/scripts/cicd/validate-workflow.sh
Gabriel Radureau 370fbdf72f
Some checks failed
Go CI/CD Pipeline / Lint and Format (push) Successful in 54s
Go CI/CD Pipeline / Arcodange Workflow Validation (push) Failing after 6m15s
Go CI/CD Pipeline / Lint and Format (pull_request) Successful in 2m22s
Go CI/CD Pipeline / Arcodange Workflow Validation (pull_request) Failing after 2m34s
Go CI/CD Pipeline / Build and Test (pull_request) Successful in 4m35s
Go CI/CD Pipeline / Version Management (pull_request) Has been skipped
Go CI/CD Pipeline / Build and Test (push) Successful in 12m7s
Go CI/CD Pipeline / Version Management (push) Has been cancelled
🐛 fix: resolve CI workflow issues
Fix three critical CI issues:

1. SWAG TOOL: Install swag before go generate

   - Adds 'Install swag' step to build-test job

   - Prevents 'command not found' errors

   - Ensures swagger docs can be generated

2. GO VET REDUNDANCY: Remove duplicate go vet

   - Removes go vet from lint-format job

   - Keeps go vet only in build-test job

   - Reduces CI execution time

3. WORKFLOW VALIDATION: Fix yamllint path

   - Updates validate-workflow.sh to use absolute paths

   - Fixes .yamllint.yaml file not found error

   - Makes path resolution more robust

These fixes address the root causes of:

- Job 350 failure (missing swag)

- Redundant validation (duplicate go vet)

- Workflow validation failures (wrong paths)

Tested locally and ready for CI.
2026-04-06 12:53:43 +02:00

151 lines
4.6 KiB
Bash
Executable File

#!/bin/bash
# Validate CI/CD workflow syntax and structure
set -e
echo "🔍 Validating CI/CD Workflow"
echo "================================"
# 1. Check workflow files exist
WORKFLOW_FILES=(
".gitea/workflows/go-ci-cd.yaml"
".gitea/workflows/dockerimage.yaml"
)
for file in "${WORKFLOW_FILES[@]}"; do
if [ ! -f "$file" ]; then
echo "❌ Workflow file not found: $file"
exit 1
fi
echo "✅ Workflow file found: $file"
done
# 2. Validate YAML syntax for all workflows
if command -v yq >/dev/null 2>&1; then
for file in "${WORKFLOW_FILES[@]}"; do
if ! yq eval '.' "$file" > /dev/null 2>&1; then
echo "❌ Invalid YAML syntax in: $file"
yq eval '.' "$file" || true
exit 1
fi
echo "✅ YAML syntax valid: $file"
done
else
echo "⚠️ yq not installed, skipping YAML validation"
fi
# 3. YAML Linting with custom config for all workflows
if command -v yamllint >/dev/null 2>&1; then
for file in "${WORKFLOW_FILES[@]}"; do
if [ -f ".yamllint.yaml" ]; then
yamllint -c "$(pwd)/.yamllint.yaml" "$file"
else
yamllint "$file"
fi
done
elif docker info >/dev/null 2>&1; then
for file in "${WORKFLOW_FILES[@]}"; do
if [ -f ".yamllint.yaml" ]; then
docker run --rm -v $(pwd):/workspace -w /workspace pipelinecomponents/yamllint:latest \
yamllint -c /workspace/.yamllint.yaml "$file"
else
docker run --rm -v $(pwd):/workspace -w /workspace pipelinecomponents/yamllint:latest \
yamllint "$file"
fi
done
else
echo "⚠️ Neither yamllint nor docker available, skipping linting"
fi
# 3. Check required fields for all workflows
for file in "${WORKFLOW_FILES[@]}"; do
MISSING_FIELDS=()
if command -v yq >/dev/null 2>&1; then
workflow_name=$(basename "$file" .yaml)
if [ -z "$(yq eval '.name' "$file" 2>/dev/null)" ]; then
MISSING_FIELDS+=("name")
fi
if [ -z "$(yq eval '.on' "$file" 2>/dev/null)" ]; then
MISSING_FIELDS+=("on")
fi
if [ -z "$(yq eval '.jobs' "$file" 2>/dev/null)" ]; then
MISSING_FIELDS+=("jobs")
fi
if [ ${#MISSING_FIELDS[@]} -gt 0 ]; then
echo "❌ Missing required fields in $workflow_name: ${MISSING_FIELDS[*]}"
exit 1
fi
echo "✅ All required fields present in $workflow_name"
else
echo "⚠️ yq not installed, skipping field validation for $file"
fi
done
# 4. Check jobs structure
if command -v yq >/dev/null 2>&1; then
JOBS=$(yq eval '.jobs | keys' .gitea/workflows/ci-cd.yaml 2>/dev/null)
echo "📋 Jobs defined: $JOBS"
for job in $JOBS; do
job_str=$(echo $job | tr -d '"')
# Check job has steps
if [ -z "$(yq eval ".jobs.$job_str.steps" .gitea/workflows/ci-cd.yaml 2>/dev/null)" ]; then
echo "❌ Job $job_str has no steps"
exit 1
fi
steps_count=$(yq eval ".jobs.$job_str.steps | length" .gitea/workflows/ci-cd.yaml 2>/dev/null)
echo "$job_str: $steps_count steps"
done
else
echo "⚠️ yq not installed, skipping job structure validation"
fi
# 5. Check Arcodange-specific configurations
if command -v yq >/dev/null 2>&1; then
if [ -n "$(yq eval '.env.GITEA_INTERNAL' .gitea/workflows/ci-cd.yaml 2>/dev/null)" ]; then
echo "✅ Arcodange internal URL configured"
else
echo "⚠️ Arcodange internal URL not found"
fi
if [ -n "$(yq eval '.env.GITEA_EXTERNAL' .gitea/workflows/ci-cd.yaml 2>/dev/null)" ]; then
echo "✅ Arcodange external URL configured"
else
echo "⚠️ Arcodange external URL not found"
fi
# 6. Check concurrency settings
if [ -n "$(yq eval '.concurrency' .gitea/workflows/ci-cd.yaml 2>/dev/null)" ]; then
echo "✅ Concurrency control configured"
else
echo "⚠️ No concurrency control (consider adding)"
fi
else
echo "⚠️ yq not installed, skipping Arcodange-specific validations"
fi
echo ""
echo "🎉 Workflow Validation Successful!"
echo "================================"
echo "📁 Workflows validated:"
for file in "${WORKFLOW_FILES[@]}"; do
echo " - $file"
done
if command -v yq >/dev/null 2>&1; then
echo "🔧 Summary:"
for file in "${WORKFLOW_FILES[@]}"; do
workflow_name=$(basename "$file" .yaml)
JOBS=$(yq eval '.jobs | keys | join(", ")' "$file" 2>/dev/null || echo 'Unable to parse')
echo " - $workflow_name: $JOBS"
done
else
echo "🔧 Jobs: yq not installed"
fi
echo "🎯 Ready for deployment"