github-pageszola

GitHub Pages Custom Domain Settings Gets Reset During new Commit


I have a static site generated using Zola and I'm using GitHub Actions to do a build of my static site and publish that into a gh-pages branch of my repository. I have also configured my project to serve via GitHub pages using the gh-pages branch.

The problem I'm facing is that as soon as my GitHub action builds a new version and pushes it to the gh-pages branch, the custom domain setting in the GitHub settings gets reset.

Here is what I do in my GitHub action to build and push to TARGET_BRANCH (gh-pages) branch:

  - name: Commit and push to target branch
    run: |-
      git config --global user.email "workflow-bot@mydomain.com"
      git config --global user.name "workflow-bot"
      git checkout --orphan $TARGET_BRANCH
      rm -rf .github/
      mv public ..
      rm -rf *
      mv ../public/* .
      touch .nojekyll
      touch README.md
      echo 'https://www.bigelectrons.com - SITE GENERATED USING ZOLA' > README.md
      git add .
      git commit -m "generated using zola build"
      git push --set-upstream origin $TARGET_BRANCH --force

Any idea what the problem is and how I could resolve th


Solution

  • I just had to add a CNAME file to my gh-pages branch. For example., in the run command, I had to add these two lines:

    touch CNAME
    echo 'mydomain.com' > CNAME