Skip to content

Commit 6074e3b

Browse files
committed
Improve gh-pages branch setup in deploy workflow
Enhances the deployment workflow to check for the existence of the gh-pages branch and create it as an orphan branch if it does not exist. This ensures smoother deployments and initializes the branch with a README if needed.
1 parent ce14abe commit 6074e3b

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

.github/workflows/deploy.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,28 @@ jobs:
6666
needs: build
6767
runs-on: ubuntu-latest
6868
steps:
69-
- name: Checkout gh-pages branch
69+
- name: Checkout repository
7070
uses: actions/checkout@v6
7171
with:
72-
ref: gh-pages
72+
fetch-depth: 0
73+
74+
- name: Setup gh-pages branch
75+
run: |
76+
# Check if gh-pages branch exists
77+
if git ls-remote --heads origin gh-pages | grep gh-pages; then
78+
echo "gh-pages branch exists, checking out..."
79+
git checkout gh-pages
80+
else
81+
echo "gh-pages branch doesn't exist, creating orphan branch..."
82+
git checkout --orphan gh-pages
83+
git rm -rf .
84+
echo "# Better Code - PR Previews" > README.md
85+
git add README.md
86+
git config user.name "github-actions[bot]"
87+
git config user.email "github-actions[bot]@users.noreply.github.com"
88+
git commit -m "Initialize gh-pages branch for PR previews"
89+
git push origin gh-pages
90+
fi
7391
7492
- name: Download build artifact
7593
uses: actions/download-artifact@v4

0 commit comments

Comments
 (0)