-
Notifications
You must be signed in to change notification settings - Fork 9
/
entrypoint.sh
executable file
·57 lines (45 loc) · 1.36 KB
/
entrypoint.sh
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
#!/usr/bin/env bash
set -e
echo "Compiling $1"
tectonic $1
PUSH_OUTPUT=$(echo "$2" | tr '[:upper:]' '[:lower:]')
if [[ $PUSH_OUTPUT != "yes" ]]; then # Don't push PDF
exit 0;
fi
OUTPUT_PDF="${1%.*}.pdf"
if [[ ${OUTPUT_PDF:0:1} == "/" ]]; then
OUTPUT_PDF=${OUTPUT_PDF:1}
fi
FILE_NAME=$(basename $OUTPUT_PDF)
DIR=$(dirname $OUTPUT_PDF)
STATUSCODE=$(curl --silent --output resp.json --write-out "%{http_code}" -X GET -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/${GITHUB_REPOSITORY}/contents/$DIR)
if [ $((STATUSCODE/100)) -ne 2 ]; then
echo "Github's API returned $STATUSCODE"
cat resp.json
exit 22;
fi
SHA=""
for i in $(jq -c '.[]' resp.json);
do
NAME=$(echo $i | jq -r .name)
if [ "$NAME" = "$FILE_NAME" ]; then
SHA=$(echo $i | jq -r .sha)
break
fi
done
echo '{
"message": "'"update $OUTPUT_PDF"'",
"committer": {
"name": "Tectonic Action",
"email": "[email protected]"
},
"content": "'"$(base64 -w 0 $OUTPUT_PDF)"'",
"sha": "'$SHA'"
}' > payload.json
STATUSCODE=$(curl --silent --output /dev/stderr --write-out "%{http_code}" \
-i -X PUT -H "Authorization: token $GITHUB_TOKEN" -d @payload.json \
https://api.github.com/repos/${GITHUB_REPOSITORY}/contents/${OUTPUT_PDF})
if [ $((STATUSCODE/100)) -ne 2 ]; then
echo "Github's API returned $STATUSCODE"
exit 22;
fi