-
Notifications
You must be signed in to change notification settings - Fork 0
301 lines (277 loc) · 9.62 KB
/
book-production.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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
name: book-production
run-name: book-production for ${{ inputs.doi }}
on:
workflow_dispatch:
inputs:
doi:
description: 'DOI of book (last four digits only)'
required: true
type: number
has_pdf:
description: 'Run PDF workflow'
default: true
required: true
type: boolean
has_epub:
description: 'Run EPUB workflow'
default: true
required: true
type: boolean
run_archive:
description: 'Run URL archiving'
default: true
required: true
type: boolean
copyright_page:
description: 'Copyright page number (default is 4, first page is 0)'
default: 4
required: true
type: number
env:
WORK_DIR: /ebook_automation/
OUT_DIR: /ebook_automation/output/
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
jobs:
download-pdf:
runs-on: ubuntu-latest
if: ${{ inputs.has_pdf || inputs.run_archive }}
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Copy PDF from S3
run: |
aws s3 cp ${{ secrets.S3_URL }}obp.${{ inputs.doi }}.pdf .
- name: Save PDF
uses: actions/upload-artifact@v4
with:
name: original-pdf
path: obp.${{ inputs.doi }}.pdf
retention-days: 10
if-no-files-found: error
overwrite: true
download-epub:
runs-on: ubuntu-latest
if: ${{ inputs.has_epub }}
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Copy EPUB from S3
run: |
aws s3 cp ${{ secrets.S3_URL }}obp.${{ inputs.doi }}.epub .
- name: Save EPUB
uses: actions/upload-artifact@v4
with:
name: original-epub
path: obp.${{ inputs.doi }}.epub
retention-days: 10
if-no-files-found: error
overwrite: true
archive-pdf-urls:
needs: download-pdf
runs-on: ubuntu-latest
if: ${{ inputs.run_archive }}
steps:
- name: Install archive-pdf-urls
# https://github.com/thoth-pub/archive-pdf-urls
run: cargo install archive-pdf-urls
- name: Retrieve PDF
uses: actions/download-artifact@v4
with:
name: original-pdf
- name: Run archive-pdf-urls Rust script
run: archive-pdf-urls obp.${{ inputs.doi }}.pdf --exclude https://doi.org/10.11647/OBP.${{ inputs.doi }}\*
chapter-splitter:
needs: download-pdf
runs-on: ubuntu-latest
if: ${{ inputs.has_pdf }}
container:
image: openbookpublishers/chapter-splitter
steps:
- name: Retrieve Data
uses: actions/download-artifact@v4
with:
name: original-pdf
path: ${{ env.WORK_DIR }}
- name: Create Output Folder
run: mkdir ${{ env.OUT_DIR }}
- name: Run Python Command
working-directory: ${{ env.WORK_DIR }}
run: |
python3 main.py \
--input-file obp.${{ inputs.doi }}.pdf \
--output-folder ${{ env.OUT_DIR }} \
--write-urls \
10.11647/obp.${{ inputs.doi }}
env:
THOTH_EMAIL: ${{ secrets.THOTH_EMAIL }}
THOTH_PWD: ${{ secrets.THOTH_PASSWORD }}
COPYRIGHT_PAGE: ${{ inputs.copyright_page }}
- name: Save Data
uses: actions/upload-artifact@v4
with:
name: chapters
path: ${{ env.OUT_DIR }}
retention-days: 1
if-no-files-found: error
overwrite: true
epublius:
needs: download-epub
runs-on: ubuntu-latest
container:
image: openbookpublishers/epublius
steps:
- name: Retrieve Data
uses: actions/download-artifact@v4
with:
name: original-epub
path: ${{ env.WORK_DIR }}
- name: Create Output Folder
run: mkdir ${{ env.OUT_DIR }}
- name: Run Python Command
working-directory: ${{ env.WORK_DIR }}
run: |
./thoth_wrapper.py obp.${{ inputs.doi }}.epub \
--doi 10.11647/obp.${{ inputs.doi }}
env:
MATHJAX: 'False'
PRIVACYPOLICY_URL: 'https://www.openbookpublishers.com/policies/privacy/'
OUTDIR: ${{ env.OUT_DIR }}
THOTH_EMAIL: ${{ secrets.THOTH_EMAIL }}
THOTH_PWD: ${{ secrets.THOTH_PASSWORD }}
- name: Save Data
uses: actions/upload-artifact@v4
with:
name: HTML
path: ${{ env.OUT_DIR }}/10.11647/
retention-days: 1
if-no-files-found: error
overwrite: true
upload-chapters:
needs: chapter-splitter
runs-on: ubuntu-latest
env:
CHAPTERS_DIR: ./chapters
steps:
- name: Retrieve Data
uses: actions/download-artifact@v4
with:
name: chapters
path: ${{ env.CHAPTERS_DIR }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Copy Chapter PDFs to S3
run: |
aws s3 cp ${{ env.CHAPTERS_DIR }} ${{ secrets.S3_URL }} --recursive
upload-html:
needs: epublius
runs-on: ubuntu-latest
steps:
- name: Retrieve Data
uses: actions/download-artifact@v4
with:
name: HTML
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Copy HTML Edition to S3
run: |
aws s3 cp ./obp.${{ inputs.doi }}/ ${{ secrets.S3_URL }}obp.${{ inputs.doi }}/ --recursive
cit-ex-obp-loader:
needs: upload-html
runs-on: ubuntu-latest
container:
image: openbookpublishers/cit-ex-obp-loader
env:
WORK_DIR: /home/obp/cit-ex/
steps:
- name: Run Python Command
working-directory: ${{ env.WORK_DIR }}
run: |
python3 obp-loader.py 10.11647/obp.${{ inputs.doi }}
env:
THOTH_EMAIL: ${{ secrets.THOTH_EMAIL }}
THOTH_PWD: ${{ secrets.THOTH_PASSWORD }}
status:
runs-on: ubuntu-latest
needs: [upload-chapters, cit-ex-obp-loader]
if: always()
steps:
- name: Set up job status summary
id: generate_summary
run: |
get_status_emoji() {
local status=$1
if [ "$status" == "success" ]; then
echo ":large_green_circle:"
elif [ "$status" == "failure" ]; then
echo ":red_circle:"
else
echo ":white_circle:"
fi
}
overall_status() {
local statuses=("$@")
local overall="success"
local all_skipped_or_cancelled=true
for status in "${statuses[@]}"; do
if [ "$status" == "failure" ]; then
overall="failure"
all_skipped_or_cancelled=false
break
elif [ "$status" == "success" ]; then
all_skipped_or_cancelled=false
fi
done
if [ "$all_skipped_or_cancelled" = true ]; then
overall="skipped"
fi
echo $overall
}
PDF_WORKFLOW_STATUS=$(overall_status "${{ needs.download-pdf.result }}" "${{ needs.chapter-splitter.result }}" "${{ needs.upload-chapters.result }}")
EPUB_WORKFLOW_STATUS=$(overall_status "${{ needs.download-epub.result }}" "${{ needs.epublius.result }}" "${{ needs.upload-html.result }}" "${{ needs.cit-ex-obp-loader.result }}")
echo "| Workflow | Status | |" >> summary.md
echo "| -------- | ------ | - |" >> summary.md
echo "| PDF Workflow | $PDF_WORKFLOW_STATUS | $(get_status_emoji $PDF_WORKFLOW_STATUS) |" >> summary.md
echo "| EPUB Workflow | $EPUB_WORKFLOW_STATUS | $(get_status_emoji $EPUB_WORKFLOW_STATUS) |" >> summary.md
- name: Write summary to GITHUB_STEP_SUMMARY
run: cat summary.md >> $GITHUB_STEP_SUMMARY
- name: Read summary into environment variable
id: summary
run: |
echo "SUMMARY<<EOF" >> $GITHUB_ENV
cat summary.md >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Send notification to Mattermost
uses: mattermost/action-mattermost-notify@master
with:
MATTERMOST_WEBHOOK_URL: ${{ secrets.MM_WEBHOOK_URL }}
TEXT: |
#### Book production workflow for ${{ inputs.doi }}
@channel please review the [workflow run](${{ env.WORKFLOW_URL }}).
${{ env.SUMMARY }}
report-pdf-archiving-failure:
runs-on: ubuntu-latest
needs: archive-pdf-urls
if: failure()
steps:
- uses: mattermost/action-mattermost-notify@master
with:
MATTERMOST_WEBHOOK_URL: ${{ secrets.MM_WEBHOOK_URL }}
TEXT: |
#### :red_circle: Archive PDF URLs for ${{inputs.doi}} has failed
@channel please review the [workflow run](${{ env.WORKFLOW_URL }})