From 420867024532dd1ad18db8ad3d1beb857a3e2d21 Mon Sep 17 00:00:00 2001 From: Marcelo Prates Date: Fri, 16 May 2025 22:06:26 -0300 Subject: [PATCH] Enhance GitHub Actions workflow to handle orphan branch creation and prevent unnecessary commits for site updates. --- .github/workflows/docs.yml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 46395be..0f1d95e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -34,10 +34,20 @@ jobs: run: | git config --global user.name "github-actions[bot]" git config --global user.email "github-actions[bot]@users.noreply.github.com" - git fetch origin site-artifact || true - git switch --orphan site-artifact - git rm -rf . + # Create orphan branch or switch to it + git checkout --orphan site-artifact + # Remove all files (tracked and untracked) + git rm -rf . || true + rm -rf * + # Copy site output to root cp -r site/* . + # Add a .nojekyll file to prevent GitHub Pages from ignoring files/folders starting with _ + touch .nojekyll git add . - git commit -m "Update built site from main" - git push --force origin site-artifact \ No newline at end of file + # Only commit if there are files to commit + 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 \ No newline at end of file