forked from pactflow/example-provider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
114 lines (90 loc) · 3.37 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
PACTICIPANT := "pactflow-example-provider"
WEBHOOK_UUID := "c76b601e-d66a-4eb1-88a4-6ebc50c0df8b"
TRIGGER_PROVIDER_BUILD_URL := "https://api.travis-ci.com/repo/pactflow%2Fexample-provider/requests"
PACT_CLI="docker run --rm -v ${PWD}:${PWD} -e PACT_BROKER_BASE_URL -e PACT_BROKER_TOKEN pactfoundation/pact-cli:latest"
# Only deploy from master
ifeq ($(TRAVIS_BRANCH),master)
DEPLOY_TARGET=deploy
else
DEPLOY_TARGET=no_deploy
endif
all: test
## ====================
## CI tasks
## ====================
ci: test can_i_deploy $(DEPLOY_TARGET)
# Run the ci target from a developer machine with the environment variables
# set as if it was on Travis CI.
# Use this for quick feedback when playing around with your workflows.
fake_ci: .env
CI=true \
TRAVIS_COMMIT=`git rev-parse --short HEAD`+`date +%s` \
TRAVIS_BRANCH=`git rev-parse --abbrev-ref HEAD` \
PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true \
make ci
ci_webhook: .env
npm run test:pact
fake_ci_webhook:
CI=true \
TRAVIS_COMMIT=`git rev-parse --short HEAD`+`date +%s` \
TRAVIS_BRANCH=`git rev-parse --abbrev-ref HEAD` \
PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true \
make ci_webhook
## =====================
## Build/test tasks
## =====================
test: .env
npm run test
## =====================
## Deploy tasks
## =====================
deploy: deploy_app tag_as_prod
no_deploy:
@echo "Not deploying as not on master branch"
can_i_deploy: .env
@"${PACT_CLI}" broker can-i-deploy --pacticipant ${PACTICIPANT} --version ${TRAVIS_COMMIT} --to prod
deploy_app:
@echo "Deploying to prod"
tag_as_prod:
@"${PACT_CLI}" broker create-version-tag \
--pacticipant ${PACTICIPANT} \
--version ${TRAVIS_COMMIT} \
--tag prod
## =====================
## Pactflow set up tasks
## =====================
# export the TRAVIS_TOKEN environment variable before running this
# You can get your token from the Settings tab of https://travis-ci.com/account/preferences
create_travis_token_secret:
@curl -v -X POST ${PACT_BROKER_BASE_URL}/secrets \
-H "Authorization: Bearer ${PACT_BROKER_TOKEN}" \
-H "Content-Type: application/json" \
-H "Accept: application/hal+json" \
-d "{\"name\":\"travisToken\",\"description\":\"Travis CI Provider Build Token\",\"value\":\"${TRAVIS_TOKEN}\"}"
# NOTE: the travis token secret must be created (either through the UI or using the
# `create_travis_token_secret` target) before the webhook is invoked.
create_or_update_travis_webhook:
@"${PACT_CLI}" \
broker create-or-update-webhook \
"${TRIGGER_PROVIDER_BUILD_URL}" \
--header "Content-Type: application/json" "Accept: application/json" "Travis-API-Version: 3" 'Authorization: token $${user.travisToken}' \
--request POST \
--data @${PWD}/pactflow/travis-ci-webhook.json \
--uuid ${WEBHOOK_UUID} \
--provider ${PACTICIPANT} \
--contract-content-changed \
--description "Travis CI webhook for ${PACTICIPANT}"
test_travis_webhook:
@"${PACT_CLI}" broker test-webhook --uuid ${WEBHOOK_UUID}
## ======================
## Travis CI set up tasks
## ======================
travis_login:
@docker run --rm -v ${HOME}/.travis:/root/.travis -it lirantal/travis-cli login --pro
travis_encrypt_pact_broker_token:
@docker run --rm -v ${HOME}/.travis:/root/.travis -v ${PWD}:${PWD} --workdir ${PWD} lirantal/travis-cli encrypt --pro PACT_BROKER_TOKEN="${PACT_BROKER_TOKEN}"
## ======================
## Misc
## ======================
.env:
touch .env