GitHub Pages Custom Domain Settings Gets Reset During new Commit
Asked Answered
B

3

7

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 "[email protected]"
      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

Biondo answered 22/2, 2021 at 6:47 Comment(0)
B
8

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
Biondo answered 22/2, 2021 at 7:0 Comment(0)
I
1

I know this is not Zola-related, but I've stumbled upon the same error when using Mkdocs. The documentation says that you need to create a CNAME file in your docs_dir directory, so that their gh-deploy script can pick that up and copy it at the right place in the gh-pages branch (see that doc here).

For information, using the Github developer settings page to set the custom domain does exactly the same thing, ie. creating a CNAME file at the root of the gh-pages branch.

Into answered 31/8, 2022 at 21:36 Comment(0)
T
1

If you are using Zola within GitHub pages, the solution is even simpler. Just simply create a CNAME file with the custom domain on it inside the static/ folder and it should work.

You can check the documentation from the Zola official page here: https://www.getzola.org/documentation/deployment/github-pages/#custom-domain

Trembly answered 23/6, 2023 at 13:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.