name: AI Agent - Test & Deploy on: push: branches: - master paths: - 'mnemo_cards_web_v2/**' - 'mnemo_cards_backend/**' - 'mnemo_cards_common/**' workflow_dispatch: inputs: component: description: 'Component to test' required: true type: choice options: - web_v2 - backend - common jobs: detect-changes: runs-on: ubuntu-latest outputs: web_v2: ${{ steps.changes.outputs.web_v2 }} backend: ${{ steps.changes.outputs.backend }} common: ${{ steps.changes.outputs.common }} steps: - uses: actions/checkout@v3 with: fetch-depth: 2 - name: Detect changes id: changes run: | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then # Manual trigger - test specified component case "${{ inputs.component }}" in web_v2) echo "web_v2=true" >> $GITHUB_OUTPUT ;; backend) echo "backend=true" >> $GITHUB_OUTPUT ;; common) echo "common=true" >> $GITHUB_OUTPUT ;; esac else # Auto trigger - detect from git diff git diff --name-only HEAD^ HEAD > changed_files.txt if grep -q "mnemo_cards_web_v2/" changed_files.txt; then echo "web_v2=true" >> $GITHUB_OUTPUT else echo "web_v2=false" >> $GITHUB_OUTPUT fi if grep -q "mnemo_cards_backend/" changed_files.txt; then echo "backend=true" >> $GITHUB_OUTPUT else echo "backend=false" >> $GITHUB_OUTPUT fi if grep -q "mnemo_cards_common/" changed_files.txt; then echo "common=true" >> $GITHUB_OUTPUT else echo "common=false" >> $GITHUB_OUTPUT fi fi test-web-v2: needs: detect-changes if: needs.detect-changes.outputs.web_v2 == 'true' runs-on: ubuntu-latest timeout-minutes: 30 steps: - uses: actions/checkout@v3 - name: Set up Flutter run: | git clone https://github.com/flutter/flutter.git -b stable --depth 1 $HOME/flutter export PATH="$HOME/flutter/bin:$PATH" echo "$HOME/flutter/bin" >> $GITHUB_PATH flutter --version flutter doctor - name: Install dependencies run: | cd mnemo_cards_web_v2 flutter pub get - name: Run analyzer run: | cd mnemo_cards_web_v2 flutter analyze - name: Run tests run: | cd mnemo_cards_web_v2 flutter test --coverage - name: Build web run: | cd mnemo_cards_web_v2 flutter build web --release - name: Create test report if: always() run: | echo "# Web v2 Test Results" > /tmp/test_report.md echo "✅ Tests passed" >> /tmp/test_report.md cat /tmp/test_report.md test-backend: needs: detect-changes if: needs.detect-changes.outputs.backend == 'true' runs-on: ubuntu-latest timeout-minutes: 30 steps: - uses: actions/checkout@v3 - name: Set up Dart uses: dart-lang/setup-dart@v1 with: sdk: stable - name: Install dependencies run: | cd mnemo_cards_backend dart pub get - name: Run analyzer run: | cd mnemo_cards_backend dart analyze - name: Run tests run: | cd mnemo_cards_backend dart test - name: Create test report if: always() run: | echo "# Backend Test Results" > /tmp/test_report.md echo "✅ Tests passed" >> /tmp/test_report.md cat /tmp/test_report.md test-common: needs: detect-changes if: needs.detect-changes.outputs.common == 'true' runs-on: ubuntu-latest timeout-minutes: 15 steps: - uses: actions/checkout@v3 - name: Set up Dart uses: dart-lang/setup-dart@v1 with: sdk: stable - name: Install dependencies run: | cd mnemo_cards_common dart pub get - name: Run analyzer run: | cd mnemo_cards_common dart analyze - name: Run tests run: | cd mnemo_cards_common dart test - name: Create test report if: always() run: | echo "# Common Test Results" > /tmp/test_report.md echo "✅ Tests passed" >> /tmp/test_report.md cat /tmp/test_report.md deploy-staging: needs: [test-web-v2, test-backend, test-common] if: always() && (needs.test-web-v2.result == 'success' || needs.test-backend.result == 'success') runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Deploy notification run: | echo "# Deployment" > /tmp/deploy_summary.md echo "🚀 Ready for deployment to staging" >> /tmp/deploy_summary.md echo "Note: Actual deployment logic should be added here" >> /tmp/deploy_summary.md cat /tmp/deploy_summary.md report-failure: needs: [test-web-v2, test-backend, test-common] if: always() && (needs.test-web-v2.result == 'failure' || needs.test-backend.result == 'failure' || needs.test-common.result == 'failure') runs-on: ubuntu-latest steps: - name: Create failure issue via Forgejo API run: | # Collect failed components COMPONENTS="" if [ "${{ needs.test-web-v2.result }}" = "failure" ]; then COMPONENTS="${COMPONENTS}web_v2," fi if [ "${{ needs.test-backend.result }}" = "failure" ]; then COMPONENTS="${COMPONENTS}backend," fi if [ "${{ needs.test-common.result }}" = "failure" ]; then COMPONENTS="${COMPONENTS}common," fi COMPONENTS=${COMPONENTS%,} # Remove trailing comma # Create issue body TITLE="🤖 AI Agent Test Failure: ${COMPONENTS}" BODY="# ❌ Test Failure\\n\\n" BODY="${BODY}**Components:** ${COMPONENTS}\\n" BODY="${BODY}**Workflow:** ${{ github.workflow }}\\n" BODY="${BODY}**Run Number:** ${{ github.run_number }}\\n\\n" BODY="${BODY}[View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})\\n\\n" BODY="${BODY}---\\n*This issue was created automatically by the AI Agent system*" # Create issue via Forgejo API API_URL="${{ github.api_url }}/repos/${{ github.repository }}/issues" curl -X POST "$API_URL" \ -H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \ -H "Content-Type: application/json" \ -d "{\"title\":\"${TITLE}\",\"body\":\"${BODY}\",\"labels\":[\"ai-agent\",\"test-failure\"]}"