Skip to content

Commit

Permalink
reverted to bash to speed things up
Browse files Browse the repository at this point in the history
  • Loading branch information
tsickert committed Feb 25, 2021
1 parent 891a826 commit f41d3df
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 46 deletions.
9 changes: 4 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM python:3.7
FROM ubuntu

ADD main.py /main.py
ADD requirements.txt /requirements.txt
RUN apt update && apt upgrade -y && apt install -y curl

RUN pip install -r /requirements.txt
ADD webhook.sh /webhook.sh

ENTRYPOINT [ "python", "/main.py" ]
ENTRYPOINT [ "/webhook.sh" ]
12 changes: 6 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inputs:
webhook-url:
description: 'Webhook URL from discord. See: https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks for details'
required: true
content: # id of input
content:
description: 'Message that is sent via the webhook.'
required: true
username:
Expand All @@ -24,13 +24,13 @@ runs:
using: 'docker'
image: 'Dockerfile'
args:
- --url
- -w
- ${{ inputs.webhook-url }}
- --content
- -c
- ${{ inputs.content }}
- --username
- -u
- ${{ inputs.username }}
- --avatar-url
- -a
- ${{ inputs.avatar-url }}
- --raw-data
- -d
- ${{ inputs.raw-data }}
34 changes: 0 additions & 34 deletions main.py

This file was deleted.

1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

47 changes: 47 additions & 0 deletions webhook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

content=''
avatar_url=''
username=''
raw_data=''

print_usage() {
printf "Usage: webhook -w <webhook_url> -a <avatar_url> -u <username> -c <content> -d <raw_data>\n"
}

while getopts 'a:c:d:u:w:' flag; do
case "${flag}" in
a) avatar_url="${OPTARG}" ;;
c) content="${OPTARG}" ;;
d) raw_data="${OPTARG}" ;;
u) username="${OPTARG}" ;;
w) webhook="${OPTARG}" ;;
*) print_usage
exit 1 ;;
esac
done

generate_post_data()
{
cat <<EOF
{
"content": "$content",
"username": "$username",
"avatar_url": "$avatar_url"
}
EOF
}

if [ -z "$raw_data" ]
then
echo sending simple body
curl --location --request POST "$webhook" \
--header 'Content-Type: application/json' \
--data-raw "$(generate_post_data)"
else
echo sending raw data
curl --location --request POST "$webhook" \
--header 'Content-Type: application/json' \
-d "@$raw_data"
fi

0 comments on commit f41d3df

Please sign in to comment.