Skip to content

Commit 98b9f55

Browse files
authored
Full book is now deployed to gh-pages to be deployed to Connect cloud (#1513)
1 parent 86e3631 commit 98b9f55

File tree

2 files changed

+11
-60
lines changed

2 files changed

+11
-60
lines changed

.github/workflows/Book.yaml

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ on:
2121
- '.github/workflows/Book.yaml'
2222
workflow_dispatch:
2323
inputs:
24-
ghpages:
25-
description: 'Build gitbook with pandoc devel and deploy gitbook to gh-page for checking differences'
24+
publish:
25+
description: 'publish the book to github pages for connect cloud deployment'
2626
required: false
27-
default: true
27+
default: false
28+
type: boolean
2829

2930
name: Build and deploy book
3031

@@ -45,17 +46,15 @@ jobs:
4546

4647
steps:
4748
- name: Checkout Repo
48-
uses: actions/checkout@v4
49+
uses: actions/checkout@v6
4950

5051
- name: Install R
5152
uses: r-lib/actions/setup-r@v2
5253

5354
- name: Install Pandoc
5455
uses: r-lib/actions/setup-pandoc@v2
5556
with:
56-
# install nightly when checking on gh-pages
57-
pandoc-version: ${{ github.event.inputs.ghpages && 'nightly' || '3.8' }}
58-
token: ${{ secrets.GITHUB_TOKEN }}
57+
pandoc-version: latest
5958

6059
- name: Install TinyTeX
6160
uses: r-lib/actions/setup-tinytex@v2
@@ -86,29 +85,18 @@ jobs:
8685
key: bookdown-${{ hashFiles('inst/examples/*Rmd') }}
8786
restore-keys: bookdown-
8887

89-
- name: Test build of HTML books
90-
if: github.event_name == 'pull_request'
91-
run: make -C inst/examples gitbook bs4_book
92-
93-
- name: Build and Deploy all book
94-
if: github.event_name == 'push'
95-
env:
96-
CONNECT_API_KEY: ${{ secrets.RSC_BOOKDOWN_ORG_TOKEN }}
97-
CONTENT_ID: 3
88+
- name: Build all book formats
9889
run: make -C inst/examples all
9990

100-
- name: Build Gitbook only
101-
env:
102-
DEPLOY_GH_PAGES: ${{ github.event.inputs.ghpages }}
103-
if: github.event_name == 'workflow_dispatch'
104-
run: make -C inst/examples gitbook
105-
10691
- name: Deploy Gitbook to gh-pages
107-
if: github.event_name == 'workflow_dispatch' && github.event.inputs.ghpages
92+
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
10893
uses: JamesIves/github-pages-deploy-action@v4
10994
with:
11095
branch: gh-pages
11196
folder: inst/examples/_book
97+
clean: true
98+
single-commit: true
99+
dry-run: ${{ (github.event_name == 'workflow_dispatch' && (github.event.inputs.publish == 'false' || github.event.inputs.publish == false)) || false }}
112100

113101
- name: Upload book folder for debug
114102
if: failure()

inst/examples/_render.R

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
quiet = "--quiet" %in% commandArgs(FALSE)
22
formats = commandArgs(TRUE)
3-
# travis is still use for github page deployment
4-
# TODO: Remove github page deployment
5-
ghpages = identical(Sys.getenv("DEPLOY_GH_PAGES", NA), "true")
6-
73

84
src = (function() {
95
attr(body(sys.function()), 'srcfile')
@@ -34,44 +30,11 @@ for (f in list.files('_book', '[.]html$', full.names = TRUE)) {
3430
x = readLines(f)
3531

3632
if (length(i <- grep('^\\s*<body>\\s*$', x)) == 0) next
37-
# patch HTML files when published to gh-pages to redirect to bookdown.org
38-
if (ghpages) x[i[1]] = '<body onload="window.location = \'https://bookdown.org/yihui\'+location.pathname">'
3933
i = grep('<i class="fa fa-circle-o-notch fa-spin"></i><a href="./">.+</a>', x)[1]
4034
# shorter title on the toolbar
4135
if (!is.na(i)) x[i] = gsub('bookdown: ', '', x[i], fixed = TRUE)
42-
# Remove some lines when published to gh-pages
43-
if (ghpages) {
44-
i = c(
45-
grep('&lt;bytecode: 0x[0-9a-f]+&gt;$', x),
46-
grep('^\\s*<meta name="generator" content="bookdown [.0-9]+ and GitBook [.0-9]+" />$', x),
47-
grep('^<meta name="date" content="[-0-9]+" />$', x)
48-
)
49-
if (length(i)) x = x[-i]
50-
}
5136

5237
writeLines(x, f)
5338
}
5439

55-
# When several format are rendered, usually when make all is called,
56-
# then we publish everything to bookdown.org
57-
if (length(formats) > 1 && !ghpages) {
58-
message(">> Publishing Books")
59-
if (!is.na(Sys.getenv("CI", NA))) {
60-
# On CI connect to server, using API KEY and deploy using appId
61-
rsconnect::addServer('https://bookdown.org', 'bookdown.org')
62-
rsconnect::connectApiUser(
63-
account = 'GHA', server = 'bookdown.org',
64-
apiKey = Sys.getenv('CONNECT_API_KEY')
65-
)
66-
rsconnect::deploySite(
67-
appId = Sys.getenv('CONTENT_ID'),
68-
server = 'bookdown.org',
69-
render = 'none', logLevel = 'verbose',
70-
forceUpdate = TRUE)
71-
} else {
72-
# for local deployment when rsconnect/ is available
73-
bookdown::publish_book('bookdown', server = 'bookdown.org', render = 'none')
74-
}
75-
}
76-
7740
setwd(owd)

0 commit comments

Comments
 (0)