Skip to content

Commit 80d48c8

Browse files
authored
Fix module cleanup workflow (open-telemetry#18658)
1 parent 9e1d9f5 commit 80d48c8

5 files changed

Lines changed: 68 additions & 90 deletions

File tree

.github/scripts/module-cleanup/build-cleanup-matrix.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
GITHUB_OUTPUT - path to the GitHub Actions output file
1414
GH_TOKEN - token for `gh` CLI (set automatically by the workflow)
1515
REVIEW_PROGRESS - newline-separated list of processed module names
16-
(contents of processed.txt on the memory branch, plus
17-
shorts already in inflight module-cleanup PR bodies)
16+
(contents of processed.txt on the memory branch)
1817
1918
Outputs (to $GITHUB_OUTPUT):
2019
has_work - "true" if a module was picked, "false" otherwise

.github/scripts/module-cleanup/export-cleanup-patch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Final action invoked by the LLM agent: format-patch the cleanup commit
33
# range into /tmp/gh-aw/agent/cleanup.patch so gh-aw's auto-uploader
44
# includes it in the `agent` workflow artifact. The finalize job then
5-
# downloads that artifact and applies the patch onto module-cleanup-wip.
5+
# downloads that artifact and applies the patch onto otelbot/module-cleanup-wip.
66
#
77
# Idempotent and write-only to /tmp. Does NOT push anything.
88
#

.github/scripts/module-cleanup/finalize.sh

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/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
33
# memory/module-cleanup branch. Runs after the agent job (regardless of
44
# whether the agent succeeded, no-oped, or failed).
55
#
@@ -9,24 +9,23 @@
99
# module is recorded as "processed" (so it isn't retried in a loop)
1010
# AND logged as a failure for diagnostics.
1111
# 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.
1313
# 3. If wip diff vs origin/main has reached FLUSH_THRESHOLD files OR
1414
# the queue is empty, atomically rename wip to a
1515
# module-cleanup-batch-<run_id> branch and open the PR. The wip
1616
# branch ceases to exist on remote until the next run recreates
1717
# 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.
2121
#
2222
# No rebase-retry loops on push: the workflow uses
2323
# concurrency.group=module-cleanup with cancel-in-progress=false, so this
2424
# job is the only writer of either branch and runs serialized across
2525
# workflow runs.
2626
#
2727
# 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
3029
# GITHUB_REPOSITORY - owner/repo
3130
# SHORT_NAME - the module short_name processed this run
3231
# AGENT_RESULT - github.needs.agent.result ('success'|'failure'|...)
@@ -36,25 +35,26 @@
3635
#
3736
# Optional env:
3837
# FLUSH_THRESHOLD - file count that triggers a PR (default 10)
39-
# WORKFLOW_FILE - workflow file name for self-dispatch
4038
# MEMORY_BRANCH - default: memory/module-cleanup
41-
# WIP_BRANCH - default: module-cleanup-wip
39+
# WIP_BRANCH - default: otelbot/module-cleanup-wip
4240

4341
set -euo pipefail
4442

4543
MEMORY_BRANCH="${MEMORY_BRANCH:-memory/module-cleanup}"
46-
WIP_BRANCH="${WIP_BRANCH:-module-cleanup-wip}"
44+
WIP_BRANCH="${WIP_BRANCH:-otelbot/module-cleanup-wip}"
4745
THRESHOLD="${FLUSH_THRESHOLD:-10}"
4846
QUEUE_REMAINING="${QUEUE_REMAINING:-0}"
4947
REPO="${GITHUB_REPOSITORY:?GITHUB_REPOSITORY required}"
50-
WORKFLOW_FILE="${WORKFLOW_FILE:-module-cleanup.lock.yml}"
5148
SHORT="${SHORT_NAME:?SHORT_NAME required}"
5249
AGENT_RESULT="${AGENT_RESULT:-failure}"
5350
ARTIFACT_DIR="${ARTIFACT_DIR:-./agent-artifact}"
5451

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
5858

5959
# ---- 1. Update processed.txt (and failed.txt on failure) ----
6060

@@ -136,7 +136,7 @@ if [ -n "$PATCH_SRC" ]; then
136136
)
137137
fi
138138

139-
git fetch origin "$WIP_BRANCH" --depth=50 2>/dev/null || true
139+
git fetch origin "$WIP_BRANCH" 2>/dev/null || true
140140

141141
# ---- 3. Decide flush ----
142142

@@ -170,6 +170,8 @@ if [ "$SHOULD_FLUSH" = "true" ]; then
170170

171171
MODULE_COUNT=$(git -C "$WIP_WT" rev-list --count "origin/main..origin/$WIP_BRANCH")
172172

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.
173175
BODY_FILE=$(mktemp)
174176
{
175177
echo "Automated module-cleanup batch."
@@ -210,21 +212,5 @@ if [ "$SHOULD_FLUSH" = "true" ]; then
210212
OPENED_PR=true
211213
fi
212214

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-
229215
git worktree remove --force "$MEM_WT" 2>/dev/null || true
230216
git worktree remove --force "$WIP_WT" 2>/dev/null || true

.github/workflows/module-cleanup.lock.yml

Lines changed: 24 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)