name: Self-Healing on: schedule: - cron: '*/30 * * * *' workflow_dispatch: workflow_run: workflows: ["Auto Deploy"] types: [completed] jobs: monitor: name: Monitor Deployments runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Check Health id: health run: | if [ -n "${{ secrets.DEPLOY_URL }}" ]; then STATUS=$(curl -s -o /dev/null -w "%{http_code}" "${{ secrets.DEPLOY_URL }}/api/health" || echo "000") echo "status=$STATUS" >> $GITHUB_OUTPUT else echo "status=skip" >> $GITHUB_OUTPUT fi - name: Auto-Rollback if: steps.health.outputs.status != '200' && steps.health.outputs.status != 'skip' run: | echo "Health check failed (Status: ${{ steps.health.outputs.status }})" echo "Triggering rollback..." gh workflow run auto-deploy.yml --ref $(git rev-parse HEAD~1) || true env: GH_TOKEN: ${{ github.token }} - name: Create Issue on Failure if: steps.health.outputs.status != '200' && steps.health.outputs.status != 'skip' uses: actions/github-script@v7 with: script: | const issues = await github.rest.issues.listForRepo({ owner: context.repo.owner, repo: context.repo.repo, labels: 'deployment,auto-generated', state: 'open', }); if (issues.data.length < 3) { github.rest.issues.create({ owner: context.repo.owner, repo: context.repo.repo, title: 'Self-Healing: Health Check Failed (Status: ${{ steps.health.outputs.status }})', body: `Health check failed.\n\nStatus: ${{ steps.health.outputs.status }}\nWorkflow: ${context.workflow}\nRun: ${context.runId}\nTimestamp: ${new Date().toISOString()}`, labels: ['bug', 'deployment', 'auto-generated'] }); } dependency-updates: name: Auto Update Dependencies runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 if: hashFiles('package.json') != '' with: node-version: '20' - name: Update npm dependencies if: hashFiles('package.json') != '' run: | npm update if [ -n "$(git status --porcelain)" ]; then git config user.name "BlackRoad Bot" git config user.email "bot@blackroad.io" git add package*.json git commit -m "chore: auto-update dependencies" git push fi