Improvements and changes

Improved build time
Better curl usage
Allow unsigned SSL certificates
Additional GitHub environment header
This commit is contained in:
distributhor
2020-10-04 16:36:57 +01:00
parent 9a28a22908
commit 16b7ccd3f1
3 changed files with 40 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
FROM ubuntu:bionic
FROM alpine
LABEL "name"="bash"
LABEL "repository"="https://github.com/distributhor/workflow-webhook"
@@ -9,7 +9,7 @@ LABEL com.github.actions.description="An action that will call a webhook from yo
LABEL com.github.actions.icon="upload-cloud"
LABEL com.github.actions.color="gray-dark"
RUN apt-get update && apt-get install -y curl openssl xxd jq
RUN apk add --no-cache bash curl openssl xxd jq
COPY LICENSE README.md /
COPY entrypoint.sh /entrypoint.sh

View File

@@ -11,12 +11,25 @@ field named `X-Hub-Signature`. Therefore any existing Github webhook signature
validation will continue to work. For more information on how to valiate the signature,
see <https://developer.github.com/webhooks/securing>.
By default, the values of the following workflow environment variables are sent in the
payload: `GITHUB_REPOSITORY`, `GITHUB_REF`, `GITHUB_SHA`, `GITHUB_EVENT_NAME` and
`GITHUB_WORKFLOW`. For more information on what is contained in these variables, see
By default, the values of the following GitHub workflow environment variables are sent in the
payload: `GITHUB_REPOSITORY`, `GITHUB_REF`, `GITHUB_HEAD_REF`, `GITHUB_SHA`, `GITHUB_EVENT_NAME`
and `GITHUB_WORKFLOW`. For more information on what is contained in these variables, see
<https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables>.
Additional (custom) data can be added to the payload as well.
These values map to the payload as follows:
```json
{
"repository": "GITHUB_REPOSITORY",
"ref": "GITHUB_REF",
"head": "GITHUB_HEAD_REF",
"commit": "GITHUB_SHA",
"event": "GITHUB_EVENT_NAME",
"workflow": "GITHUB_WORKFLOW"
}
```
Additional (custom) data can be added to the payload as well (see further down).
## Usage
@@ -39,6 +52,7 @@ Will deliver a payload with the following properties:
{
"repository": "owner/project",
"ref": "refs/heads/master",
"head": "",
"commit": "a636b6f0861bbee98039bf3df66ee13d8fbc9c74",
"event": "push",
"workflow": "Build and deploy"
@@ -64,6 +78,7 @@ and now look like:
{
"repository": "owner/project",
"ref": "refs/heads/master",
"head": "",
"commit": "a636b6f0861bbee98039bf3df66ee13d8fbc9c74",
"event": "push",
"workflow": "Build and deploy",

View File

@@ -12,7 +12,7 @@ if [ -z "$webhook_secret" ]; then
exit 1
fi
DATA_JSON="\"repository\":\"$GITHUB_REPOSITORY\",\"ref\":\"$GITHUB_REF\",\"commit\":\"$GITHUB_SHA\",\"trigger\":\"$GITHUB_EVENT_NAME\",\"workflow\":\"$GITHUB_WORKFLOW\""
DATA_JSON="\"repository\":\"$GITHUB_REPOSITORY\",\"ref\":\"$GITHUB_REF\",\"head\":\"$GITHUB_HEAD_REF\",\"commit\":\"$GITHUB_SHA\",\"event\":\"$GITHUB_EVENT_NAME\",\"workflow\":\"$GITHUB_WORKFLOW\""
if [ -n "$data" ]; then
COMPACT_JSON=$(echo -n "$data" | jq -c '')
@@ -30,11 +30,24 @@ if [ -n "$webhook_auth" ]; then
WEBHOOK_ENDPOINT="-u $webhook_auth $webhook_url"
fi
curl -X POST \
-H "content-type: application/json" \
# Note:
# "curl --trace-ascii /dev/stdout" is an alternative to "curl -v", and includes
# the posted data in the output. However, it can't do so for multipart/form-data
curl -k -v \
-H "Content-Type: application/json" \
-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" \
-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
# -D - $WEBHOOK_ENDPOINT --data-urlencode @"$GITHUB_EVENT_PATH"
# wget -q --server-response --timeout=2000 -O - \
# --header="Content-Type: application/json" \
# --header="User-Agent: User-Agent: GitHub-Hookshot/760256b" \
# --header="X-Hub-Signature: sha1=$WEBHOOK_SIGNATURE" \
# --header="X-GitHub-Delivery: $GITHUB_RUN_NUMBER" \
# --header="X-GitHub-Event: $GITHUB_EVENT_NAME" \
# --post-data "$WEBHOOK_DATA" $webhook_url
# # --http-user user --http-password