-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathentrypoint.sh
executable file
·32 lines (24 loc) · 992 Bytes
/
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
#!/bin/bash
# $1 :: ${{ inputs.auth }}
# $2 :: ${{ inputs.gist_url }}
# $3 :: ${{ inputs.gist_title }}
# $4 :: ${{ inputs.gist_description }}
# $5 :: ${{ inputs.github_file }}
Error() {
echo "$1"
exit "$2"
}
auth_token=$1
gist_api="https://api.github.com/gists/"
gist_id=$(grep -Po "\w+$" <<< "$2")
gist_endpoint=$gist_api$gist_id
title=$(echo "$3" | sed 's/\"/\\"/g')
description=$(echo "$4" | sed 's/\"/\\"/g')
[[ -r "$5" ]] || Error "The file '$5' does not exist or is not readable" 1
content=$(sed -e 's/\\/\\\\/g' -e 's/\t/\\t/g' -e 's/\"/\\"/g' -e 's/\r//g' "$5" | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g')
echo '{"description": "'"$description"'", "files": {"'"$title"'": {"content": "'"$content"'"}}}' > postContent.json || Error 'Failed to write temp json file' 2
curl -s -X PATCH \
-H "Content-Type: application/json" \
-H "Authorization: token $auth_token" \
-d @postContent.json "$gist_endpoint" \
--fail --show-error || Error 'Failed to patch gist' 3