|
1 | 1 | PACTICIPANT := "pactflow-example-consumer"
|
| 2 | +GITHUB_WEBHOOK_UUID := "04510dc1-7f0a-4ed2-997d-114bfa86f8ad" |
2 | 3 |
|
3 |
| -all: test deploy |
| 4 | +all: create_or_update_github_webhook test deploy |
4 | 5 |
|
5 | 6 | test:
|
6 | 7 | npm run test:pact
|
@@ -33,3 +34,36 @@ tag_as_prod:
|
33 | 34 | --tag prod
|
34 | 35 |
|
35 | 36 | deploy: can_i_deploy deploy_app tag_as_prod
|
| 37 | + |
| 38 | +# This webhook will update the Github commit status for this commit |
| 39 | +# so that any PRs will get a status that shows what the status of |
| 40 | +# the pact is. |
| 41 | +create_or_update_github_webhook: |
| 42 | + docker run --rm \ |
| 43 | + -e PACT_BROKER_BASE_URL \ |
| 44 | + -e PACT_BROKER_USERNAME \ |
| 45 | + -e PACT_BROKER_PASSWORD \ |
| 46 | + -v ${PWD}:${PWD} \ |
| 47 | + pactfoundation/pact-cli:latest \ |
| 48 | + broker create-or-update-webhook \ |
| 49 | + 'https://api.github.com/repos/pactflow/example-consumer/statuses/$${pactbroker.consumerVersionNumber}' \ |
| 50 | + --header 'Content-Type: application/json' 'Accept: application/vnd.github.v3+json' 'Authorization: token $${user.githubCommitStatusToken}' \ |
| 51 | + --request POST \ |
| 52 | + --data @${PWD}/pactflow/github-commit-status-webhook.json \ |
| 53 | + --uuid ${GITHUB_WEBHOOK_UUID} \ |
| 54 | + --consumer ${PACTICIPANT} \ |
| 55 | + --contract-published \ |
| 56 | + --provider-verification-published \ |
| 57 | + --description "Github commit status webhook for ${PACTICIPANT}" |
| 58 | + |
| 59 | +test_github_webhook: |
| 60 | + curl -v -X POST ${PACT_BROKER_BASE_URL}/webhooks/${GITHUB_WEBHOOK_UUID}/execute -u ${PACT_BROKER_USERNAME}:${PACT_BROKER_PASSWORD} |
| 61 | + |
| 62 | +# This should be called once before creating the webhook |
| 63 | +# with the environment variable GITHUB_TOKEN set |
| 64 | +create_github_token_secret: |
| 65 | + curl -v -X POST ${PACT_BROKER_BASE_URL}/secrets \ |
| 66 | + -u ${PACT_BROKER_USERNAME}:${PACT_BROKER_PASSWORD} \ |
| 67 | + -H "Content-Type: application/json" \ |
| 68 | + -H "Accept: application/hal+json" \ |
| 69 | + -d "{\"name\":\"githubCommitStatusToken\",\"description\":\"Github token for updating commit statuses\",\"value\":\"${GITHUB_TOKEN}\"}" |
0 commit comments