mirror of
https://github.com/jon4hz/workflow-webhook.git
synced 2025-12-19 23:56:02 +01:00
Initial commit
This commit is contained in:
18
Dockerfile
Normal file
18
Dockerfile
Normal file
@@ -0,0 +1,18 @@
|
||||
FROM ubuntu:bionic
|
||||
|
||||
LABEL "name"="bash"
|
||||
LABEL "repository"="https://github.com/distributhor/workflow-webhook"
|
||||
LABEL "maintainer"="distributhor"
|
||||
LABEL "version"="1.0.0"
|
||||
|
||||
LABEL com.github.actions.name="Workflow Webhook"
|
||||
LABEL com.github.actions.description="An action that will call a webhook from your Github workdlow"
|
||||
LABEL com.github.actions.icon="upload-cloud"
|
||||
LABEL com.github.actions.color="gray-dark"
|
||||
|
||||
COPY LICENSE README.md jq /
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 distributhor
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
45
entrypoint.sh
Normal file
45
entrypoint.sh
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eu
|
||||
|
||||
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
|
||||
|
||||
if [ -n "$data_type" ] && [ "$data_type" == "csv" ]; then
|
||||
CONTENT_TYPE="text/csv"
|
||||
else
|
||||
CONTENT_TYPE="application/json"
|
||||
fi
|
||||
|
||||
if [ "$CONTENT_TYPE" == "text/csv" ]; then
|
||||
|
||||
DATA_CSV="\"$GITHUB_REPOSITORY\",\"$GITHUB_REF\",\"$GITHUB_SHA\",\"$GITHUB_EVENT_NAME\",\"$GITHUB_WORKFLOW\""
|
||||
if [ -n "$data" ]; then
|
||||
WEBHOOK_DATA="$DATA_CSV,$data"
|
||||
else
|
||||
WEBHOOK_DATA="$DATA_CSV"
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
DATA_JSON="\"repository\":\"$GITHUB_REPOSITORY\",\"ref\":\"$GITHUB_REF\",\"commit\":\"$GITHUB_SHA\",\"trigger\":\"$GITHUB_EVENT_NAME\",\"workflow\":\"$GITHUB_WORKFLOW\""
|
||||
if [ -n "$data" ]; then
|
||||
COMPACT_JSON=$(echo -n "$data" | ./jq -c '')
|
||||
WEBHOOK_DATA="{$DATA_JSON,\"data\":$COMPACT_JSON}"
|
||||
else
|
||||
WEBHOOK_DATA="{$DATA_JSON}"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
WEBHOOK_DATA="{\"repository\":\"$GITHUB_REPOSITORY\",\"ref\":\"$GITHUB_REF\",\"commit\":\"$GITHUB_SHA\",\"trigger\":\"$GITHUB_EVENT_NAME\",\"workflow\":\"$GITHUB_WORKFLOW\"}"
|
||||
WEBHOOK_SIGNATURE=$(echo -n "$WEBHOOK_DATA" | openssl sha1 -hmac "$webhook_secret" -binary | xxd -p)
|
||||
|
||||
curl -X POST -H "content-type: $CONTENT_TYPE" -H "x-hub-signature: sha1=$WEBHOOK_SIGNATURE" -H "x-github-event: $GITHUB_EVENT_NAME" --data "$WEBHOOK_DATA" $webhook_url
|
||||
Reference in New Issue
Block a user