forked from distributhor/workflow-webhook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
31 lines (23 loc) · 926 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
#!/bin/bash
set -e
if [ -z "$webhook_url" ]; then
echo "No webhook_url configured"
exit 1
fi
if [ -z "$webhook_secret" ]; then
echo "No webhook_secret configured"
exit 1
fi
CONTENT_TYPE="application/json"
GITHUB_EVENT_NAME=push
WEBHOOK_DATA="{\"repository\":\"$GITHUB_REPOSITORY\",\"commit\":\"$GITHUB_SHA\",\"ref\":\"$GITHUB_REF\",\"head\":\"$GITHUB_HEAD_REF\",\"workflow\":\"$GITHUB_WORKFLOW\",\"sender\": {\"id\": 12345}}"
WEBHOOK_SIGNATURE=$(echo -n "$WEBHOOK_DATA" | openssl sha1 -hmac "$webhook_secret" -binary | xxd -p)
WEBHOOK_ENDPOINT=$webhook_url
echo "WEBHOOK_DATA: $WEBHOOK_DATA"
curl -k -v --fail \
-H "Content-Type: $CONTENT_TYPE" \
-H "User-Agent: User-Agent: GitHub-Hookshot/760256b" \
-H "X-Hub-Signature: sha1=$WEBHOOK_SIGNATURE" \
-H "X-GitHub-Delivery: $GITHUB_RUN_NUMBER" \
-H "X-GitHub-Event: $GITHUB_EVENT_NAME" \
--data "$WEBHOOK_DATA" $WEBHOOK_ENDPOINT