Skip to content

Merge pull request #563 from miles990/feature/auto-idx-1ee00e3c-78e-1… #1466

Merge pull request #563 from miles990/feature/auto-idx-1ee00e3c-78e-1…

Merge pull request #563 from miles990/feature/auto-idx-1ee00e3c-78e-1… #1466

Workflow file for this run

name: Deploy
on:
push:
branches: [main]
paths:
- 'src/**'
- 'package.json'
- 'pnpm-lock.yaml'
- 'tsconfig.json'
- 'scripts/**'
- 'agent-compose.yaml'
- '.github/**'
workflow_dispatch:
# 短時間多次 push 只部署最後一次 — 取消排隊中的舊 deploy
concurrency:
group: deploy-production
cancel-in-progress: true
jobs:
deploy:
name: Deploy to Server
runs-on: [self-hosted, macOS]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get version
id: version
run: |
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
echo "version=$SHORT_SHA" >> $GITHUB_OUTPUT
- name: Deploy
run: |
cd /Users/user/Workspace/mini-agent
git fetch origin main
# Self-hosted runner shares the runtime working tree. Deployment must
# leave this checkout on origin/main; dev/runtime dirt is preserved in a
# stash for later recovery, but not popped back into the deploy checkout.
STASH_TAG="deploy-backup-$(date -u +%Y%m%dT%H%M%SZ)"
STASHED=0
if ! git diff-index --quiet HEAD -- 2>/dev/null || [ -n "$(git ls-files --others --exclude-standard)" ]; then
if git stash push --include-untracked -m "$STASH_TAG" >/dev/null 2>&1; then
STASHED=1
echo "Stashed runtime/dev dirt as $STASH_TAG"
fi
fi
# Preserve runtime-generated memory files (myelin rules, state, etc.)
# before git reset --hard wipes uncommitted changes
MEMORY_BACKUP=$(mktemp -d)
if [ -d memory ]; then
cp -a memory/ "$MEMORY_BACKUP/"
fi
git checkout -B runtime/main origin/main
git reset --hard origin/main
# Restore memory files — prefer runtime version over repo version
# (runtime has latest myelin rules, state files, etc.)
if [ -d "$MEMORY_BACKUP/memory" ]; then
rsync -a --ignore-existing "$MEMORY_BACKUP/memory/" memory/
# For rule/state files, runtime version is authoritative
for f in "$MEMORY_BACKUP"/memory/myelin-*.json "$MEMORY_BACKUP"/memory/research-*.json "$MEMORY_BACKUP"/memory/state/*.json; do
[ -f "$f" ] && cp "$f" "memory/$(basename "$f")" 2>/dev/null || true
done
fi
rm -rf "$MEMORY_BACKUP"
# Do not pop the stash here. Popping runtime dirt into the deployment
# checkout can create unresolved conflicts and break deploy. The stash is
# an explicit recovery artifact; autonomous work must continue in an
# isolated worktree/branch, not in this runtime checkout.
if [ "$STASHED" = "1" ]; then
echo "Runtime/dev dirt preserved in stash; not restoring into deploy checkout:"
git stash list | grep "$STASH_TAG" || true
fi
MINI_AGENT_SKIP_DEPLOY_PULL=1 ./scripts/deploy.sh
git checkout -B runtime/main origin/main
- name: Notify Success
if: success()
uses: ./.github/actions/telegram-notify
with:
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
chat-id: ${{ secrets.TELEGRAM_CHAT_ID }}
message: "🚀 mini-agent deployed ${{ steps.version.outputs.version }}"
- name: Notify Failure
if: failure()
uses: ./.github/actions/telegram-notify
with:
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
chat-id: ${{ secrets.TELEGRAM_CHAT_ID }}
message: "❌ mini-agent deploy failed ${{ steps.version.outputs.version }} - ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"