Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Travis CI + Netlify workflow #1

Closed
apreshill opened this issue Nov 1, 2018 · 6 comments
Closed

Travis CI + Netlify workflow #1

apreshill opened this issue Nov 1, 2018 · 6 comments

Comments

@apreshill
Copy link
Collaborator

apreshill commented Nov 1, 2018

Still not entirely sure what worked and what did not, but these are my breadcrumbs for next time...

  1. Make a new Netlify site from GitHub repo via browser

  2. If first time doing this at all, locally install Netlify CLI via terminal

brew install node # install nodejs first via homebrew
npm install netlify-cli -g # then install cli for netlify
netlify login # via browser pop-up
  1. For each new site, do:
netlify link

From Jenny's notes: "This produced .netlify/state.json, which holds the (non-secret) site id. Apparently this can also be provided via a travis env var named NETLIFY_SITE_ID (ok to reveal in the log)."

What did not work was: (a) setting the netlify site link with a text file called .netlify; or (b) using the "path":"_book" in that file either (conclude that you should use the .travis.yml below to set the --dir _book instead).

  1. Obtain a Token in the Netlify UI

  2. In Travis:

    • enable continuous integration for your book’s GitHub repo on Travis
    • save the Netlify token from step 4 as a NETLIFY_AUTH_TOKEN environment variable.
  3. Following Sean Kross' instructions for adding Travis to a bookdown

    • add .Rbuildignore
    • add DESCRIPTION
    • add .travis.yml:
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r

language: R
sudo: false
cache:
  packages: true
  directories:
  - _bookdown_files
  - $HOME/.npm

before_install:
- npm install netlify-cli -g

script:
- Rscript -e 'bookdown::render_book("index.Rmd")'

after_success:
- netlify deploy --prod --dir _book
  1. Modify .gitignore to include:

    • _book (unless you had changed the bookdown default output_dir to something else)
    • _bookdown_files
  2. add, commit, and push these files.

Lots of help from @jennybc's notes:

rstats-wtf/what-they-forgot#25

And from here:

rstudio/bookdown#459

And here:
dgrtwo/tidy-text-mining#42

@apreshill
Copy link
Collaborator Author

apreshill commented Nov 6, 2018

Another option from @ismayc:

  1. Have travis build book, then push to a different branch (target_branch: gh-pages); travis docs here

  2. Have Netlify deploy from that branch (gh-pages), not master.

https://github.com/moderndive/moderndive_book/blob/master/.travis.yml

@ismayc
Copy link

ismayc commented Nov 6, 2018

My settings in Netlify in case that wasn't clear.
screenshot 2018-09-25 12 24 20

@hammer
Copy link

hammer commented Nov 14, 2018

Thanks for writing this up! I used your directions to get a deploy of bookdown-demo working: https://github.com/hammer/test-book. One thing I noticed was that the PDF and EPUB downloads weren't working, so I changed bookdown::render_book("index.Rmd") to rmarkdown::render_site(encoding = 'UTF-8') in .travis.yml.

I'm not sure if this approach is preferred over repeated invocations of bookdown::render_book (the approach taken by Yihui in bookdown-demo), so I've asked on StackOverflow.

Either way, I thought others like me who come to this issue seeking guidance may benefit from what I've learned about PDF and EPUB building today.

Thanks again and apologies if the above information is redundant for you!

@rudeboybert
Copy link

@ismayc work setting up GitHub + Travis CI + Netlify integration has been total cash money. Being able to fix typos in the source .Rmd only and then publish on the web w/o rebuilding the book locally has been a yooge time saver @ajohns24 @MilesOtt

Also @apreshill, I'm sure you're already 76 steps ahead of me, but people would ❤️a tutorial on integrating bookdown + Travis CI that's in a similar vein as your Up and running with blogdown tutorial! I loved it, my advanced students loved it, everyone loved it! Dunno if you have the bandwidth to write one up, but I'm sure it would equally sell like 🔥🍰!

@apreshill
Copy link
Collaborator Author

apreshill commented Dec 9, 2018

Huzzah this worked!

new _travis.yml

# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r

language: R
sudo: false
cache:
  packages: true
  directories:
  - _bookdown_files

script:
- Rscript -e 'bookdown::render_book("index.Rmd", "bookdown::gitbook")'

deploy:
  provider: pages
  local_dir: _book
  skip_cleanup: true
  keep-history: true
  github_token: $stat545_GITHUB_PAT
  target_branch: gh-pages
  on:
    all_branches: true

screen shot 2018-12-08 at 8 30 02 pm

@jennybc
Copy link
Collaborator

jennybc commented Sep 15, 2019

I've reworked this with manual deploys and using renv to manage the package library. Closing (current state is 11a618f).

@jennybc jennybc closed this as completed Sep 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants