From 3b3e8b33a318fa989317b97727e0eb2dfaaf8fc1 Mon Sep 17 00:00:00 2001 From: Jorge Marques Date: Tue, 23 Jul 2024 17:34:03 +0200 Subject: [PATCH] Check if gh-pages branch exist If not, create it. Suppress git rm return error. Signed-off-by: Jorge Marques --- .github/workflows/top-level.yml | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/.github/workflows/top-level.yml b/.github/workflows/top-level.yml index da530f5..3167681 100644 --- a/.github/workflows/top-level.yml +++ b/.github/workflows/top-level.yml @@ -2,11 +2,7 @@ on: push: branches: - main - paths: - - 'docs/**' pull_request: - paths: - - 'docs/**' jobs: build-doc: @@ -47,6 +43,23 @@ jobs: contents: write steps: + - run: | + git config --global user.name "${{ github.event.head_commit.committer.name }}" + git config --global user.email "${{ github.event.head_commit.committer.email }}" + + - uses: actions/checkout@v4 + - name: Create gh-pages branch + run: > + git ls-remote --exit-code --heads origin refs/heads/gh-pages || + ( + git reset --hard ; + git clean -fdx ; + git checkout --orphan gh-pages ; + git reset --hard; + git commit -m "empty" --allow-empty ; + git push origin gh-pages:gh-pages + ) + - uses: actions/checkout@v4 with: ref: 'gh-pages' @@ -54,7 +67,7 @@ jobs: - name: Empty gh-pages run: | - git rm -r . --quiet + git rm -r . --quiet || true - uses: actions/download-artifact@v4 with: @@ -72,9 +85,7 @@ jobs: commit=$(git rev-parse --short HEAD) git add . >> /dev/null - git config --global user.name "$author" - git config --global user.email "$email" - git commit -m "deploy: $commit" --allow-empty + git commit -m "deploy: ${GITHUB_SHA}" --allow-empty - name: Push to gh-pages run: >-