From b825030fa641ad37f67b107f1cb2a2f4a62043cd Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 2 Dec 2025 16:14:06 +0100 Subject: [PATCH 1/4] Deploy to gh-pages so that we can deploy to Connect Cloud --- .github/workflows/bookdown.yaml | 37 +++++++++++++++++++++++---------- _render.R | 23 -------------------- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/.github/workflows/bookdown.yaml b/.github/workflows/bookdown.yaml index 56b27eb..759e555 100644 --- a/.github/workflows/bookdown.yaml +++ b/.github/workflows/bookdown.yaml @@ -6,6 +6,12 @@ on: pull_request: branches: [main, master] workflow_dispatch: + inputs: + publish: + description: 'publish the book to github pages for connect cloud deployment' + required: false + default: false + type: boolean name: bookdown @@ -17,7 +23,7 @@ jobs: R_KNITR_OPTIONS: "knitr.chunk.tidy=TRUE" steps: - name: Checkout Repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 with: @@ -43,19 +49,28 @@ jobs: run: sudo apt-get install -y ghostscript - name: Cache bookdown results - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: _bookdown_files key: bookdown-${{ hashFiles('**/*Rmd') }} restore-keys: bookdown- - - name: Build Gitbook - if: github.event_name == 'pull_request' - run: make gitbook - - - name: Build and Deploy all book - if: github.event_name == 'push' - env: - CONNECT_API_KEY: ${{ secrets.RSC_BOOKDOWN_ORG_TOKEN }} - CONTENT_ID: c4506062-503b-4747-bcd8-490dd76620cb + - name: Build all book run: make all + + - name: Deploy to gh-pages for Connect Cloud deploy + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' + uses: JamesIves/github-pages-deploy-action@v4 + with: + branch: gh-pages + folder: _book + clean: true + single-commit: true + dry-run: ${{ (github.event_name == 'workflow_dispatch' && (github.event.inputs.publish == 'false' || github.event.inputs.publish == false)) || false }} + + - name: Upload book folder for debug + if: failure() + uses: actions/upload-artifact@main + with: + name: book-dir + path: . diff --git a/_render.R b/_render.R index ceca252..df7c6b6 100644 --- a/_render.R +++ b/_render.R @@ -9,26 +9,3 @@ for (fmt in formats) { res = xfun::Rscript(c('-e', shQuote(cmd))) if (res != 0) stop('Failed to compile the book to ', fmt) } - -# When several format are rendered, usually when make all is called, -# then we publish everything to bookdown.org -if (length(formats) > 1) { - message(">> Publishing Books") - if (!is.na(Sys.getenv("CI", NA))) { - xfun::pkg_load2("rsconnect") - # On CI connect to server, using API KEY and deploy using appId - rsconnect::addConnectServer('https://bookdown.org', 'bookdown.org') - rsconnect::connectApiUser( - account = 'GHA', server = 'bookdown.org', - apiKey = Sys.getenv('CONNECT_API_KEY') - ) - rsconnect::deploySite( - appId = Sys.getenv('CONTENT_ID'), - server = 'bookdown.org', - render = 'none', logLevel = 'verbose', - forceUpdate = TRUE) - } else if (Sys.getenv('USER') == 'yihui') { - # for local deployment when rsconnect/ is available - bookdown::publish_book('rmarkdown', server = 'bookdown.org', render = 'none') - } -} From 4a53203baed2c5aeb98b1f0010fcb69a718b0592 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 2 Dec 2025 17:53:22 +0100 Subject: [PATCH 2/4] Try with webshot2 and chrome --- DESCRIPTION | 2 +- index.Rmd | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 21a1cfa..9b81e8b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,7 +23,7 @@ Imports: servr, shiny, tufte, - webshot, + webshot2, xaringan, sigma Remotes: diff --git a/index.Rmd b/index.Rmd index 09a6d04..2b7ac5b 100644 --- a/index.Rmd +++ b/index.Rmd @@ -53,8 +53,7 @@ options(bookdown.post.latex = function(x) { x }) -knitr::opts_chunk$set(webshot = "webshot") -webshot::install_phantomjs() +knitr::opts_chunk$set(webshot = "webshot2") ``` # Preface {-} From b0222ee59d52b762c7f47042ea9417d0ada424de Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 2 Dec 2025 18:10:59 +0100 Subject: [PATCH 3/4] Use dev knitr This is because we need https://github.com/yihui/knitr/pull/2400 --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9b81e8b..a416789 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,6 +27,7 @@ Imports: xaringan, sigma Remotes: - jjallaire/sigma + jjallaire/sigma, + yihui/knitr Config/Needs/deploy: rsconnect Encoding: UTF-8 From d3e499aafc6183be1316f348919d31066da81f98 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 2 Dec 2025 18:44:28 +0100 Subject: [PATCH 4/4] knitr is not directly a dependency so install dev version from CI --- .github/workflows/bookdown.yaml | 1 + DESCRIPTION | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bookdown.yaml b/.github/workflows/bookdown.yaml index 759e555..cf42a42 100644 --- a/.github/workflows/bookdown.yaml +++ b/.github/workflows/bookdown.yaml @@ -43,6 +43,7 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: needs: deploy + extra-packages: github::yihui/knitr - name: Install missing system dependencies if: runner.os == 'Linux' diff --git a/DESCRIPTION b/DESCRIPTION index a416789..9b81e8b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,7 +27,6 @@ Imports: xaringan, sigma Remotes: - jjallaire/sigma, - yihui/knitr + jjallaire/sigma Config/Needs/deploy: rsconnect Encoding: UTF-8