Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
349 changes: 349 additions & 0 deletions .github/workflows/cyberai-super-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,349 @@
name: CyberAi Super Workflow

on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
# Run daily at 2 AM UTC
- cron: '0 2 * * *'
workflow_dispatch:
inputs:
mode:
description: 'Execution mode'
required: false
default: 'dry-run'
type: choice
options:
- dry-run
- production
audit_depth:
description: 'Audit depth'
required: false
default: 'standard'
type: choice
options:
- quick
- standard
- deep

env:
DRY_RUN: true
PNPM: pnpm

permissions:
contents: read
pull-requests: write
issues: write

jobs:
orchestrate:
name: CyberAi Bot Orchestration
runs-on: ubuntu-latest

permissions:
contents: read
pull-requests: write
actions: read
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The job-level permissions block omits issues: write, but the workflow later uses github.rest.issues.createComment(...) to comment on PRs. Because job-level permissions override the workflow-level permissions, this step is likely to fail with an authorization error. Add issues: write to the orchestrate job permissions (or remove the job-level override so the workflow-level issues: write applies).

Suggested change
actions: read
actions: read
issues: write

Copilot uses AI. Check for mistakes.

steps:
- name: Checkout SmartContractAudit
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install pnpm
run: npm install -g pnpm

- name: Setup Environment
run: |
echo "Setting up CyberAi Bot environment..."

# Copy environment template
if [ -f .env.example ]; then
cp .env.example .env
fi

# Configure dry-run mode
echo "DRY_RUN=true" >> .env
echo "PNPM=pnpm" >> .env
echo "LOG_LEVEL=INFO" >> .env

# Make scripts executable
chmod +x scripts/*.sh

# Create necessary directories
mkdir -p logs
mkdir -p reports
mkdir -p .quarantine

- name: Install Dependencies
if: hashFiles('package.json') != ''
run: |
if [ -f pnpm-lock.yaml ]; then
pnpm install --frozen-lockfile || pnpm install
else
pnpm install || true
fi

- name: SmartBrain Health Check
id: health_check
run: |
echo "Running SmartBrain health check..."

# Run health check
./scripts/master.sh health || echo "Health check completed with warnings"

# Check if SMARTBRAIN.log exists and has content
if [ -f SMARTBRAIN.log ]; then
echo "health_status=success" >> $GITHUB_OUTPUT
echo "Health check log:"
tail -20 SMARTBRAIN.log
else
echo "health_status=warning" >> $GITHUB_OUTPUT
fi

- name: CyberAi Bot - Audit Orchestration
id: audit
if: github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
run: |
echo "Starting CyberAi Bot audit orchestration..."

# Determine audit mode
AUDIT_MODE="${{ github.event.inputs.mode || 'dry-run' }}"
AUDIT_DEPTH="${{ github.event.inputs.audit_depth || 'standard' }}"

echo "Audit mode: $AUDIT_MODE"
echo "Audit depth: $AUDIT_DEPTH"

# Run audit through SmartBrain orchestrator
if [ "$AUDIT_MODE" = "dry-run" ]; then
export DRY_RUN=true
else
export DRY_RUN=false
fi

# Execute audit
./scripts/master.sh audit || echo "Audit completed with findings"

# Store audit status
if [ -f AUDIT-REPORT.md ]; then
echo "audit_status=completed" >> $GITHUB_OUTPUT
else
echo "audit_status=no_report" >> $GITHUB_OUTPUT
fi

- name: CyberAi Bot - Security Scan
id: security_scan
run: |
echo "Running CyberAi Bot security scan..."

# Run security scan
./scripts/master.sh scan || echo "Security scan completed"

# Check quarantine
if [ -d .quarantine ] && [ "$(ls -A .quarantine)" ]; then
echo "scan_findings=true" >> $GITHUB_OUTPUT
echo "Security findings detected in .quarantine/"
else
echo "scan_findings=false" >> $GITHUB_OUTPUT
echo "No security issues detected"
fi

- name: CyberAi Bot - Integrity Check
id: integrity
if: github.event_name == 'pull_request' || github.event_name == 'push'
run: |
echo "Running CyberAi Bot integrity check..."

# Run integrity check
./scripts/master.sh integrity || echo "Integrity check completed"

echo "integrity_status=completed" >> $GITHUB_OUTPUT

- name: CyberAi Bot - Aggregate Results
id: aggregate
run: |
echo "Aggregating CyberAi Bot results..."

# Create comprehensive report
cat > reports/cyberai-summary.md <<EOF
# CyberAi Bot Execution Summary

**Run Date**: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
**Trigger**: ${{ github.event_name }}
**Branch**: ${{ github.ref_name }}
**Commit**: ${{ github.sha }}

## Results

### Health Check
- Status: ${{ steps.health_check.outputs.health_status || 'not_run' }}

### Audit
- Status: ${{ steps.audit.outputs.audit_status || 'not_run' }}
- Mode: ${{ github.event.inputs.mode || 'dry-run' }}

### Security Scan
- Status: ${{ steps.security_scan.outputs.scan_findings == 'true' && 'findings_detected' || 'clean' }}

### Integrity Check
- Status: ${{ steps.integrity.outputs.integrity_status || 'not_run' }}

## Logs

EOF

# Append SmartBrain log if exists
if [ -f SMARTBRAIN.log ]; then
echo "### SmartBrain Log (Last 50 lines)" >> reports/cyberai-summary.md
echo '```' >> reports/cyberai-summary.md
tail -50 SMARTBRAIN.log >> reports/cyberai-summary.md
echo '```' >> reports/cyberai-summary.md
fi

# Display summary
cat reports/cyberai-summary.md

- name: Upload Audit Report
if: steps.audit.outputs.audit_status == 'completed'
uses: actions/upload-artifact@v4
with:
name: audit-report-${{ github.run_number }}
path: |
AUDIT-REPORT.md
SMARTBRAIN.log
retention-days: 30

- name: Upload Security Findings
if: steps.security_scan.outputs.scan_findings == 'true'
uses: actions/upload-artifact@v4
with:
name: security-findings-${{ github.run_number }}
path: .quarantine/
retention-days: 90

- name: Upload CyberAi Summary
uses: actions/upload-artifact@v4
with:
name: cyberai-summary-${{ github.run_number }}
path: reports/cyberai-summary.md
retention-days: 30

- name: Comment on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');

let body = '## 🤖 CyberAi Bot Report\n\n';

// Add health check status
body += '### Health Check\n';
body += `- Status: ${{ steps.health_check.outputs.health_status }}\n\n`;

// Add audit status
if ('${{ steps.audit.outputs.audit_status }}' !== 'not_run') {
body += '### Audit\n';
body += `- Status: ${{ steps.audit.outputs.audit_status }}\n`;
Comment on lines +253 to +255
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the PR comment script, the audit section is gated by if ('${{ steps.audit.outputs.audit_status }}' !== 'not_run'), but the audit step is skipped on pull_request events. When a step is skipped, its outputs are empty, so this condition becomes true and the comment will include an Audit section with empty values. Gate on whether the step actually ran (e.g., check steps.audit.conclusion != 'skipped' or use an expression fallback like steps.audit.outputs.audit_status || 'not_run' consistently).

Suggested change
if ('${{ steps.audit.outputs.audit_status }}' !== 'not_run') {
body += '### Audit\n';
body += `- Status: ${{ steps.audit.outputs.audit_status }}\n`;
if ("${{ steps.audit.outputs.audit_status || 'not_run' }}" !== 'not_run') {
body += '### Audit\n';
body += `- Status: ${{ steps.audit.outputs.audit_status || 'not_run' }}\n`;

Copilot uses AI. Check for mistakes.
body += `- Mode: ${{ github.event.inputs.mode || 'dry-run' }}\n\n`;
}

// Add security scan results
body += '### Security Scan\n';
if ('${{ steps.security_scan.outputs.scan_findings }}' === 'true') {
body += '⚠️ Security findings detected. Please review the artifacts.\n\n';
} else {
body += '✅ No security issues detected.\n\n';
}

// Add integrity check
if ('${{ steps.integrity.outputs.integrity_status }}' !== 'not_run') {
body += '### Integrity Check\n';
body += `- Status: ${{ steps.integrity.outputs.integrity_status }}\n\n`;
}

body += '---\n';
body += '*CyberAi Bot - Smart Brain Security for Smart Contracts*\n';
body += `*Workflow run: [#${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})*`;

github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});

- name: Set Job Summary
run: |
cat >> $GITHUB_STEP_SUMMARY <<EOF
# CyberAi Bot Execution Summary

## 🤖 Overview

**Orchestrator**: SmartBrain (master.sh)
**Mode**: ${{ github.event.inputs.mode || 'dry-run' }}
**Trigger**: ${{ github.event_name }}

## 📊 Results

| Component | Status |
|-----------|--------|
| Health Check | ${{ steps.health_check.outputs.health_status || 'N/A' }} |
| Audit | ${{ steps.audit.outputs.audit_status || 'not_run' }} |
| Security Scan | ${{ steps.security_scan.outputs.scan_findings == 'true' && '⚠️ Findings' || '✅ Clean' }} |
| Integrity Check | ${{ steps.integrity.outputs.integrity_status || 'not_run' }} |

## 📁 Artifacts

- Audit Report: ${{ steps.audit.outputs.audit_status == 'completed' && '✅ Available' || 'N/A' }}
- Security Findings: ${{ steps.security_scan.outputs.scan_findings == 'true' && '⚠️ Available' || 'N/A' }}
- Summary Report: ✅ Available

## 🔗 Resources

- [CyberAi Architecture](docs/CYBERAI_ARCHITECTURE.md)
- [PR Merge Guide](docs/CYBERAI_PR_MERGE_GUIDE.md)
- [Setup Documentation](docs/cuberai-setup.md)

---

*CyberAi Bot orchestrates all SolanaRemix security tools while keeping SmartContract functions focused and separate.*
EOF

- name: Fail on Critical Security Findings
if: steps.security_scan.outputs.scan_findings == 'true' && github.event_name == 'pull_request'
run: |
echo "⚠️ Critical security findings detected in PR"
echo "Please review the security artifacts before merging"
echo "This is a warning - review required but not blocking"
# Uncomment the next line to make security findings blocking
# exit 1

notify:
name: Notification
runs-on: ubuntu-latest
needs: orchestrate
if: always() && (github.event_name == 'schedule' || github.event_name == 'push')

permissions:
contents: read

steps:
- name: Workflow Summary
run: |
echo "CyberAi Bot workflow completed"
echo "Status: ${{ needs.orchestrate.result }}"

if [ "${{ needs.orchestrate.result }}" = "success" ]; then
echo "✅ All checks passed"
else
echo "⚠️ Some checks require attention"
fi
Loading
Loading