Skip to content

Commit 4050502

Browse files
fix(ci): prevent gh-pages branch bloat (#6340)
1 parent 536b138 commit 4050502

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

.github/workflows/deploy-docs-and-extensions.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
paths:
88
- 'documentation/**'
99

10+
# Use same concurrency group as PR preview workflow to prevent race conditions
11+
# when both workflows try to modify gh-pages branch simultaneously
12+
concurrency: pr-preview
13+
1014
jobs:
1115
deploy:
1216
runs-on: ubuntu-latest
@@ -40,10 +44,30 @@ jobs:
4044
npm install
4145
npm run build
4246
47+
- name: Checkout gh-pages branch
48+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
49+
continue-on-error: true # Branch may not exist on first deploy or in forks
50+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # pin@v3
51+
with:
52+
ref: gh-pages
53+
path: gh-pages-current
54+
55+
- name: Preserve pr-preview directory
56+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
57+
run: |
58+
# Copy pr-preview from current gh-pages to the new build (if it exists)
59+
if [ -d "gh-pages-current/pr-preview" ]; then
60+
cp -r gh-pages-current/pr-preview documentation/build/pr-preview
61+
echo "Preserved pr-preview directory with $(ls gh-pages-current/pr-preview | wc -l) PR previews"
62+
else
63+
echo "No pr-preview directory to preserve"
64+
fi
65+
4366
- name: Deploy to /gh-pages
4467
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
4568
uses: peaceiris/actions-gh-pages@373f7f263a76c20808c831209c920827a82a2847 # pin@v3
4669
with:
4770
github_token: ${{ secrets.GITHUB_TOKEN }}
4871
publish_dir: documentation/build
49-
keep_files: true # This preserves existing files in gh-pages branch especially for previews
72+
keep_files: false # Clean deploy - only keep what's in the build + pr-preview
73+
force_orphan: true # Create a fresh commit without history to prevent bloat

0 commit comments

Comments
 (0)