1
1
# Candace Savonen 2021
2
- # Updated Jan 2023
2
+ # Updated May 2024
3
3
4
4
name : Pull Request
5
5
14
14
runs-on : ubuntu-latest
15
15
steps :
16
16
- name : Checkout
17
- uses : actions/checkout@v3
17
+ uses : actions/checkout@v4
18
18
with :
19
19
fetch-depth : 0
20
+ token : ${{ secrets.GH_PAT }}
20
21
21
22
# Use the yaml-env-action action.
22
23
- name : Load environment from YAML
@@ -32,16 +33,18 @@ jobs:
32
33
- name : Make the branch fresh
33
34
run : |
34
35
git config --global --add safe.directory $GITHUB_WORKSPACE
35
- git config --global user.email "[email protected] "
36
- git config --global user.name "jhudsl-robot"
36
+ git config --global user.name 'github-actions[bot]'
37
+ git config --global user.email 'github-actions[bot]@users.noreply.github.com'
37
38
38
39
branch_name='preview-${{ github.event.pull_request.number }}'
39
40
echo branch doesnt exist
40
41
git checkout -b $branch_name || echo branch exists
41
- git push --set-upstream origin $branch_name
42
+ git push --set-upstream origin $branch_name || echo branch exists remotely
42
43
shell : bash
43
44
45
+
44
46
outputs :
47
+ toggle_website : " ${{ env.RENDER_WEBSITE }}"
45
48
toggle_spell_check : " ${{ env.SPELL_CHECK }}"
46
49
toggle_style_code : " ${{ env.STYLE_CODE }}"
47
50
toggle_url_check : " ${{ env.URL_CHECKER }}"
59
62
check_type : spelling
60
63
error_min : 3
61
64
gh_pat : secrets.GH_PAT
65
+ branch_name : ${GITHUB_HEAD_REF}
62
66
63
67
url-check :
64
68
name : Check URLs
69
73
check_type : urls
70
74
error_min : 0
71
75
gh_pat : secrets.GH_PAT
76
+ branch_name : ${GITHUB_HEAD_REF}
72
77
73
78
quiz-check :
74
79
name : Check quiz formatting
79
84
check_type : quiz_format
80
85
error_min : 0
81
86
gh_pat : secrets.GH_PAT
87
+ branch_name : ${GITHUB_HEAD_REF}
82
88
83
89
# ############################ Style the code ###################################
84
90
style-code :
@@ -91,18 +97,18 @@ jobs:
91
97
92
98
steps :
93
99
- name : Checkout files
94
- uses : actions/checkout@v3
100
+ uses : actions/checkout@v4
95
101
with :
96
102
fetch-depth : 0
97
103
98
104
- name : Run styler
99
- run : Rscript -e "styler::style_file(list.files(pattern = 'Rmd $', recursive = TRUE , full.names = TRUE));warnings()"
105
+ run : Rscript -e "styler::style_file(list.files(pattern = '(R|q)md $', recursive = FALSE , full.names = TRUE));warnings()"
100
106
101
107
- name : Commit styled files
102
108
run : |
103
109
git config --system --add safe.directory "$GITHUB_WORKSPACE"
104
- git add \*.Rmd
105
- git commit -m 'Style Rmds ' || echo "No changes to commit"
110
+ git add \*md
111
+ git commit -m 'Style *mds ' || echo "No changes to commit"
106
112
git push origin || echo "No changes to commit"
107
113
108
114
# ############################ Render Preview ###################################
@@ -117,16 +123,16 @@ jobs:
117
123
118
124
steps :
119
125
- name : Checkout files
120
- uses : actions/checkout@v3
126
+ uses : actions/checkout@v4
121
127
with :
122
128
fetch-depth : 0
123
129
124
130
# Set up git checkout
125
131
- name : Set up git checkout
126
132
run : |
127
133
git config --global --add safe.directory $GITHUB_WORKSPACE
128
- git config --global user.email "[email protected] "
129
- git config --global user.name "jhudsl-robot"
134
+ git config --global user.name 'github-actions[bot]'
135
+ git config --global user.email 'github-actions[bot]@users.noreply.github.com'
130
136
131
137
branch_name='preview-${{ github.event.pull_request.number }}'
132
138
git fetch --all
@@ -137,23 +143,35 @@ jobs:
137
143
# Run bookdown rendering
138
144
- name : Run bookdown render
139
145
id : bookdown
146
+ if : ${{needs.yaml-check.outputs.toggle_website == 'rmd' }}
140
147
run : Rscript -e "bookdown::render_book('index.Rmd', output_format = 'all')"
141
148
142
- # Run TOC-less version
143
- # Rendered content for Leanpub and Coursera is very similar.
144
- # This job creates a shared scaffold for both.
145
- - name : Run TOC-less version of render
146
- id : tocless
147
- run : Rscript -e "ottrpal::render_without_toc()"
149
+ # Run quarto rendering
150
+ - name : Render quarto version
151
+ id : quarto
152
+ if : ${{needs.yaml-check.outputs.toggle_website == 'quarto' }}
153
+ run : Rscript -e "quarto::quarto_render('.')"
148
154
149
155
# This checks on the steps before it and makes sure that they completed.
150
156
# If the renders didn't complete we don't want to commit the file changes
151
- - name : Check on render steps
152
- if : steps.bookdown.outcome != 'success' || steps.tocless.outcome != 'success'
157
+ - name : Check on Rmd render steps
158
+ if : ${{needs.yaml-check.outputs.toggle_website == 'rmd' }}
153
159
run : |
154
160
echo Bookdown status ${{steps.bookdown.outcome}}
155
- echo Toc-less status ${{steps.tocless.outcome}}
156
- exit 1
161
+ if [${{steps.bookdown.outcome}} != 'success']; then
162
+ exit 1
163
+ fi
164
+
165
+ - name : Check on quarto render steps
166
+ if : ${{needs.yaml-check.outputs.toggle_website == 'quarto' }}
167
+ run : |
168
+ echo Quarto status ${{steps.quarto.outcome}}
169
+ if [${{steps.quarto.outcome}} != 'success']; then
170
+ exit 1
171
+ fi
172
+
173
+ - name : Website preview for download
174
+ run : zip website-preview.zip docs/* -r
157
175
158
176
# Commit the rendered bookdown files
159
177
- name : Commit rendered bookdown files to preview branch
@@ -164,7 +182,7 @@ jobs:
164
182
echo "changes=$changes" >> $GITHUB_OUTPUT
165
183
git add . --force
166
184
git commit -m 'Render preview' || echo "No changes to commit"
167
- git pull --set-upstream origin $branch_name --allow-unrelated-histories --strategy-option=ours
185
+ git pull --rebase -- set-upstream origin $branch_name --allow-unrelated-histories --strategy-option=ours
168
186
git push --force || echo "No changes to commit"
169
187
shell : bash
170
188
@@ -181,10 +199,10 @@ jobs:
181
199
run : |
182
200
course_name=$(head -n 1 _bookdown.yml | cut -d'"' -f 2| tr " " "-")
183
201
bookdown_link=$(echo "https://htmlpreview.github.io/?https://raw.githubusercontent.com/$GITHUB_REPOSITORY/preview-${{ github.event.pull_request.number }}/docs/index.html")
184
- tocless_link=$(echo "https://htmlpreview.github.io/?https://raw.githubusercontent.com/$GITHUB_REPOSITORY/preview-${{ github.event.pull_request.number }}/docs/no_toc/index.html")
185
202
docx_link=$(echo "https://github.com/$GITHUB_REPOSITORY/raw/preview-${{ github.event.pull_request.number }}/docs/$course_name.docx")
203
+ zip_link=$(echo "https://github.com/$GITHUB_REPOSITORY/raw/preview-${{ github.event.pull_request.number }}/website-preview.zip")
204
+ echo "zip_link=$zip_link" >> $GITHUB_OUTPUT
186
205
echo "bookdown_link=$bookdown_link" >> $GITHUB_OUTPUT
187
- echo "tocless_link=$tocless_link" >> $GITHUB_OUTPUT
188
206
echo "docx_link=$docx_link" >> $GITHUB_OUTPUT
189
207
echo "time=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
190
208
echo "commit_id=$GITHUB_SHA" >> $GITHUB_OUTPUT
@@ -198,11 +216,13 @@ jobs:
198
216
issue-number : ${{ github.event.pull_request.number }}
199
217
body : |
200
218
Re-rendered previews from the latest commit:
201
- - See [preview of Bookdown here](${{ steps.build-components.outputs.bookdown_link }})
202
- - See [preview of Coursera/Leanpub version here](${{ steps.build-components.outputs.tocless_link }})
203
- - Download the [preview of .docx file](${{ steps.build-components.outputs.docx_link }})
219
+ - :eyes: Quick [preview of course website here](${{ steps.build-components.outputs.bookdown_link }}) \*
220
+ - :microscope: Comprehensive [download of the course website here](${{ steps.build-components.outputs.zip_link }})
221
+ - Download the [.docx file](${{ steps.build-components.outputs.docx_link }})
204
222
205
- _Updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_
223
+ \* note not all html features will be properly displayed in the "quick preview" but it will give you a rough idea.
224
+
225
+ _Updated at ${{ steps.build-components.outputs.time }} with changes from the latest commit ${{ steps.build-components.outputs.commit_id }}_
206
226
edit-mode : replace
207
227
208
228
- name : Comment if no changes
0 commit comments