Initial commit

This commit is contained in:
Wilhelm Krause
2020-01-02 16:19:24 +01:00
commit 7c131f6f1f
5 changed files with 86 additions and 0 deletions

18
Dockerfile Normal file
View 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
View 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.

2
README.md Normal file
View File

@@ -0,0 +1,2 @@
# workflow-webhook
Github workflow webhook action

45
entrypoint.sh Normal file
View 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

BIN
jq Executable file

Binary file not shown.