Enhance GitHub Actions workflow to handle orphan branch creation and prevent unnecessary commits for site updates.

This commit is contained in:
Marcelo Prates
2025-05-16 22:06:26 -03:00
parent 5dd7297200
commit 4208670245

View File

@@ -34,10 +34,20 @@ jobs:
run: | run: |
git config --global user.name "github-actions[bot]" git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.email "github-actions[bot]@users.noreply.github.com"
git fetch origin site-artifact || true # Create orphan branch or switch to it
git switch --orphan site-artifact git checkout --orphan site-artifact
git rm -rf . # Remove all files (tracked and untracked)
git rm -rf . || true
rm -rf *
# Copy site output to root
cp -r site/* . cp -r site/* .
# Add a .nojekyll file to prevent GitHub Pages from ignoring files/folders starting with _
touch .nojekyll
git add . git add .
git commit -m "Update built site from main" # Only commit if there are files to commit
git push --force origin site-artifact if git diff --cached --quiet; then
echo 'No changes to commit'
else
git commit -m "Update built site from main"
git push --force origin site-artifact
fi