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