Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/build-and-preview-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,47 @@ jobs:
action: auto
comment: false

- name: Checkout gh-pages for preview retention
if: github.event.action != 'closed'
uses: actions/checkout@v6
with:
ref: gh-pages
fetch-depth: 0
path: gh-pages-maintenance

- name: Prune old PR previews
if: github.event.action != 'closed'
run: |
cd gh-pages-maintenance
mkdir -p pr-preview

mapfile -t previews < <(
while IFS= read -r preview; do
timestamp="$(git log -1 --format=%ct -- "pr-preview/$preview" 2>/dev/null || echo 0)"
printf '%s %s\n' "$timestamp" "$preview"
done < <(find pr-preview -mindepth 1 -maxdepth 1 -type d -name 'pr-*' -printf '%f\n') \
| sort -nr \
| awk '{print $2}'
)

if (( ${#previews[@]} <= 6 )); then
exit 0
fi

for preview in "${previews[@]:6}"; do
rm -rf "pr-preview/$preview"
done

if git diff --quiet -- pr-preview; then
exit 0
fi

git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pr-preview
git commit -m "Prune old PR previews"
git push

- name: Comment PR with Preview URL
if: github.event.action != 'closed'
uses: marocchino/sticky-pull-request-comment@v2
Expand Down
Loading