Skip to content

Commit 7c9b18b

Browse files
authored
Publish book to gh-pages (#774)
do this when we want to deploy to posit connect cloud
1 parent b2c17c6 commit 7c9b18b

File tree

2 files changed

+20
-41
lines changed

2 files changed

+20
-41
lines changed

.github/workflows/bookdown.yaml

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,18 @@ on:
66
paths:
77
- 'docs/**'
88
- '.github/workflows/bookdown.yaml'
9+
pull_request:
10+
branches: [main, master]
11+
paths:
12+
- 'docs/**'
13+
- '.github/workflows/bookdown.yaml'
914
workflow_dispatch:
15+
inputs:
16+
publish:
17+
description: 'publish the book to github pages for connect cloud deployment'
18+
required: false
19+
default: false
20+
type: boolean
1021

1122
name: Build and deploy book
1223

@@ -51,28 +62,18 @@ jobs:
5162
key: bookdown-1-${{ hashFiles('docs/*Rmd') }}
5263
restore-keys: bookdown-1-
5364

54-
- name: Build and Deploy all book
55-
if: github.event_name == 'push'
56-
env:
57-
CONNECT_API_KEY: ${{ secrets.RSC_BOOKDOWN_ORG_TOKEN }}
58-
CONTENT_ID: 463
65+
- name: Build all book
5966
run: make -C docs all
6067

61-
- uses: actions/github-script@v3
62-
env:
63-
URL: https://bookdown.org/yihui/blogdown
68+
- name: Deploy Gitbook to gh-pages
69+
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
70+
uses: JamesIves/github-pages-deploy-action@v4
6471
with:
65-
github-token: ${{secrets.GITHUB_TOKEN}}
66-
script: |
67-
github.repos.createCommitStatus({
68-
owner: context.repo.owner,
69-
repo: context.repo.repo,
70-
sha: context.sha,
71-
state: "success",
72-
target_url: "${{ env.URL}}",
73-
description: "Book deployed!",
74-
context: "bookdown.org"
75-
})
72+
branch: gh-pages
73+
folder: docs/_book
74+
clean: true
75+
single-commit: true
76+
dry-run: ${{ (github.event_name == 'workflow_dispatch' && (github.event.inputs.publish == 'false' || github.event.inputs.publish == false)) || false }}
7677

7778
- name: Upload book folder for debug
7879
if: failure()

docs/_render.R

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,4 @@ for (fmt in formats) {
1818
if (res != 0) stop('Failed to compile the book to ', fmt)
1919
}
2020

21-
# When several format are rendered, usually when make all is called,
22-
# then we publish everything to bookdown.org
23-
if (length(formats) > 1) {
24-
if (!is.na(Sys.getenv("CI", NA))) {
25-
xfun::pkg_load2("rsconnect")
26-
# On CI connect to server, using API KEY and deploy using appId
27-
rsconnect::addConnectServer('https://bookdown.org', 'bookdown.org')
28-
rsconnect::connectApiUser(
29-
account = 'GHA', server = 'bookdown.org',
30-
apiKey = Sys.getenv('CONNECT_API_KEY')
31-
)
32-
rsconnect::deploySite(
33-
appId = Sys.getenv('CONTENT_ID'),
34-
server = 'bookdown.org',
35-
render = 'none', logLevel = 'verbose',
36-
forceUpdate = TRUE)
37-
} else if (Sys.getenv('USER') == 'yihui') {
38-
# for local deployment when rsconnect/ is available
39-
bookdown::publish_book('blogdown', server = 'bookdown.org', render = 'none')
40-
}
41-
}
42-
4321
setwd(owd)

0 commit comments

Comments
 (0)