Skip to content

Commit

Permalink
Merge pull request #2 from vinay0410/fix/large-files
Browse files Browse the repository at this point in the history
fix(push): read curl payload from file
  • Loading branch information
vinay0410 committed Dec 3, 2019
2 parents 862b32c + b672e65 commit 086143d
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,50 @@
#!/bin/sh -l
#!/usr/bin/env bash

set -e
set -ex

echo "Compiling $1"
tectonic $1

OUTPUT_PDF="${1%.*}.pdf"

STATUSCODE=$(curl --silent --output /dev/stderr --write-out "%{http_code}" -i -X PUT -H "Authorization: token $GITHUB_TOKEN" -d '{
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": "tectonic-action@github.com"
},
"content": "'"$(base64 -w 0 $OUTPUT_PDF)"'",
"sha": '$(curl -X GET https://api.github.com/repos/vinay0410/webpage/contents/$OUTPUT_PDF | jq .sha)'
}' https://api.github.com/repos/vinay0410/webpage/contents/$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"
Expand Down

0 comments on commit 086143d

Please sign in to comment.