-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaeaready
More file actions
executable file
·460 lines (413 loc) · 15 KB
/
aeaready
File metadata and controls
executable file
·460 lines (413 loc) · 15 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
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
#!/bin/bash
os=$(uname)
apperror=0
version=1.1
#
# A few alternative looks
# CSSURL=https://gist.githubusercontent.com/ryangray/1882525/raw/2a6e53f645b960f0bed16d686ba3df36505f839f/buttondown.css
#set -e
#CSSURL=https://gist.githubusercontent.com/dashed/6714393/raw/ae966d9d0806eb1e24462d88082a0264438adc50/github-pandoc.css
CSSURL=https://raw.githubusercontent.com/AEADataEditor/editor-scripts/refs/heads/main/.aeaready.css
CSSLOCAL=.aeaready.css
LOGOLOCAL=.logo-aea-88x88.jpg
DOCKERIMG=aeadataeditor/html-to-pdf:latest
dockerbin=$(which docker1 2>/dev/null || which docker)
#pdfengine="--pdf-engine wkhtmltopdf"
#pdfengine=""
pdfengine="docker"
case $pdfengine in
"")
WKHTMLOPTS="-s Letter --disable-smart-shrinking --enable-local-file-access"
;;
"docker")
DOCKEROPTS=""
;;
*)
WKHTMLOPTS="-V margin-top=1in -V margin-left=1in -V margin-right=1in -V margin-bottom=1in"
;;
esac
# other stuff
ICPSRMSG="Details in the full report, which you will receive via ScholarOne shortly. Please provide your response to the items listed above via the openICPSR Project Communication log, specifying AEAREP-xxx. Other items in the report may need to be addressed via ScholarOne."
PANDOCOPTS="--fail-if-warnings -s"
template_app="template/REPLICATION_appendix.md"
appendix="generated/REPLICATION_appendix.md"
echo "$0 version $version"
# validating inputs
if [[ -z $1 ]]
then
echo "Please add issue number"
exit 2
fi
num=$1
shift
case $1 in
a*|approve)
preapprove="Approved. Ready to submit."
decision=approve
shift
;;
p*|pre-approve)
preapprove="Preapproved. Ready for approval."
decision=pre-approve
shift
;;
*)
echo "Please define approval status: [a]pproved or [p]reapproved"
exit 2
;;
esac
nopdf=0
if [[ "$1" == "nopdf" ]]
then
nopdf=1
shift
fi
extramsg=$*
exit_on_error() {
exit_code=$1
exit_message=${@:2}
if [ $exit_code -ne 0 ]; then
>&2 echo "${exit_message}, exit code ${exit_code}."
exit $exit_code
fi
}
set -o history -o histexpand
case $os in
Linux)
pythonbin=$(which python3.12)
[[ -f $pythonbin ]] || pythonbin=$(which python3)
[[ -f $pythonbin ]] || pythonbin=$(which python)
[[ -f $pythonbin ]] || apperror=1
pandoc=$(which pandoc)
[[ -f $pandoc ]] || apperror=1
if [[ "$pdfengine" == "" ]]
then
wkhtmltopdf=$(which wkhtmltopdf)
[[ -f $wkhtmltopdf ]] || apperror=1
elif [[ "$pdfengine" == "docker" ]]
then
[[ -f $dockerbin ]] || apperror=1
fi
export QT_STYLE_OVERRIDE=fusion
# get the CSS
if [[ -f $(dirname $0)/$CSSLOCAL ]]
then
cp $(dirname $0)/$CSSLOCAL $CSSLOCAL
else
curl $CSSURL > $CSSLOCAL
fi
# get the logo
if [[ -f $(dirname $0)/$LOGOLOCAL ]]
then
cp $(dirname $0)/$LOGOLOCAL $LOGOLOCAL
fi
;;
Darwin)
pythonbin=$(which python)
[[ -f $pythonbin ]] || apperror=1
# for MacOS, might want to install Rstudio (comes with pandoc) and replace the line above with the outcome of
# find /Applications -name pandoc -type f
pandoc=/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc
# later versions have it bundled in the quarto directory
[[ ! -f $pandoc ]] && pandoc=/Applications/RStudio.app/Contents/MacOS/quarto/bin/pandoc
[[ ! -f $pandoc ]] && pandoc=/Applications/RStudio.app/Contents/MacOS/quarto/bin/tools/pandoc
[[ ! -f $pandoc ]] && pandoc=/Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/pandoc
# let's see if its there
if [[ ! -f $pandoc ]]
then
echo "We suggest using pandoc from the RStudio install. Searching for a different one..."
pandoc=$(find /Applications -name pandoc -type f)
fi
echo "Found pandoc at $pandoc"
# get the CSS
if [[ -f $(dirname $0)/$CSSLOCAL ]]
then
cp $(dirname $0)/$CSSLOCAL $CSSLOCAL
else
curl $CSSURL > $CSSLOCAL
fi
# get the logo
if [[ -f $(dirname $0)/$LOGOLOCAL ]]
then
cp $(dirname $0)/$LOGOLOCAL $LOGOLOCAL
fi
;;
*)
echo "Please review the script to define your OS"
apperror=1
;;
esac
# update the CSS
if [[ -f $CSSLOCAL ]]
then
case $pdfengine in
"")
WKHTMLOPTS="$WKHTMLOPTS --user-style-sheet $CSSLOCAL"
;;
"docker")
#
PANDOCOPTS="$PANDOCOPTS --css $CSSLOCAL"
;;
*)
WKHTMLOPTS="$WKHTMLOPTS --css $CSSLOCAL"
;;
esac
fi
# other stuff
if [[ "$apperror" == "1" ]]
then
case $pdfengine in
"")
echo "We need pandoc and wkhtmltopdf"
echo "One or the other not found"
;;
"docker")
echo "We need pandoc and docker"
echo "One or the other not found"
;;
*)
echo "We need pandoc and wkhtmltopdf"
echo "One or the other not found"
;;
esac
case $os in
Darwin)
echo "Install Rstudio to get pandoc"
if [[ "$pdfengine" == "" ]]
then
echo "Try: brew cask install wkhtmltopdf"
elif [[ "$pdfengine" == "docker" ]]
then
echo "Try: brew install docker"
fi
;;
*)
echo "Please install"
;;
esac
[[ "$nopdf" == "1" ]] || exit_on_error 2 "Required dependencies missing"
fi
commitmsg="AEAREP-$num #comment $preapprove $extramsg"
## Test if we are where we think we should be
if [[ ! -d ".git" ]]
then
exit_on_error 2 Not in right directory
fi
if [[ ! -f "REPLICATION.md" ]]
then
exit_on_error 2 Missing REPLICATION.md -required-
fi
# Only add checkboxes to lines with '-' that also contain 'REQUIRED' or 'SUGGESTED' and are not already checkboxes
if [[ -f "REPLICATION.md" ]]; then
sed -i.bak -E '/^- *\[ \]/!{/^-.*(REQUIRED|SUGGESTED)/s/^(- *)/- [ ] /}' REPLICATION.md
fi
# If there is a line with "Automatically Generated Appendices", we remove it and everything after it.
tmpmain=$(mktemp)
tmpapp=$(mktemp)
cat REPLICATION.md > $tmpmain
if grep -q "Automatically Generated Appendices" $tmpmain
then
sed '/Automatically Generated Appendices/,$d' $tmpmain > $tmpapp
else
cp $tmpmain $tmpapp
fi
# Fill in the appendix
python3 tools/replace_placeholders.py --infile ${template_app} --indir "generated" --outfile $appendix
git add $appendix
# Append the generated appendix to the base file
echo "" >> $tmpapp
cat $tmpapp $appendix > REPLICATION.md
# Query JIRA API for DOI information and inject it into REPLICATION.md
if [[ -f "tools/jira_get_info.py" ]]
then
echo "Querying JIRA for DOI information..."
doi_info=$($pythonbin tools/jira_get_info.py aearep-$num doi 2>/dev/null)
if [[ -n "$doi_info" && "$doi_info" != "" ]]
then
echo "Found DOI: $doi_info"
# Check if the DOI line already exists and remove it
sed -i '/^\s*- \[FYI\] \[EDITORIAL STAFF\] The predicted DOI of the replication package is /d' REPLICATION.md
# Find the line with "Action Items (manuscript)" and insert blank line + DOI line after it
sed -i "/### Action Items (manuscript)/a\\
\\
- [FYI] [EDITORIAL STAFF] The predicted DOI of the replication package is $doi_info" REPLICATION.md
echo "DOI information added to REPLICATION.md"
else
echo "No DOI information found in JIRA"
fi
else
echo "jira_get_info.py not found in tools/ subdirectory, skipping DOI injection"
sleep 1
fi
# Query JIRA API for openICPSR project URL and inject it into REPLICATION.md
if [[ -f "tools/jira_get_info.py" ]]
then
echo "Querying JIRA for openICPSR URL..."
openicpsr_url=$($pythonbin tools/jira_get_info.py aearep-$num openicpsrurl 2>/dev/null)
if [[ -n "$openicpsr_url" && "$openicpsr_url" != "" ]]
then
echo "Found openICPSR URL: $openicpsr_url"
# Try to replace the placeholder URL with the actual URL
# The line pattern to match (approximately):
# > [REQUIRED] When returning proofs, confirm that all requested changes to the replication package, as outlined in the "Actions Items (openICPSR)" section of the Data Editor report, have been completed. The URL to access the deposit is <https://www.openicpsr.org/openicpsr/workspace?goToPath=/openicpsr/xxxxx>.
# Search for the template text in the 50 lines after "### Action Items (manuscript)"
if sed -n '/### Action Items (manuscript)/,+50p' REPLICATION.md | grep -q "confirm that all requested changes to the replication package.*The URL to access the deposit is"
then
# Replace existing placeholder URL - use more specific pattern to avoid spurious matches
sed -i "s|\(confirm that all requested changes to the replication package.*The URL to access the deposit is <\)https://www.openicpsr.org/openicpsr/workspace?goToPath=/openicpsr/[^>]*|\1$openicpsr_url|g" REPLICATION.md
echo "openICPSR URL updated in REPLICATION.md"
else
# Template line not found, inject full text before "### Action Items (openICPSR)"
sed -i "/### Action Items (openICPSR)/i\\
> [REQUIRED] When returning proofs, confirm that all requested changes to the replication package, as outlined in the \"Actions Items (openICPSR)\" section of the Data Editor report, have been completed. The URL to access the deposit is <$openicpsr_url>.\\
\\
" REPLICATION.md
echo "openICPSR URL line injected into REPLICATION.md"
fi
else
echo "No openICPSR URL found in JIRA"
fi
else
echo "jira_get_info.py not found in tools/ subdirectory, skipping openICPSR URL injection"
sleep 1
fi
# Query JIRA API for DCAF_Access_Restrictions_V2 and inject private data notice if applicable
if [[ -f "tools/jira_get_info.py" ]]
then
echo "Querying JIRA for DCAF private data restriction..."
dcaf_private=$($pythonbin tools/jira_get_info.py aearep-$num dcaf_private 2>/dev/null)
if [[ -n "$dcaf_private" && "$dcaf_private" == "yes" ]]
then
echo "Found DCAF private data restriction"
# Check if the notice already exists to avoid duplication
if ! grep -q "The article uses restricted-access data, which the authors provided privately not-for-publication" REPLICATION.md
then
# Find the line starting with "In assessing compliance with our" and insert notice above it
if grep -q "^In assessing compliance with our" REPLICATION.md
then
sed -i "/^In assessing compliance with our/i\\
> The article uses restricted-access data, which the authors provided privately not-for-publication. We will be in touch separately to confirm deletion of the data.\\
\\
" REPLICATION.md
echo "Private data restriction notice added to REPLICATION.md"
else
echo "WARNING: Could not find 'In assessing compliance with our' line in REPLICATION.md"
fi
else
echo "Private data restriction notice already exists in REPLICATION.md"
fi
else
echo "No DCAF private data restriction found in JIRA"
fi
else
echo "jira_get_info.py not found in tools/ subdirectory, skipping DCAF private data check"
sleep 1
fi
# Update timestamp directly in REPLICATION.md
timestamp=$(date '+%B %d, %Y %H:%M %Z')
# Remove any existing timestamp lines
sed -i '/^\*Report last created on.*\*$/d' REPLICATION.md
# Add new timestamp before "Some useful links:" line
sed -i "/^> Some useful links:/i\\
*Report last created on $timestamp*\\
\\
" REPLICATION.md
# convert to PDF, just in case
# requires: wkhtmltopdf and pandoc
if [[ "$nopdf" == "0" ]]
then
case $pdfengine in
"")
echo "Using pandoc to generate HTML, then wkhtmltopdf to generate PDF"
outfile=REPLICATION.html
PANDOCXTRA=""
;;
"docker")
echo "Using pandoc to generate HTML, then Docker to generate PDF"
outfile=REPLICATION.html
PANDOCXTRA=""
;;
*)
echo "Using pandoc and wkhtmltopdf to generate PDF"
outfile=REPLICATION.pdf
PANDOCXTRA="$WKHTMLOPTS"
;;
esac
$pandoc $PANDOCOPTS REPLICATION.md -f gfm -t html5 -o $outfile --metadata pagetitle="Report for AEAREP-$num" $PANDOCXTRA
exit_on_error $? "Pandoc failed to generate $outfile"
# now generate the PDF
if [[ "$pdfengine" == "" ]]
then
$wkhtmltopdf $WKHTMLOPTS $outfile REPLICATION.pdf
exit_on_error $? "wkhtmltopdf failed to generate REPLICATION.pdf"
elif [[ "$pdfengine" == "docker" ]]
then
echo "Preparing for Docker execution..."
echo "Pulling latest Docker image..."
$dockerbin pull $DOCKERIMG || echo "Failed to pull Docker image $DOCKERIMG"
# Set directory permissions to allow Docker (others) to access
chmod o+rwx .
chmod o+r .[a-z]*css
chmod -R o+rX *
# Remove any pre-existing REPLICATION.pdf
rm -f REPLICATION.pdf
$dockerbin run -it --rm --user 10042:999 -v $(pwd):/home/pptruser/project -w /home/pptruser/project $DOCKERIMG
exit_on_error $? "Docker failed to generate REPLICATION.pdf"
fi
else
echo "Skipping PDF generation as requested"
fi
rm $CSSLOCAL
[[ -f $LOGOLOCAL ]] && rm $LOGOLOCAL
[[ -f REPLICATION.html ]] && rm REPLICATION.html
# No need to restore from backup - timestamp is now permanent in REPLICATION.md
echo "-------- Current git status -----------"
git status
echo "---------------------------------------"
git add REPLICATION.md
git add REPLICATION.pdf
if [[ -f "for openICPSR.md" ]]
then
# check for standard language in ICPSR file
grep ScholarOne "for openICPSR.md" 1>/dev/null
icpsr_check=$?
case $icpsr_check in
0)
# tag is already in
echo "ICPSR file is ready for addition"
;;
*)
# tag needs to be added
echo "" >> "for openICPSR.md"
echo "" >> "for openICPSR.md"
echo "$ICPSRMSG" | sed "s/xxx/$num/" >> "for openICPSR.md"
echo "---------------------------------------"
cat "for openICPSR.md"
echo "---------------------------------------"
echo "::: Does this look fine?"
read
;;
esac
git add "for openICPSR.md"
commitmsg="$commitmsg with notes for openICPSR"
fi
echo "-------- Updated git status -----------"
git status
echo "::: Ready to commit/ push? "
echo "::: Msg:"
echo " $commitmsg"
read
git commit -m "$commitmsg"
git push
# Now modify the Jira issue accordingly. Ask first, and then call jira-approval-manager
echo "::: Ready to update Jira issue AEAREP-$num ? (Ctrl-C to abort)"
read
# check first if the script is in the path
if ! command -v jira-approval-manager &> /dev/null
then
echo "jira-approval-manager could not be found in PATH. Not modifying Jira issue."
echo "You may want to call aeaopen ."
exit 0
fi
set -evx
jira-approval-manager aearep-$num $decision 0