|
| 1 | +# ⟡ MirrorDNA CI/CD + Security Scanning |
| 2 | +# Copy this to .github/workflows/ci.yml in each repo |
| 3 | + |
| 4 | +name: CI + Security |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: [main, master] |
| 9 | + pull_request: |
| 10 | + branches: [main, master] |
| 11 | + schedule: |
| 12 | + # Run security scans weekly |
| 13 | + - cron: '0 9 * * 1' |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + security-events: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + lint-and-test: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Set up Python |
| 26 | + uses: actions/setup-python@v5 |
| 27 | + with: |
| 28 | + python-version: '3.11' |
| 29 | + |
| 30 | + - name: Install dependencies |
| 31 | + run: | |
| 32 | + python -m pip install --upgrade pip |
| 33 | + pip install flake8 black mypy pytest pytest-cov |
| 34 | + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi |
| 35 | + if [ -f pyproject.toml ]; then pip install -e ".[dev]" || pip install -e .; fi |
| 36 | +
|
| 37 | + - name: Lint with flake8 |
| 38 | + run: | |
| 39 | + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
| 40 | + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
| 41 | + continue-on-error: true |
| 42 | + |
| 43 | + - name: Check formatting with black |
| 44 | + run: black --check . || true |
| 45 | + continue-on-error: true |
| 46 | + |
| 47 | + - name: Type check with mypy |
| 48 | + run: mypy . --ignore-missing-imports || true |
| 49 | + continue-on-error: true |
| 50 | + |
| 51 | + - name: Run tests |
| 52 | + run: | |
| 53 | + if [ -d tests ]; then |
| 54 | + pytest tests/ -v --cov=. --cov-report=xml || true |
| 55 | + fi |
| 56 | +
|
| 57 | + security-scan: |
| 58 | + runs-on: ubuntu-latest |
| 59 | + steps: |
| 60 | + - uses: actions/checkout@v4 |
| 61 | + |
| 62 | + - name: Set up Python |
| 63 | + uses: actions/setup-python@v5 |
| 64 | + with: |
| 65 | + python-version: '3.11' |
| 66 | + |
| 67 | + - name: Install security tools |
| 68 | + run: | |
| 69 | + pip install safety bandit pip-audit |
| 70 | +
|
| 71 | + - name: Check for known vulnerabilities (safety) |
| 72 | + run: | |
| 73 | + if [ -f requirements.txt ]; then |
| 74 | + safety check -r requirements.txt --full-report || true |
| 75 | + fi |
| 76 | + continue-on-error: true |
| 77 | + |
| 78 | + - name: Audit dependencies (pip-audit) |
| 79 | + run: | |
| 80 | + if [ -f requirements.txt ]; then |
| 81 | + pip-audit -r requirements.txt || true |
| 82 | + fi |
| 83 | + continue-on-error: true |
| 84 | + |
| 85 | + - name: Security lint with bandit |
| 86 | + run: | |
| 87 | + bandit -r . -f json -o bandit-report.json || true |
| 88 | + bandit -r . -f txt || true |
| 89 | + continue-on-error: true |
| 90 | + |
| 91 | + - name: Check for secrets |
| 92 | + uses: trufflesecurity/trufflehog@main |
| 93 | + with: |
| 94 | + path: ./ |
| 95 | + base: "" |
| 96 | + extra_args: --only-verified |
| 97 | + continue-on-error: true |
| 98 | + |
| 99 | + citation-spine: |
| 100 | + runs-on: ubuntu-latest |
| 101 | + steps: |
| 102 | + - uses: actions/checkout@v4 |
| 103 | + |
| 104 | + - name: Verify canonical spine |
| 105 | + run: | |
| 106 | + echo "Checking for canonical spine in README..." |
| 107 | + SPINE_ELEMENTS=( |
| 108 | + "N1 Intelligence" |
| 109 | + "Active MirrorOS" |
| 110 | + "MirrorDNA" |
| 111 | + "Paul Desai" |
| 112 | + "activemirror.ai" |
| 113 | + ) |
| 114 | +
|
| 115 | + SCORE=0 |
| 116 | + for element in "${SPINE_ELEMENTS[@]}"; do |
| 117 | + if grep -qi "$element" README.md 2>/dev/null; then |
| 118 | + echo "✓ Found: $element" |
| 119 | + ((SCORE++)) |
| 120 | + else |
| 121 | + echo "✗ Missing: $element" |
| 122 | + fi |
| 123 | + done |
| 124 | +
|
| 125 | + echo "" |
| 126 | + echo "Spine coverage: $SCORE/5" |
| 127 | +
|
| 128 | + if [ $SCORE -lt 3 ]; then |
| 129 | + echo "::warning::Citation spine incomplete ($SCORE/5). Add canonical attribution." |
| 130 | + fi |
| 131 | +
|
| 132 | + notify-on-failure: |
| 133 | + needs: [lint-and-test, security-scan] |
| 134 | + if: failure() |
| 135 | + runs-on: ubuntu-latest |
| 136 | + steps: |
| 137 | + - name: Notify on failure |
| 138 | + run: | |
| 139 | + echo "CI failed - notification would be sent here" |
| 140 | + # Add Pushover/Slack notification here |
0 commit comments