s0 / git-publish-subdir-action

GitHub Action to push a subdirectory as a branch to any git repo (e.g. for GitHub Pages)
https://github.com/marketplace/actions/push-git-subdirectory-as-branch
MIT License
210 stars 36 forks source link

GitHub Pages resetting Custom Domain #20

Closed MyKo101 closed 4 years ago

MyKo101 commented 4 years ago

I have recently switched to using main as my default branch on my User repo, however I know that GitHub Pages can only be built from the master branch. I'm using this action to automatically push my public subdirectory (i.e. the one with the website in) to the master branch. The theory being that I can git push my entire repo to main and it'll update my site to be just the subdirectory. Similar to an example on your homepage, except this is for a User repo, rather than a normal repo. However, whenever this update happens, my Custom Domain in my settings gets reset to nothing.

I think this might be because your Action destroys the master branch and then re-builds it, which might be why it's getting reset, although I'm not sure how your code works under-the-hood to be sure that this is what's happening.

If so, would a fix be possible/easy? Or would you be able to demonstrate how the push to master could happen without destroying the branch?

(PS. Love the Action, just started my website/blog using it and even focused my first blog post on it)

s0 commented 4 years ago

Ah yes. This action deletes all the files in the target branch and replaces them with the contents of the folder you have chosen.

That's a problem because it will delete the CNAME file at the root of your master branch, which is automatically created by GitHub when you configure a custom domain.

There's no way to exclude files to delete with this action atm, so I would recommend also adding the CNAME file to the directory you're publishing before running your action. It's simply going to be a text file with your custom domain as its contents. You can look at the history of your master branch to see it.

Also, very pleased to hear you focused your first blog post on this! That makes me very happy, I'll give it a read now!

MyKo101 commented 4 years ago

Thanks! That solved it.

echo -n "michaelbarrowman.co.uk" > public/CNAME

Just tried it out and it works, also added it at the bottom of the blogpost (and also fixed the Social Sharing links on there!)

And fortunately, the way that I'm building my website, this file doesn't get deleted when I rebuild (annoying in other ways sometimes).