Clean PR preview sites from gh-pages branch history (#6161)
This commit is contained in:
@@ -13,20 +13,20 @@ on:
|
|||||||
branches-ignore:
|
branches-ignore:
|
||||||
- 'dependabot/**'
|
- 'dependabot/**'
|
||||||
|
|
||||||
concurrency: preview-${{ github.ref }}
|
concurrency: pr-preview
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout the branch
|
- name: Checkout the branch
|
||||||
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # pin@v3
|
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
if: github.event.action != 'closed'
|
if: github.event.action != 'closed'
|
||||||
uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # pin@v3
|
uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610 # v3
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 20
|
||||||
|
|
||||||
- name: Install dependencies and build docs
|
- name: Install dependencies and build docs
|
||||||
working-directory: ./documentation
|
working-directory: ./documentation
|
||||||
@@ -41,7 +41,25 @@ jobs:
|
|||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
- name: Deploy preview
|
- name: Deploy preview
|
||||||
uses: rossjrw/pr-preview-action@df22037db54ab6ee34d3c1e2b8810ac040a530c6 # pin@v1
|
uses: rossjrw/pr-preview-action@8ff09e486b4c23709012eedd3b42e9f0b95dd0c5 # v1
|
||||||
if: ${{ github.event.pull_request.head.repo.full_name == 'block/goose' }}
|
if: ${{ github.event.pull_request.head.repo.full_name == 'block/goose' }}
|
||||||
with:
|
with:
|
||||||
source-dir: documentation/build
|
source-dir: documentation/build
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: deploy
|
||||||
|
if: github.event.action == 'closed'
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- uses: astral-sh/setup-uv@38f3f104447c67c051c4a08e39b64a148898af3a # v4
|
||||||
|
|
||||||
|
- name: Clean up gh-pages branch
|
||||||
|
run: |
|
||||||
|
bash scripts/clean-gh-pages.sh
|
||||||
|
git push origin $(git rev-parse origin/gh-pages):gh-pages --force
|
||||||
|
|||||||
Executable
+39
@@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e # Exit on error
|
||||||
|
|
||||||
|
echo "Starting gh-pages branch cleanup..."
|
||||||
|
|
||||||
|
REMOVE_PATHS_FILE="/tmp/remove-paths.txt"
|
||||||
|
> "$REMOVE_PATHS_FILE"
|
||||||
|
|
||||||
|
dirs_with_visible_files=$(git ls-tree -r origin/gh-pages:pr-preview --name-only 2>/dev/null | \
|
||||||
|
grep -v '/\.' | \
|
||||||
|
cut -d/ -f1 | \
|
||||||
|
sort -u || true)
|
||||||
|
|
||||||
|
all_dirs=$(git ls-tree -d origin/gh-pages:pr-preview --name-only 2>/dev/null || true)
|
||||||
|
|
||||||
|
if [ -z "$all_dirs" ]; then
|
||||||
|
echo "No directories found in pr-preview or pr-preview does not exist"
|
||||||
|
rm "$REMOVE_PATHS_FILE"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
while IFS= read -r dir; do
|
||||||
|
if [ -n "$dir" ]; then
|
||||||
|
if ! echo "$dirs_with_visible_files" | grep -q "^${dir}$"; then
|
||||||
|
dir_path="pr-preview/$dir"
|
||||||
|
echo "Found directory to remove: $dir_path"
|
||||||
|
echo "$dir_path" >> "$REMOVE_PATHS_FILE"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done <<< "$all_dirs"
|
||||||
|
|
||||||
|
if [ ! -s "$REMOVE_PATHS_FILE" ]; then
|
||||||
|
echo "No empty or hidden-file-only directories found. Nothing to clean up."
|
||||||
|
rm "$REMOVE_PATHS_FILE"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
uvx git-filter-repo@2.47.0 --paths-from-file "$REMOVE_PATHS_FILE" --invert-paths --refs origin/gh-pages
|
||||||
Reference in New Issue
Block a user