name: Nightly Evolution on: schedule: - cron: "0 3 * * *" # 03:00 UTC nightly workflow_dispatch: # manual trigger button permissions: contents: write # push merged mutations / attempt logs jobs: evolve: runs-on: ubuntu-latest timeout-minutes: 25 steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Kill switch run: | if [ -f EVOLUTION_PAUSED ]; then echo "Evolution paused by kill-switch file. Exiting cleanly." exit 0 fi - uses: actions/setup-python@v5 with: python-version: "3.12" - uses: actions/setup-node@v4 with: node-version: "20" - run: pip install -r requirements.txt -r requirements-dev.txt - name: Baseline - frozen suite must pass before evolving run: | pytest tests/ -q for f in dataset_embed.js app_v30.js globe_patch.js mapping_canvas.js; do node --check "static/$f" done - name: Propose mutation (one SEARCH/REPLACE edit) env: HF_TOKEN: ${{ secrets.HF_TOKEN }} run: python evolution/evolve.py - name: Detect mutation id: detect run: | if [ -f evolution/.mutation_applied ]; then echo "applied=true" >> "$GITHUB_OUTPUT" echo "Mutation applied to $(cat evolution/.mutation_applied)" else echo "applied=false" >> "$GITHUB_OUTPUT" echo "No usable mutation this cycle — clean no-op." fi - name: Guard - frozen files untouched if: steps.detect.outputs.applied == 'true' run: | if ! git diff --quiet -- tests/ .github/ requirements.txt requirements-dev.txt Dockerfile; then echo "VIOLATION: mutation touched frozen files. Reverting." git checkout -- tests/ .github/ requirements.txt requirements-dev.txt Dockerfile exit 1 fi - name: Validate mutation id: validate if: steps.detect.outputs.applied == 'true' continue-on-error: true run: | pytest tests/ -q for f in dataset_embed.js app_v30.js globe_patch.js mapping_canvas.js; do node --check "static/$f" done - name: Finalize — merge / revert / no-op, then push (+deploy on accept) env: HF_TOKEN: ${{ secrets.HF_TOKEN }} run: | git config user.name "evolution-bot" git config user.email "bot@users.noreply.github.com" rm -f evolution/.mutation_applied ts="$(date -u --iso-8601=seconds)" if [ "${{ steps.detect.outputs.applied }}" != "true" ]; then git add evolution/attempts.log git commit -m "evolve: no-op $(date -u +%F)" || echo "nothing to commit" git push origin HEAD:main || true exit 0 fi if [ "${{ steps.validate.outcome }}" = "success" ]; then echo "$ts | MERGED | tests passed" >> evolution/attempts.log git add main.py static/ evolution/attempts.log git commit -m "evolve: mutation accepted $(date -u +%F)" git push origin HEAD:main echo "Deploying to live HuggingFace Space..." git push "https://colesr:${HF_TOKEN}@huggingface.co/spaces/colesr/insight-engine-docker" HEAD:main else git checkout -- main.py static/ echo "$ts | REVERTED | tests failed" >> evolution/attempts.log git add evolution/attempts.log git commit -m "evolve: mutation reverted $(date -u +%F)" git push origin HEAD:main fi