Deploy

Deploy to GitHub Pages

Key feature: Fully automatic, no need to build website locally. Yes, you can skip blogdown::build_site() step locally.

1. Add all R and system packages to /deps.yaml file that are required to render your Rmarkdown files

  • Specify any CRAN, Bioconductor or Github packages you have used, in yaml array format. Github packages need to be user_name/repo_name.
  • The site building is happening on Github by an Ubuntu system, so specify any system packages to install that are required by your R packages. Only a single line, use space to separate each system dependencies.

2. Change base URL in config file

Change your baseURL in the /config.toml.

  • If this is your first github website, change the baseURL = “/” to your github base url, like “https://USERNAME.github.io/”.
  • If not, change baseURL = “/” to your repo’s url, like “https://USERNAME.github.io/REPO_NAME/”.
  • If you use custom domain, change baseURL = “/” to your custom url, like “https://MY_DOMAIN_NAME.com/”.

3. Create a new branch named gh-pages

git checkout -b gh-pages
rm -rv !(.git|README.md)
git add . && git commit -m "gh-pages" && git push --set-upstream origin gh-pages
git checkout main
git add . && git commit -m "pg_build" && git push
git submodule update --init --recursive

Or go to Github website create a branch by clicking.

You do not need to push any content to this gh-pages branch. This branch is automatically managed by Github Actions.

4. Github Setting

  • Click on Setting
  • click on GitHub Pages
  • Select Branch gh-pages and folder /(root) and click on Save
  • Click on Enforce HTTPS

5. Trigger page build

  • To trigger a build and deployment event, in the git commit message, include the word “pg_build”, e.g. git commit -m "blabla pg_build". This will run the full rendering process (rendering and deploy the website may still take a few minutes).
  • If you have build the site locally and updated the /public locally, in your commit message, include the word “no_render” will skip the site rendering + build process. Github Actions will directly use /public to host the website.

6. Add CNAME file cname

If the webpage requires CNAME file, we can set the cname option in the .github/workflows/build_page.yaml.

For more details about CNAME, read the official documentation: Managing a custom domain for your GitHub Pages site - GitHub Help.

- name: Deploy
  uses: peaceiris/actions-gh-pages@v3
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    publish_dir: ./public
    cname: <add CNAME>

Details

  • The first deployment can take some time because Github Actions need to install these packages. After first successful deployment with Github Actions, all packages will be cached and no need to install again later. So later deployment will be much faster.

Deploy to Netlify

Netlify Status

Important: :

  1. Before running blogdown::build_site(), in /config.toml change baseURL to “/” baseURL="/"
  2. Before deployment, in /netlify.toml change publish to “public” publish = "public"

Deploy to Netlify with GitHub

  • Go online to Netlify.com.
  • Click on the Sign Up button.
  • It is recommended to sign up using your existing GitHub account, so select GitHub, and click to Authorize Netlify.
  • Click on the New site from Git button.
  • Click on the GitHub button.
  • Select the repository you just created it.
  • Click on Show advanced and then New Variable:
    • Specify HUGO_VERSION as the Key for the new variable, and 0.79.0 for the Value.
  • Click on Deploy site.

Deploy to Netlify button

Deploy to Netlify

NOTE: Gitib does not allow third party tools to create/modify Github actions workflows and this template contains workflows, so clicking the button above will not copy code to your new repository, but it will publish website to netlify. Follow the instructions above to create a repository with code.

Click on the button above and follow these instructions:

  • Click Connect to GitHub
  • Enter Login and Password
  • Choose Repository Name and Save & Deploy
Add your own status badge You can get a status badge for you website by going to Netlify website, login, go to Site settings > Status badges, copy the status badge.


Last modified 2021-07-24 : pg_build (fae2843)