File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Storybook PR Preview Cleanup
2+
3+ on :
4+ schedule :
5+ - cron : ' 0 3 * * 1' # Every Monday at 03:00 UTC
6+ workflow_dispatch :
7+
8+ permissions :
9+ contents : write
10+
11+ jobs :
12+ cleanup :
13+ name : Delete stale PR preview folders
14+ runs-on : ubuntu-latest
15+ timeout-minutes : 10
16+
17+ steps :
18+ - name : Checkout gh-pages (full history)
19+ uses : actions/checkout@v4
20+ with :
21+ ref : gh-pages
22+ fetch-depth : 0
23+
24+ - name : Delete preview folders older than 7 days
25+ id : cleanup
26+ run : |
27+ DELETED=0
28+ CUTOFF=$(date -d '7 days ago' +%s)
29+
30+ for dir in preview/pr-*/; do
31+ [ -d "$dir" ] || continue
32+
33+ LAST_COMMIT_TS=$(git log -1 --format="%ct" -- "$dir")
34+
35+ if [ -z "$LAST_COMMIT_TS" ]; then
36+ echo "Skipping $dir: no commit history found"
37+ continue
38+ fi
39+
40+ if [ "$LAST_COMMIT_TS" -lt "$CUTOFF" ]; then
41+ echo "Removing $dir (last commit: $(date -d @$LAST_COMMIT_TS))"
42+ if git rm -rf "$dir"; then
43+ DELETED=$((DELETED + 1))
44+ else
45+ echo "Failed to remove $dir"
46+ fi
47+ else
48+ echo "Keeping $dir (last commit: $(date -d @$LAST_COMMIT_TS))"
49+ fi
50+ done
51+
52+ echo "deleted=$DELETED" >> "$GITHUB_OUTPUT"
53+
54+ - name : Commit and push removals
55+ if : steps.cleanup.outputs.deleted != '0'
56+ run : |
57+ git config --global user.email "DXGitHubRobot@devexpress.com"
58+ git config --global user.name "DX Robot"
59+ git commit -m "chore: remove ${{ steps.cleanup.outputs.deleted }} stale PR preview(s) [skip ci]"
60+ git push origin gh-pages
You can’t perform that action at this time.
0 commit comments