Skip to content

Commit 819ac26

Browse files
authored
Remove stale PR folders from docs/preview branch (#3628)
Fixes No space left on device error. * Removes stale PR (open >5 days) folder from docs/preview branch * Keeps the available limited memory for the new PRs doc * Runs with the current scheduled job * Current step for the closed/merged PRs remains intact The branch [docs/preview](https://github.com/NVIDIA/cuda-quantum/tree/docs/preview) gets full with the Old open PRs docs. The following error is seen in the [documentation job](https://github.com/NVIDIA/cuda-quantum/actions/runs/19449024863) in CI ``` System.IO.IOException: No space left on device : '/home/runner/actions-runner/cached/_diag/Worker_20251118-001100-utc.log' ``` Note: I had manually purged these folders twice in order to make space for the new incoming PRs. This PR just automated the process. --------- Signed-off-by: Sachin Pisal <spisal@nvidia.com>
1 parent 0f62e02 commit 819ac26

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

.github/workflows/clean_up.yml

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ jobs:
177177
178178
pr_cleanup:
179179
name: Clean up documentation previews
180-
if: github.event_name == 'pull_request_target'
180+
if: github.event_name == 'pull_request_target' || github.event_name == 'schedule'
181181
runs-on: ubuntu-latest
182182

183183
permissions:
@@ -189,11 +189,65 @@ jobs:
189189
with:
190190
ref: ${{ vars.preview_branch }}
191191

192-
- name: Delete preview folder
192+
- name: Delete preview folder for closed PR
193+
if: github.event_name == 'pull_request_target'
193194
run: |
194195
git config --global user.name "cuda-quantum-bot"
195196
git config --global user.email "cuda-quantum-bot@users.noreply.github.com"
196197
git rm -r "pr-${{ github.event.pull_request.number }}" --ignore-unmatch
197198
git commit --allow-empty -m "Cleaning up docs preview for PR #${{ github.event.pull_request.number }}."
198199
git config pull.rebase true
199200
git pull --no-edit && git push
201+
202+
- name: Delete preview folder for stale PRs (open > 5 days)
203+
if: github.event_name == 'schedule'
204+
env:
205+
GH_TOKEN: ${{ secrets.REPO_BOT_ACCESS_TOKEN || github.token }}
206+
run: |
207+
set -euo pipefail
208+
209+
# Only run once per day (at midnight UTC)
210+
if [ "$(date -u +%H%M)" != "0000" ]; then
211+
echo "Skipping stale PR cleanup."
212+
exit 0
213+
fi
214+
215+
git config --global user.name "cuda-quantum-bot"
216+
git config --global user.email "cuda-quantum-bot@users.noreply.github.com"
217+
git config pull.rebase true
218+
219+
# Keep preview branch up-to-date
220+
git pull --no-edit
221+
222+
# 5 days ago timestamp
223+
cutoff=$(date -u -d '5 days ago' +%s)
224+
225+
# Fetch open PRs created before the cutoff date
226+
stale_prs=$(gh pr list \
227+
--repo "${{ github.repository }}" \
228+
--state open \
229+
--limit 200 \
230+
--json number,createdAt \
231+
--jq ".[] | select((.createdAt | fromdate) < $cutoff) | .number")
232+
233+
if [ -z "$stale_prs" ]; then
234+
echo "No stale PR previews to delete."
235+
exit 0
236+
fi
237+
238+
echo "Stale PRs (open > 5 days): $stale_prs"
239+
240+
for pr in $stale_prs; do
241+
folder="pr-$pr"
242+
echo "Deleting preview folder $folder (PR #$pr)."
243+
git rm -r "$folder" --ignore-unmatch || true
244+
done
245+
246+
# If nothing matches, skip commit/push
247+
if git diff --cached --quiet; then
248+
echo "No preview folders were removed (nothing to commit)."
249+
exit 0
250+
fi
251+
252+
git commit -m "Cleaning up stale docs preview for PRs open > 5 days."
253+
git push

0 commit comments

Comments
 (0)