tschaub / gh-pages

General purpose task for publishing files to a gh-pages branch on GitHub
https://www.npmjs.com/package/gh-pages
MIT License
3.25k stars 191 forks source link

Deploying seems to overwrite custom domain #213

Open unlikenesses opened 7 years ago

unlikenesses commented 7 years ago

I am deploying a GatsbyJS site to GitHub pages with this command:

gatsby build --prefix-paths && gh-pages -d public -b master

I need to push to the master branch because it's a user site (rather than a project site). This works but each time I do it, the repo's "Custom domain" setting is reset. This means after every deploy I need to go into the settings and re-enter the custom domain. No idea if this is a bug or if I'm just missing something obvious.

atav32 commented 7 years ago

also getting this bug...

youfoundron commented 6 years ago

@unlikenesses @atav32

It seems you need to include a file named CNAME at the root of your file structure.
Your custom domain should be the first line in this file.

In my case, the CNAME file would have this content:

youfoundron.com

Credit goes to this comment.

pablorsk commented 6 years ago

Just adapt this lines to your DEPLOYMENT script

var ghpages = require('gh-pages');
var fs = require('fs');

fs.writeFile('dist/CNAME', "your-custom-domain.com", function(err) {});
ghpages.publish('dist', function(err) {});
dijs commented 5 years ago

I came across the same issue and just added a npm script for this before publishing.

"add-domain": "echo \"customdomain.com\" > build/CNAME",
vittorio commented 5 years ago

If you use gh-pages for React app deployment – just put CNAME file with your domain into public folder.

giteshjha commented 4 years ago

For angular 8. Create a CNAME file inside the src folder. then Inside angular.json "assets": [ "src/favicon.ico", "src/assets", "src/CNAME" // This is the change you need to make. ],

dhedegaard commented 4 years ago

It would be nice if this behavior was documented in the README.

harivamshi81189 commented 4 years ago

If you use gh-pages for React app deployment – just put CNAME file with your domain into public folder.

Thank you it helped

MohammedAl-Mahdawi commented 4 years ago

If you are using Gatsby just create a CNAME file inside the static folder and put your domain inside it like example.com

rjitsu commented 3 years ago

I'm using no react just plain html css js. How do I resolve this issue?

joshsny commented 3 years ago

As others have said, just put a CNAME file that contains only your domain in the directory that is being published. This will work independently of what tools you are using.

pruthvi2103 commented 3 years ago

I'm using no react just plain html css js. How do I resolve this issue?

@rjitsu just put a CNAME to your root folder

iamlasse commented 2 years ago

I have a CNAME file in my root folder and it still resets the domain.. Any suggestions?

youfoundron commented 2 years ago

@iamlasse

Is the CNAME file present at root after building for your github pages branch?

If not, which tool are you using to bundle your static assets?

pruthvi2103 commented 2 years ago

Please see your gh-pages branch and see if it has a CNAME file in it

makenziebird commented 2 years ago

For Hugo, I moved the CNAME file to the "public" directory as that is where the static site resources and assets are built by the GitHub Action.

iamlasse commented 2 years ago

@iamlasse

Is the CNAME file present at root after building for your github pages branch?

If not, which tool are you using to bundle your static assets?

Yes, the CNAME file is in the root in gh-pages branch with the domain as the only text inside.

flaviusburca commented 2 years ago

same problem here: CNAME file is in the build/ folder, but the custom domain keeps resetting...

dimitarangelkov commented 2 years ago

same problem here. CNAME available in the gh-pages branch root folder and the GitHub Pages custom domain keeps resetting on every deploy

rivka99 commented 2 years ago

I was also having this same issue as @dimitarangelko. It turned out the issue was that there were slightly different formats of the link in the CNAME files and In the package.json "add-domain": script line

it was "add-domain": "echo \"https://mypage.app\" > build/CNAME", and it had https://mypage.app/ in the gh-pages branch CNAME file, but had just mypage.app in the master branch CNAME file. I switched them all to just mypage.app like so

public/CNAME (in master): mypage.app CNAME file (in GH-Pages): mypage.app and in package.json: "add-domain": "echo \"mypage.app\" > build/CNAME",

made sure that the correct domain was set up in github pages before doing this and pulled them in in the gh-pages branch. Saved it all and ran npm run deploy and it finally didn't replace it!

SaadBazaz commented 2 years ago

CNAME file is in my main and gh-pages branches, and at the root of each. But this still happens. Any ideas?

I'm building a Vite React app, I use GitHub actions to build and push to gh-pages branch.

angles-n-daemons commented 1 year ago

For Hugo (as mentioned above) you can add the CNAME like so from the root of your directory:

$ mkdir -p public
$ echo 'www.<yourdomain>.com' > public/CNAME

Adding this because I wasn't sure exactly where the public directory should be, and I didn't know what a CNAME file contained.

fguisso commented 1 year ago

I have the same problem using Hugo.

I think this worked fine before the option deploy using github actions, and I never chose this option because I have my own actions to build and update the branch gh-pages. I think that the problem is something in the new way that github handles the deployment.

ani-per commented 1 year ago

I have the same problem using Hugo.

  • I'm using the deploy from branch gh-pages
  • the CNAME is set in both branches main and gh-pages

I think this worked fine before the option deploy using github actions, and I never chose this option because I have my own actions to build and update the branch gh-pages. I think that the problem is something in the new way that github handles the deployment.

I am using Sphinx, but I fixed this by adding CNAME to the directory from which Pages deploys the source.

E.g., if your build.yml is directing Pages to use the build/ subfolder of root for deployment, then add CNAME to build/ in the main branch.

fguisso commented 1 year ago

I have the same problem using Hugo.

  • I'm using the deploy from branch gh-pages
  • the CNAME is set in both branches main and gh-pages

I think this worked fine before the option deploy using github actions, and I never chose this option because I have my own actions to build and update the branch gh-pages. I think that the problem is something in the new way that github handles the deployment.

I am using Sphinx, but I fixed this by adding CNAME to the directory from which Pages deploys the source.

E.g., if your build.yml is directing Pages to use the build/ subfolder of root for deployment, then add CNAME to build/ in the main branch.

I do that. https://github.com/fguisso/fguisso.github.io/blob/gh-pages/CNAME

image

I follow the file to show to you and noticing that every deploy removes de CNAME file, but this actions is not setting by me: https://github.com/fguisso/fguisso.github.io/commits/gh-pages/CNAME