-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
233 lines (210 loc) · 9.77 KB
/
action.yml
File metadata and controls
233 lines (210 loc) · 9.77 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
name: 'ottr-preview'
author: "Candace Savonen"
description: "Render a preview for an Rmd or Quarto website or course"
inputs:
toggle_website:
description: "Is this Rmd or Quarto based? Should be a string of either 'rmd', 'quarto', 'rmd_web', or 'quarto_web'"
default: false
type: string
required: true
root_path:
description: "What is the relative file path to the root of the course directory? Default is top of the directory"
default: "."
type: string
preview:
description: "True or false a preview branch should be created for this. "
default: true
type: boolean
docker_image:
description: "The docker image that will be used for rendering"
default: jhudsl/base_ottr:dev
type: string
token:
description: "A GitHub personal access token only needed if preview = 'false'. Needs privileges to merge to main."
type: string
runs:
using: "composite"
steps:
- name: Checkout files
if: ${{ inputs.preview == 'true' }}
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout files for rendering on main
if: ${{ inputs.preview == 'false' }}
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ inputs.token }}
# Set up git checkout
- name: Set up git checkout
run: |
git config --global --add safe.directory $GITHUB_WORKSPACE
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
shell: bash
# Set up git checkout
- name: Set up preview branch
if: ${{ inputs.preview == 'true' }}
run: |
git push origin --delete preview-${{ github.event.pull_request.number }} || echo "No branch to delete"
branch_name='preview-${{ github.event.pull_request.number }}'
echo branch doesnt exist
git checkout -b $branch_name || echo branch exists
git push --set-upstream origin $branch_name || echo branch exists remotely
git fetch --all
git checkout $branch_name
git merge -s recursive --strategy-option=theirs origin/${{ github.head_ref }} --allow-unrelated-histories
shell: bash
# We want a fresh run of the renders each time
- name: Delete old docs/*
if: ${{ inputs.preview == 'false' }}
run: |
git remote set-url origin https://${{ inputs.token }}@github.com/$GITHUB_REPOSITORY
git fetch origin
git pull --rebase --allow-unrelated-histories --strategy-option=ours
rm -rf docs/*
shell: bash
# Run rendering
- name: Render Special
id: render
run: |
curl -OL https://github.com/ottrproject/ottr-preview/raw/refs/heads/main/entrypoint.sh
# TODO: I was fighting curl about downloads I know this should be a separate step
# Just fix this silly thing later.
if [ '${{ inputs.root_path }}' != '.' ]; then
mv entrypoint.sh ${{ inputs.root_path }}/entrypoint.sh
fi
docker run -v ${{ github.workspace }}/${{ inputs.root_path }}:/home \
${{ inputs.docker_image }} bash /home/entrypoint.sh ${{ inputs.toggle_website }} || exit_code=$?
rm ${{ inputs.root_path }}/entrypoint.sh
exit ${exit_code:-0}
shell: bash
# This checks on the steps before it and makes sure that they completed.
# If the renders didn't complete we don't want to commit the file changes
- name: Check on render steps
run: |
echo Rendering status ${{steps.render.outcome}}
if [ '${{steps.render.outcome}}' != 'success']; then
exit 1
fi
shell: bash
- name: Website preview for download
if: ${{ inputs.preview == 'true' }}
run: |
if [ '${{ inputs.root_path }}' != '.' ]; then
cd ${{ github.workspace }}/${{ inputs.root_path }}/docs
zip -r ${{ github.workspace }}/${{ inputs.root_path }}/website-preview.zip .
else
cd ${{ github.workspace }}/docs
zip -r ${{ github.workspace }}/website-preview.zip .
fi
shell: bash
# Commit the rendered files
- name: Commit rendered files to preview branch
if: ${{ inputs.preview == 'true' }}
id: commit
run: |
branch_name='preview-${{ github.event.pull_request.number }}'
git diff origin/main -- ${{ inputs.root_path }}/docs >/dev/null && changes=true || changes=false
echo "changes=$changes" >> $GITHUB_OUTPUT
git add -A --force
git commit -m 'Render preview' || echo "No changes to commit"
git clean --force
git pull --rebase --set-upstream origin $branch_name --allow-unrelated-histories --strategy-option=ours
git push --force || echo "No changes to commit"
shell: bash
# Commit the rendered files
- name: Commit rendered files to original branch
if: ${{ inputs.preview == 'true' }}
id: commit_rendered
run: |
git add ${{ github.workspace }}/${{ inputs.root_path }}/* --force
git commit -m 'Re-render' || echo "No changes to commit"
git pull --rebase --set-upstream origin $branch_name --allow-unrelated-histories --strategy-option=ours
git push --force || echo "No changes to commit"
shell: bash
# Commit the rendered course files
- name: Commit rendered course files
if: ${{ inputs.preview == 'false' }}
env:
GH_PAT: ${{ inputs.token }}
run: |
git add --force docs/*
git commit -m 'Render course' || echo "No changes to commit"
git status docs/*
git push --force -u origin main || echo "No changes to push"
shell: bash
- name: Find Comment
if: ${{ inputs.preview == 'true' }}
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: latest commit
- name: Build components of the comment
if: ${{ inputs.preview == 'true' }}
id: build-components
run: |
if [ '${{ inputs.root_path }}' != '.' ]; then
cd ${{ github.workspace }}/${{ inputs.root_path }}/docs
docx_file="${{ github.workspace }}/${{ inputs.root_path }}/docs/$(ls *.docx 2>/dev/null | head -1 || true)"
else
cd ${{ github.workspace }}/docs
docx_file="${{ github.workspace }}/docs/$(ls *.docx 2>/dev/null | head -1 || true)"
fi
if [ -n "$docx_file" ]; then
docx_link="https://github.com/$GITHUB_REPOSITORY/raw/preview-${{ github.event.pull_request.number }}/$docx_file"
else
docx_link="NA"
fi
bookdown_link=$(echo "https://htmlpreview.github.io/?https://raw.githubusercontent.com/$GITHUB_REPOSITORY/preview-${{ github.event.pull_request.number }}/${{ inputs.root_path }}/docs/index.html")
zip_link=$(echo "https://github.com/$GITHUB_REPOSITORY/raw/preview-${{ github.event.pull_request.number }}/${{ inputs.root_path }}/website-preview.zip")
echo "zip_link=$zip_link" >> $GITHUB_OUTPUT
echo "bookdown_link=$bookdown_link" >> $GITHUB_OUTPUT
echo "docx_link=$docx_link" >> $GITHUB_OUTPUT
echo "time=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
echo "commit_id=$GITHUB_SHA" >> $GITHUB_OUTPUT
echo ${{steps.commit.outputs.changes}}
shell: bash
- name: Create or update comment (with docx file)
if: ${{ inputs.preview == 'true' && steps.build-components.outputs.docx_link != 'NA' }}
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Re-rendered previews from the latest commit:
- :eyes: Quick [preview of course website here](${{ steps.build-components.outputs.bookdown_link }}) \*
- :microscope: Comprehensive [download of the course website here](${{ steps.build-components.outputs.zip_link }})
- Download the [.docx file](${{ steps.build-components.outputs.docx_link }})
\* note not all html features will be properly displayed in the "quick preview" but it will give you a rough idea.
_Updated at ${{ steps.build-components.outputs.time }} with changes from the latest commit ${{ steps.build-components.outputs.commit_id }}_
edit-mode: replace
- name: Create or update comment (without docx file)
if: ${{ inputs.preview == 'true' && steps.build-components.outputs.docx_link == 'NA' }}
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Re-rendered previews from the latest commit:
- :eyes: Quick [preview of course website here](${{ steps.build-components.outputs.bookdown_link }}) \*
- :microscope: Comprehensive [download of the course website here](${{ steps.build-components.outputs.zip_link }})
\* note not all html features will be properly displayed in the "quick preview" but it will give you a rough idea.
_Updated at ${{ steps.build-components.outputs.time }} with changes from the latest commit ${{ steps.build-components.outputs.commit_id }}_
edit-mode: replace
- name: Comment if no changes
if: ${{ inputs.preview == 'true' && steps.commit.outputs.changes == 'false' }}
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
The latest commit did not produce rendering changes.
_Updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_
edit-mode: replace
branding:
icon: "briefcase"
color: "blue"