|
1 | 1 | #!/bin/bash |
2 | | -# Finalize: single writer for both module-cleanup-wip and the |
| 2 | +# Finalize: single writer for both otelbot/module-cleanup-wip and the |
3 | 3 | # memory/module-cleanup branch. Runs after the agent job (regardless of |
4 | 4 | # whether the agent succeeded, no-oped, or failed). |
5 | 5 | # |
|
9 | 9 | # module is recorded as "processed" (so it isn't retried in a loop) |
10 | 10 | # AND logged as a failure for diagnostics. |
11 | 11 | # 2. If the agent produced a cleanup patch, apply it onto the fixed |
12 | | -# module-cleanup-wip branch and push. |
| 12 | +# otelbot/module-cleanup-wip branch and push. |
13 | 13 | # 3. If wip diff vs origin/main has reached FLUSH_THRESHOLD files OR |
14 | 14 | # the queue is empty, atomically rename wip to a |
15 | 15 | # module-cleanup-batch-<run_id> branch and open the PR. The wip |
16 | 16 | # branch ceases to exist on remote until the next run recreates |
17 | 17 | # it from main. |
18 | | -# 4. Self-dispatch the workflow unless the queue is empty. The chain |
19 | | -# stops on its own once MAX_OPEN_PRS is reached (matrix script |
20 | | -# returns has_work=false and finalize is skipped). |
| 18 | +# 4. Leave self-dispatch to the workflow step that follows this script, |
| 19 | +# so PR creation can use the app token while workflow dispatch uses |
| 20 | +# the normal GitHub Actions token. |
21 | 21 | # |
22 | 22 | # No rebase-retry loops on push: the workflow uses |
23 | 23 | # concurrency.group=module-cleanup with cancel-in-progress=false, so this |
24 | 24 | # job is the only writer of either branch and runs serialized across |
25 | 25 | # workflow runs. |
26 | 26 | # |
27 | 27 | # Required env: |
28 | | -# GH_TOKEN - token with contents:write, pull-requests:write, |
29 | | -# and actions:write |
| 28 | +# GH_TOKEN - token with contents:write and pull-requests:write |
30 | 29 | # GITHUB_REPOSITORY - owner/repo |
31 | 30 | # SHORT_NAME - the module short_name processed this run |
32 | 31 | # AGENT_RESULT - github.needs.agent.result ('success'|'failure'|...) |
|
36 | 35 | # |
37 | 36 | # Optional env: |
38 | 37 | # FLUSH_THRESHOLD - file count that triggers a PR (default 10) |
39 | | -# WORKFLOW_FILE - workflow file name for self-dispatch |
40 | 38 | # MEMORY_BRANCH - default: memory/module-cleanup |
41 | | -# WIP_BRANCH - default: module-cleanup-wip |
| 39 | +# WIP_BRANCH - default: otelbot/module-cleanup-wip |
42 | 40 |
|
43 | 41 | set -euo pipefail |
44 | 42 |
|
45 | 43 | MEMORY_BRANCH="${MEMORY_BRANCH:-memory/module-cleanup}" |
46 | | -WIP_BRANCH="${WIP_BRANCH:-module-cleanup-wip}" |
| 44 | +WIP_BRANCH="${WIP_BRANCH:-otelbot/module-cleanup-wip}" |
47 | 45 | THRESHOLD="${FLUSH_THRESHOLD:-10}" |
48 | 46 | QUEUE_REMAINING="${QUEUE_REMAINING:-0}" |
49 | 47 | REPO="${GITHUB_REPOSITORY:?GITHUB_REPOSITORY required}" |
50 | | -WORKFLOW_FILE="${WORKFLOW_FILE:-module-cleanup.lock.yml}" |
51 | 48 | SHORT="${SHORT_NAME:?SHORT_NAME required}" |
52 | 49 | AGENT_RESULT="${AGENT_RESULT:-failure}" |
53 | 50 | ARTIFACT_DIR="${ARTIFACT_DIR:-./agent-artifact}" |
54 | 51 |
|
55 | | -git fetch origin main --depth=1 |
56 | | -git fetch origin "$MEMORY_BRANCH" --depth=1 2>/dev/null || true |
57 | | -git fetch origin "$WIP_BRANCH" --depth=1 2>/dev/null || true |
| 52 | +# Full history is required for `origin/main..origin/$WIP_BRANCH` log/diff |
| 53 | +# below. The finalize job's checkout uses `fetch-depth: 0`, so don't |
| 54 | +# re-shallow any of these refs with `--depth`. |
| 55 | +git fetch origin main |
| 56 | +git fetch origin "$MEMORY_BRANCH" 2>/dev/null || true |
| 57 | +git fetch origin "$WIP_BRANCH" 2>/dev/null || true |
58 | 58 |
|
59 | 59 | # ---- 1. Update processed.txt (and failed.txt on failure) ---- |
60 | 60 |
|
@@ -136,7 +136,7 @@ if [ -n "$PATCH_SRC" ]; then |
136 | 136 | ) |
137 | 137 | fi |
138 | 138 |
|
139 | | -git fetch origin "$WIP_BRANCH" --depth=50 2>/dev/null || true |
| 139 | +git fetch origin "$WIP_BRANCH" 2>/dev/null || true |
140 | 140 |
|
141 | 141 | # ---- 3. Decide flush ---- |
142 | 142 |
|
@@ -170,6 +170,8 @@ if [ "$SHOULD_FLUSH" = "true" ]; then |
170 | 170 |
|
171 | 171 | MODULE_COUNT=$(git -C "$WIP_WT" rev-list --count "origin/main..origin/$WIP_BRANCH") |
172 | 172 |
|
| 173 | + # processed.txt on the memory branch is the sole source of truth for |
| 174 | + # which modules dispatch skips, so no hidden marker block is needed here. |
173 | 175 | BODY_FILE=$(mktemp) |
174 | 176 | { |
175 | 177 | echo "Automated module-cleanup batch." |
@@ -210,21 +212,5 @@ if [ "$SHOULD_FLUSH" = "true" ]; then |
210 | 212 | OPENED_PR=true |
211 | 213 | fi |
212 | 214 |
|
213 | | -# ---- 4. Self-dispatch ---- |
214 | | - |
215 | | -# Always self-dispatch when there's more queued work. The next run will |
216 | | -# pick up wherever wip is: if we just flushed, wip is gone and the run |
217 | | -# starts a fresh wip from main; otherwise it appends to the same wip. |
218 | | -# The chain stops on its own when build-cleanup-matrix.py sees |
219 | | -# MAX_OPEN_PRS reached and returns has_work=false (no agent, no |
220 | | -# finalize, no self-dispatch). Cron picks back up later. |
221 | | - |
222 | | -if [ "$QUEUE_REMAINING" -le 0 ]; then |
223 | | - echo "Queue empty; nothing to dispatch." |
224 | | -else |
225 | | - echo "Self-dispatching workflow for next module." |
226 | | - gh workflow run "$WORKFLOW_FILE" --repo "$REPO" --ref main |
227 | | -fi |
228 | | - |
229 | 215 | git worktree remove --force "$MEM_WT" 2>/dev/null || true |
230 | 216 | git worktree remove --force "$WIP_WT" 2>/dev/null || true |
0 commit comments