From b712705d9f0c1382b9dcf5a0fc1d7d475b616001 Mon Sep 17 00:00:00 2001 From: "Pablo R. Mier" Date: Sun, 12 May 2024 11:58:51 +0200 Subject: [PATCH] Fix deploy of docs --- .github/workflows/deploy-docs.yml | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index dc8d4df2..3de73042 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -48,22 +48,29 @@ jobs: run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" + + # Create a temporary directory + TEMP_DIR=$(mktemp -d) + echo "Temporary directory is $TEMP_DIR" + + # Build and prepare all the files first + mkdir -p "$TEMP_DIR/$BRANCH_NAME" + cp -r "docs/_build/html/." "$TEMP_DIR/$BRANCH_NAME/" + + # Now checkout to gh-pages git fetch origin gh-pages git checkout gh-pages || git checkout --orphan gh-pages - # Get the name of the branch that triggered the workflow - BRANCH_NAME=${GITHUB_REF#refs/heads/} - echo "Deploying documentation for branch: $BRANCH_NAME" - # Removing old files + # Clean existing files for the branch and copy new ones rm -rf "./$BRANCH_NAME" - mkdir -p "./$BRANCH_NAME" - - # Copying new files - cp -r "docs/_build/html/$BRANCH_NAME/." "./$BRANCH_NAME/" + cp -r "$TEMP_DIR/$BRANCH_NAME/." "./$BRANCH_NAME/" # Adding changes to git git add . - git commit -m "Update docs for branch $BRANCH_NAME" + git commit -m "Update docs for branch $BRANCH_NAME" --allow-empty git push -u origin gh-pages + + # Optionally, remove the temporary directory (not necessary on CI environments) + # rm -rf "$TEMP_DIR" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}