From 1d261830a0948e75197790afa914b3b51c474a0e Mon Sep 17 00:00:00 2001 From: David Rheinsberg Date: Tue, 17 Oct 2023 14:12:17 +0200 Subject: [PATCH] ci/contrib: do not fail on missing gh-pages The current contrib deploy-hook fails if there is no `gh-pages` branch. Change the CI order to disregard the old `gh-pages` branch first. The `contrib` deploy-hook always creates a fresh `gh-pages` commit and pushes it out. However, currently it relies on the old `gh-pages` branch to exist, since it does not ignore errors when pruning it. Fortunately, the code always creates a new orphan branch, since it does not want to keep history for deployments. Therefore, we can simply use: `git worktree --orphan -B ` This will ensure to always create an orphan branch named ``, and override an existing branch if it exists (see `-b` vs `-B`). Hence, there is no need for us to prune the old branch, anymore. Since we will recreate the branch on every push, we have to explicitly specify the remote to push to. We no longer set up branch tracking. --- .github/workflows/contrib.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/contrib.yml b/.github/workflows/contrib.yml index aabfd86ff4a..de8b8805511 100644 --- a/.github/workflows/contrib.yml +++ b/.github/workflows/contrib.yml @@ -25,14 +25,12 @@ jobs: run: | cd src/doc/contrib mdbook build - git worktree add gh-pages gh-pages + # Override previous ref to avoid keeping history. + git worktree add --orphan -B gh-pages gh-pages git config user.name "Deploy from CI" git config user.email "" cd gh-pages - # Delete the ref to avoid keeping history. - git update-ref -d refs/heads/gh-pages - rm -rf contrib mv ../book contrib git add contrib git commit -m "Deploy $GITHUB_SHA to gh-pages" - git push --force + git push origin +gh-pages