From de0f0dd97daba7aa19d1d461175a09c26f053f7d Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Mon, 14 Oct 2024 19:49:37 +0100 Subject: [PATCH] ci: test --- .github/workflows/test.yml | 12 +++++++--- broker-webhook/broker-create-body.json | 2 +- broker-webhook/create_webhook.sh | 31 +++++++++++++++++++++++--- docker-compose.yaml | 2 +- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 106d8cb..2a65667 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,8 @@ name: Build +env: + PACT_BROKER_WEBHOOK_HOST_WHITELIST: localhost + on: push: workflow_dispatch: @@ -14,8 +17,11 @@ jobs: node-version: '20' - run: docker compose up -d - run: npm i - - run: npm run start --prefix broker-webhook & + - run: nohup npm run start --prefix broker-webhook > out.log 2>&1 & - run: npm run create-webhook --prefix broker-webhook - run: npm test --prefix consumer - - run: npm run pact:publish --prefix consumer - - run: sleep 30 \ No newline at end of file + - run: | + npm run pact:publish --prefix consumer > publish.out + curl "$(cat publish.out | grep "View logs at" | sed -E 's/.*View logs at \x1b\[35m(.*)\x1b\[0m/\1/')" --user pact_workshop:pact_workshop -H "Accept: */*" + - run: sleep 15 + - run: cat out.log diff --git a/broker-webhook/broker-create-body.json b/broker-webhook/broker-create-body.json index 5b91aad..aa390dc 100644 --- a/broker-webhook/broker-create-body.json +++ b/broker-webhook/broker-create-body.json @@ -6,7 +6,7 @@ ], "request": { "method": "POST", - "url": "http://host.docker.internal:9090", + "url": "http://localhost:9090", "headers": { "Content-Type": "application/json" }, diff --git a/broker-webhook/create_webhook.sh b/broker-webhook/create_webhook.sh index 574e2b7..41462db 100755 --- a/broker-webhook/create_webhook.sh +++ b/broker-webhook/create_webhook.sh @@ -1,3 +1,28 @@ -curl http://localhost:8000/webhooks \ - -X POST --user pact_workshop:pact_workshop \ - -H "Content-Type: application/json" -d @broker-create-body.json -v \ No newline at end of file +#!/bin/bash +set -e + +json_payload='{ + "events": [ + { + "name": "contract_content_changed" + } + ], + "request": { + "method": "POST", + "url": "'http://"${PACT_BROKER_WEBHOOK_HOST_WHITELIST:-host.docker.internal}":9090'", + "headers": { + "Content-Type": "application/json" + }, + "body": { + "state": "${pactbroker.githubVerificationStatus}", + "description": "Pact Verification Tests ${pactbroker.providerVersionTags}", + "context": "${pactbroker.providerName}", + "target_url": "${pactbroker.verificationResultUrl}" + } + } + }' + +echo $json_payload +curl http://localhost:8000/webhooks/204430af-f8c8-4feb-8135-f027df8ecf34 \ + -X PUT --user pact_workshop:pact_workshop \ + -H "Content-Type: application/json" -d "${json_payload}" -v \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index a46225c..6ad6656 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -27,4 +27,4 @@ services: PACT_BROKER_DATABASE_CONNECT_MAX_RETRIES: "10" PACT_BROKER_PUBLIC_HEARTBEAT: "true" PACT_BROKER_WEBHOOK_SCHEME_WHITELIST: http - PACT_BROKER_WEBHOOK_HOST_WHITELIST: host.docker.internal \ No newline at end of file + PACT_BROKER_WEBHOOK_HOST_WHITELIST: ${PACT_BROKER_WEBHOOK_HOST_WHITELIST:-host.docker.internal} \ No newline at end of file