soma-core 2.0.0

World's first production-ready self-aware development system with meta-cognitive capabilities and cognitive reasoning engine for intelligent development platforms
Documentation
name: 🚀 SOMA-CORE Project Sync

on:
  push:
    branches: [main, develop]
    paths:
      - 'plan.md'
      - 'PROJECT_STATUS.md'
      - 'src/agents/**'
      - 'scripts/github-automation/**'
  workflow_dispatch:
    inputs:
      task_type:
        description: 'Type of tasks to create'
        required: false
        default: 'all'
        type: choice
        options:
          - all
          - operators-only
          - edit-control-only
          - workflow-only
      dry_run:
        description: 'Dry run (preview only)'
        required: false
        default: false
        type: boolean

env:
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  GITHUB_USERNAME: ${{ github.repository_owner }}
  GITHUB_REPO: ${{ github.event.repository.name }}

jobs:
  project-sync:
    name: 📋 Sync GitHub Project
    runs-on: ubuntu-latest
    
    steps:
      - name: 🏗️ Checkout Repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 2
          
      - name: 🔍 Check for Relevant Changes
        id: changes
        run: |
          if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
            echo "manual_trigger=true" >> $GITHUB_OUTPUT
            exit 0
          fi
          
          # Check if plan.md or PROJECT_STATUS.md changed
          if git diff --name-only HEAD^ HEAD | grep -E "(plan\.md|PROJECT_STATUS\.md)"; then
            echo "plan_changed=true" >> $GITHUB_OUTPUT
          fi
          
          # Check if new agents were added
          if git diff --name-only HEAD^ HEAD | grep "src/agents/"; then
            echo "agents_changed=true" >> $GITHUB_OUTPUT
          fi
          
      - name: 🔧 Setup Dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y jq curl
          
      - name: 📝 Generate Project Configuration
        id: config
        run: |
          # Get project ID automatically
          PROJECT_QUERY='query { viewer { projectsV2(first: 20) { nodes { id title url } } } }'
          PROJECT_RESPONSE=$(curl -s -H "Authorization: bearer ${{ secrets.GITHUB_TOKEN }}" \
            -X POST -d "{\"query\": \"$PROJECT_QUERY\"}" \
            https://api.github.com/graphql)
          
          PROJECT_ID=$(echo "$PROJECT_RESPONSE" | jq -r '.data.viewer.projectsV2.nodes[] | select(.title | test("SOMA"; "i")) | .id')
          
          if [[ -n "$PROJECT_ID" && "$PROJECT_ID" != "null" ]]; then
            echo "project_id=$PROJECT_ID" >> $GITHUB_OUTPUT
            echo "✅ Found SOMA project: $PROJECT_ID"
          else
            echo "⚠️ SOMA project not found, will create issues without project assignment"
            echo "project_id=" >> $GITHUB_OUTPUT
          fi
          
      - name: 🚀 Create Project Cards
        if: steps.changes.outputs.plan_changed == 'true' || steps.changes.outputs.agents_changed == 'true' || steps.changes.outputs.manual_trigger == 'true'
        env:
          GITHUB_PROJECT_ID: ${{ steps.config.outputs.project_id }}
          DEFAULT_LABELS: "soma++,operator,enhancement"
        run: |
          # Make scripts executable
          chmod +x scripts/github-automation/*.sh
          
          # Determine task type
          TASK_TYPE="${{ github.event.inputs.task_type || 'all' }}"
          DRY_RUN="${{ github.event.inputs.dry_run || 'false' }}"
          
          echo "🎯 Task Type: $TASK_TYPE"
          echo "🔍 Dry Run: $DRY_RUN"
          
          if [[ "$DRY_RUN" == "true" ]]; then
            echo "🔍 DRY RUN MODE - No issues will be created"
            # You could add preview logic here
            exit 0
          fi
          
          # Create config for the script
          cat > scripts/github-automation/config.env << EOF
          GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}"
          GITHUB_USERNAME="${{ github.repository_owner }}"
          GITHUB_REPO="${{ github.event.repository.name }}"
          GITHUB_PROJECT_ID="${{ steps.config.outputs.project_id }}"
          DEFAULT_LABELS="soma++,operator,enhancement"
          ISSUE_TEMPLATE_DIR="./issue-templates"
          EOF
          
          # Run the appropriate script
          case "$TASK_TYPE" in
            "operators-only")
              ./scripts/github-automation/create-cards.sh --operators-only
              ;;
            "edit-control-only")
              ./scripts/github-automation/create-cards.sh --edit-control-only
              ;;
            "workflow-only")
              ./scripts/github-automation/create-cards.sh --workflow-only
              ;;
            *)
              ./scripts/github-automation/create-cards.sh
              ;;
          esac
          
      - name: 📊 Update Project Status
        if: success()
        run: |
          # Update PROJECT_STATUS.md with automation info
          DATE=$(date '+%Y-%m-%d %H:%M:%S UTC')
          
          cat >> PROJECT_STATUS.md << EOF
          
          ## 🤖 GitHub Automation Status
          **Last Sync:** $DATE  
          **Trigger:** ${{ github.event_name }}  
          **Tasks Created:** ${{ github.event.inputs.task_type || 'all' }}  
          **Commit:** ${{ github.sha }}
          EOF
          
      - name: 💾 Commit Updates
        if: success()
        run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          
          if git diff --quiet PROJECT_STATUS.md; then
            echo "No changes to commit"
          else
            git add PROJECT_STATUS.md
            git commit -m "🤖 Update project status after GitHub automation sync"
            git push
          fi

  notification:
    name: 📢 Send Notification
    runs-on: ubuntu-latest
    needs: project-sync
    if: always()
    
    steps:
      - name: 📤 Notify Success
        if: needs.project-sync.result == 'success'
        run: |
          echo "✅ SOMA-CORE project sync completed successfully!"
          
      - name: 📤 Notify Failure
        if: needs.project-sync.result == 'failure'
        run: |
          echo "❌ SOMA-CORE project sync failed. Check the logs for details."