-
Notifications
You must be signed in to change notification settings - Fork 8
130 lines (111 loc) · 4.32 KB
/
deploy_book-en.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
on:
push:
branches:
- main
paths:
- book-en/**
- .github/workflows/deploy_book-en.yml
repository_dispatch:
types: [pong_book]
name: render-book-en
jobs:
repository-dispatch-received:
name: Dispatch received - starting all jobs here
runs-on: ubuntu-latest
steps:
- name: Event Information
run: |
echo "Event '${{ github.event.action }}' received from '${{ github.event.client_payload.repository }}'"
- name: Acknowledge - dispatch response to received pong
if: github.event.action == 'pong_book'
run: |
curl -X POST https://api.github.com/repos/QCBSRworkshops/templateWorkshops/dispatches \
-H 'Accept: application/vnd.github.everest-preview+json' \
-u ${{ secrets.ACCESS_TOKEN }} \
--data '{"event_type": "acknowledged_book_en", "client_payload": { "repository": "'"$GITHUB_REPOSITORY"'" }}'
book-en-job:
name: Render the book for this workshop in bookdown
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
defaults:
run:
working-directory: book-en
steps:
- name: 🛎️ Checkout repository
uses: actions/checkout@v3
- name: 💻 Setup R
uses: r-lib/actions/setup-r@v2
- name: 💾 Cache R packages
uses: actions/cache@v3
with:
path: ${{ env.R_LIBS_USER }}
key: r-${{ hashFiles('DESCRIPTION') }}
- name: 💻 Install pandoc and pandoc citeproc
uses: r-lib/actions/setup-pandoc@v2
- name: 💻 Install R packages and dependencies if needed
run: |
Rscript -e 'list.of.packages <- c("rmarkdown", "bookdown", "formatR");
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])];
if(length(new.packages) > 0) {
install.packages(new.packages, dependencies = TRUE)
print(paste0("The following package was installed:", new.packages))} else
if(length(new.packages) == 0) {
print("All packages have been previously installed and fetched from cache.")}'
- name: 🧶 Render the book using bookdown
run: Rscript -e 'bookdown::render_book("index.Rmd")'
- name: 📜 Create script using purl
run: |
Rscript -e 'rmds <- list.files(pattern = ".Rmd");
rmds <- rmds[-length(rmds)];
for (file in rmds){
file_r <- gsub("Rmd","R",file)
if(file.exists(file_r)){
file.remove(file_r)
}
knitr::purl(file,documentation = 0,output = file_r)
};
rfiles <- list.files(pattern = ".R$");
sink("workshop03-script-en.R", append = FALSE);
for(file in rfiles){
current_file = readLines(file)
cat("#### Section:",file,"\n\n")
cat(current_file, "\n", sep ="\n")
};
sink();
script <- readLines("workshop03-script-en.R");
script <- gsub("## ", "", script);
write(script, file = "workshop03-script-en.R");
file.copy("workshop03-script-en.R", "_book/")'
- name: 🔺 Upload artifact containing the book
uses: actions/upload-artifact@v1
with:
name: book-en
path: book-en/
# Need to first create an empty gh-pages branch
# see https://pkgdown.r-lib.org/reference/deploy_site_github.html
# and also add secrets for an ACCESS_TOKEN
checkout-and-deploy:
name: Checkout and deploy the book within the gh-pages repository
runs-on: ubuntu-latest
needs: book-en-job
steps:
- name: 🛎️ Checkout again
uses: actions/checkout@v3
with:
persist-credentials: false
- name: 🔻 Download artifact containing the book
uses: actions/download-artifact@v3
with:
# Artifact name
name: book-en # optional
# Destination path
path: book-en/ # optional
- name: 💎 Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
token: ${{ secrets.ACCESS_TOKEN }}
branch: gh-pages # The branch the action should deploy to.
folder: book-en/_book/
target-folder: book-en # The folder the action should deploy
clean: true