Skip to content

Commit 67288fa

Browse files
committed
feat: switch to PR-based workflow
- Create feature branch (evolution/day-N) - Create PR instead of direct push - Auto-merge when CI passes - Added pull-requests: write permission
1 parent a8996ec commit 67288fa

2 files changed

Lines changed: 66 additions & 3 deletions

File tree

.github/workflows/evolve.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
permissions:
99
contents: write
1010
issues: write
11+
pull-requests: write
1112

1213
jobs:
1314
evolve:

scripts/evolution/evolve.sh

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,75 @@ log "Generating stats..."
176176
python3 scripts/build/generate_stats.py . 2>/dev/null || true
177177
git add docs/stats.json memory/weekly_summary.md 2>/dev/null || true
178178

179-
# ── Final commit and push ──
180-
log "Pushing changes..."
179+
# ── Final commit and PR ──
180+
log "Creating pull request..."
181+
182+
BRANCH="evolution/day-${DAY}"
183+
184+
# Re-calculate day after pull (pull may overwrite DAY_COUNT)
185+
DAY=$(( ($(date -u +%s) - $(date -d "$BIRTH_DATE" +%s 2>/dev/null || date -j -f "%Y-%m-%d" "$BIRTH_DATE" +%s)) / 86400 ))
186+
echo "$DAY" > "${REPOPATH}/DAY_COUNT"
187+
188+
# Stage and commit all changes
181189
if [[ -n $(git status -s) ]]; then
182190
git add -A
183191
git commit -m "iterate: Day $DAY evolution session" 2>/dev/null || true
184192
fi
193+
194+
# Pull latest main
185195
git pull --rebase origin main 2>/dev/null || true
186-
git push origin main 2>/dev/null || log "Push failed"
196+
197+
# Ensure DAY_COUNT is correct after pull
198+
echo "$DAY" > "${REPOPATH}/DAY_COUNT"
199+
git add DAY_COUNT 2>/dev/null || true
200+
git diff --cached --quiet || git commit --amend --no-edit 2>/dev/null || true
201+
202+
# Check if there are changes to push
203+
if [[ -z $(git diff origin/main HEAD --stat 2>/dev/null) ]]; then
204+
log "No changes to push — skipping PR"
205+
git checkout main 2>/dev/null || true
206+
log "=== evolution cycle completed ==="
207+
exit 0
208+
fi
209+
210+
# Create feature branch and push
211+
git checkout -b "$BRANCH" 2>/dev/null || git checkout "$BRANCH"
212+
git push -u origin "$BRANCH" --force-with-lease 2>/dev/null || {
213+
log "Push failed, trying without lease"
214+
git push -u origin "$BRANCH" 2>/dev/null || log "Push failed"
215+
}
216+
217+
# Create PR
218+
PR_TITLE="iterate: Day $DAY evolution session"
219+
PR_BODY="## Evolution Session — Day $DAY
220+
221+
Automated evolution session by iterate-evolve[bot].
222+
223+
### What changed
224+
- Ran plan → implement → communicate pipeline
225+
- All changes verified with go build + go test
226+
227+
### Journal
228+
See docs/JOURNAL.md for session details.
229+
230+
---
231+
*Auto-generated by iterate*"
232+
233+
gh pr create \
234+
--repo "$GITHUB_REPO" \
235+
--title "$PR_TITLE" \
236+
--body "$PR_BODY" \
237+
--base main \
238+
--head "$BRANCH" 2>/dev/null || log "PR creation failed"
239+
240+
# Auto-merge if PR was created
241+
PR_NUMBER=$(gh pr list --repo "$GITHUB_REPO" --head "$BRANCH" --json number --jq '.[0].number' 2>/dev/null)
242+
if [[ -n "$PR_NUMBER" && "$PR_NUMBER" != "null" ]]; then
243+
log "Enabling auto-merge for PR #$PR_NUMBER"
244+
gh pr merge "$PR_NUMBER" --repo "$GITHUB_REPO" --auto --squash 2>/dev/null || log "Auto-merge setup failed (may need branch protection)"
245+
fi
246+
247+
# Switch back to main
248+
git checkout main 2>/dev/null || true
187249

188250
log "=== evolution cycle completed ==="

0 commit comments

Comments
 (0)