Skip to content

Commit 8d5f9d4

Browse files
committed
wip: initial implementation
1 parent 02fa398 commit 8d5f9d4

29 files changed

+867
-0
lines changed

.env

Whitespace-only changes.

.github/workflows/build.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
workflow_dispatch:
6+
7+
env:
8+
PACT_BROKER_BASE_URL: https://test.pactflow.io
9+
PACT_BROKER_HOST: test.pactflow.io
10+
PACT_BROKER_TOKEN: ${{ secrets.PACTFLOW_TOKEN_FOR_CI_CD_WORKSHOP }}
11+
PACT_BROKER_PUBLISH_VERIFICATION_RESULTS: true
12+
GIT_COMMIT: ${{ github.sha }}
13+
GITHUB_REF: ${{ github.ref }}
14+
15+
jobs:
16+
test:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: Set up JDK 11
21+
uses: actions/setup-java@v2
22+
with:
23+
distribution: 'zulu'
24+
java-version: '11'
25+
- name: Test
26+
run: GIT_BRANCH=${GITHUB_REF:11} make test
27+
28+
# Runs on branches as well, so we know the status of our PRs
29+
can-i-deploy:
30+
runs-on: ubuntu-latest
31+
needs: test
32+
steps:
33+
- uses: actions/checkout@v2
34+
- run: docker pull pactfoundation/pact-cli:latest
35+
- name: Can I deploy?
36+
run: GIT_BRANCH=${GITHUB_REF:11} make can_i_deploy
37+
38+
# Only deploy from master
39+
deploy:
40+
runs-on: ubuntu-latest
41+
needs: can-i-deploy
42+
steps:
43+
- uses: actions/checkout@v2
44+
- run: docker pull pactfoundation/pact-cli:latest
45+
- name: Deploy
46+
run: GIT_BRANCH=${GITHUB_REF:11} make deploy
47+
if: github.ref == 'refs/heads/master'
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Trigger update to partners.pactflow.io
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- '**.md'
9+
10+
jobs:
11+
run:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Trigger partners.pact.io update workflow
15+
run: |
16+
curl -X POST https://api.github.com/repos/pactflow/partners.pactflow.io/dispatches \
17+
-H 'Accept: application/vnd.github.everest-preview+json' \
18+
-H "Authorization: Bearer $GITHUB_TOKEN" \
19+
-d '{"event_type": "pactflow-example-provider-java-spring-boot-updated"}'
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GHTOKENFORTRIGGERINGPACTDOCSUPDATE }}
22+
- name: Trigger docs.pact.io update workflow
23+
run: |
24+
curl -X POST https://api.github.com/repos/pactflow/docs.pactflow.io/dispatches \
25+
-H 'Accept: application/vnd.github.everest-preview+json' \
26+
-H "Authorization: Bearer $GITHUB_TOKEN" \
27+
-d '{"event_type": "pactflow-example-provider-java-spring-boot-updated"}'
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GHTOKENFORTRIGGERINGPACTDOCSUPDATE }}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Verify changed pact
2+
3+
on:
4+
repository_dispatch:
5+
types:
6+
- pact_changed
7+
8+
env:
9+
PACT_BROKER_BASE_URL: https://test.pactflow.io
10+
PACT_BROKER_TOKEN: ${{ secrets.PACTFLOW_TOKEN_FOR_CI_CD_WORKSHOP }}
11+
PACT_BROKER_PUBLISH_VERIFICATION_RESULTS: true
12+
GIT_COMMIT: ${{ github.sha }}
13+
GITHUB_REF: ${{ github.ref }}
14+
PACT_URL: ${{ github.event.client_payload.pact_url }}
15+
16+
jobs:
17+
verify-changed-pact:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v2
21+
- name: Set up JDK 11
22+
uses: actions/setup-java@v2
23+
with:
24+
distribution: 'zulu'
25+
java-version: '11'
26+
- name: Build
27+
run: GIT_BRANCH=${GITHUB_REF:11} make ci_webhook

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
*.DS_Store
2+
*.sw?
3+
.#*
4+
*#
5+
*~
6+
.classpath
7+
.project
8+
.settings
9+
bin
10+
build
11+
target
12+
dependency-reduced-pom.xml
13+
*.sublime-*
14+
/scratch
15+
.gradle
16+
README.html
17+
.idea
18+
*.iml
19+
*.log
20+
.vscode

.java-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
11

.whitesource

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"settingsInheritedFrom": "pactflow/whitesource-config@main"
3+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 PactFlow
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
PACTICIPANT := "pactflow-example-provider-java-graphql"
2+
WEBHOOK_UUID := "9GS-Z8nSAbUzvJW4xmhdsg"
3+
PACT_CHANGED_WEBHOOK_UUID := "c76b601e-d66a-4eb1-88a4-6ebc50c0df8b"
4+
PACT_CLI="docker run --rm -v ${PWD}:${PWD} -e PACT_BROKER_BASE_URL -e PACT_BROKER_TOKEN pactfoundation/pact-cli"
5+
6+
# Only deploy from master
7+
ifeq ($(GIT_BRANCH),master)
8+
DEPLOY_TARGET=deploy
9+
else
10+
DEPLOY_TARGET=no_deploy
11+
endif
12+
13+
all: test
14+
15+
## ====================
16+
## CI tasks
17+
## ====================
18+
19+
ci: test $(DEPLOY_TARGET)
20+
21+
# Run the ci target from a developer machine with the environment variables
22+
# set as if it was on GitHub Actions
23+
# Use this for quick feedback when playing around with your workflows.
24+
fake_ci: .env
25+
CI=true \
26+
GIT_COMMIT=`git rev-parse --short HEAD`+`date +%s` \
27+
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD` \
28+
PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true \
29+
make ci
30+
31+
ci_webhook: .env
32+
./gradlew clean test -i
33+
34+
fake_ci_webhook:
35+
CI=true \
36+
GIT_COMMIT=`git rev-parse --short HEAD`+`date +%s` \
37+
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD` \
38+
PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true \
39+
make ci_webhook
40+
41+
## =====================
42+
## Build/test tasks
43+
## =====================
44+
45+
test: .env
46+
./gradlew clean test -i
47+
48+
## =====================
49+
## Deploy tasks
50+
## =====================
51+
52+
deploy: can_i_deploy deploy_app record_deployment
53+
54+
no_deploy:
55+
@echo "Not deploying as not on master branch"
56+
57+
can_i_deploy: .env
58+
@"${PACT_CLI}" broker can-i-deploy --pacticipant ${PACTICIPANT} --version ${GIT_COMMIT} --to-environment production
59+
60+
deploy_app:
61+
@echo "Deploying to prod"
62+
63+
record_deployment:
64+
@"${PACT_CLI}" broker record_deployment --pacticipant ${PACTICIPANT} --version ${GIT_COMMIT} --environment production
65+
66+
## =====================
67+
## PactFlow set up tasks
68+
## =====================
69+
70+
# export the GITHUB_TOKEN environment variable before running this
71+
create_github_token_secret:
72+
curl -v -X POST ${PACT_BROKER_BASE_URL}/secrets \
73+
-H "Authorization: Bearer ${PACT_BROKER_TOKEN}" \
74+
-H "Content-Type: application/json" \
75+
-H "Accept: application/hal+json" \
76+
-d "{\"name\":\"githubToken\",\"description\":\"Github token\",\"value\":\"${GITHUB_TOKEN}\"}"
77+
78+
# NOTE: the github token secret must be created (either through the UI or using the
79+
# `create_github_token_secret` target) before the webhook is invoked.
80+
create_or_update_pact_changed_webhook:
81+
"${PACT_CLI}" \
82+
broker create-or-update-webhook \
83+
"https://api.github.com/repos/${GITHUB_REPO}/dispatches" \
84+
--header 'Content-Type: application/json' 'Accept: application/vnd.github.everest-preview+json' 'Authorization: Bearer $${user.githubToken}' \
85+
--request POST \
86+
--data '{ "event_type": "pact_changed", "client_payload": { "pact_url": "$${pactbroker.pactUrl}" } }' \
87+
--uuid ${PACT_CHANGED_WEBHOOK_UUID} \
88+
--consumer ${PACTICIPANT} \
89+
--contract-content-changed \
90+
--description "Pact content changed for ${PACTICIPANT}"
91+
92+
test_pact_changed_webhook:
93+
@curl -v -X POST ${PACT_BROKER_BASE_URL}/webhooks/${PACT_CHANGED_WEBHOOK_UUID}/execute -H "Authorization: Bearer ${PACT_BROKER_TOKEN}"
94+
95+
## ======================
96+
## Misc
97+
## ======================
98+
99+
.env:
100+
touch .env
101+
102+
schema-test:
103+
# @./node_modules/.bin/swagger-mock-validator ./oas/swagger.yml ../example-consumer-cypress/pacts/example-cypress-consumer-pactflow-example-provider.json
104+
./node_modules/.bin/swagger-mock-validator --user dXfltyFMgNOFZAxr8io9wJ37iUpY42M:O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1 --tag master --provider pactflow-example-provider ./oas/swagger.yml https://test.pactflow.io

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,19 @@ You can simulate a CI process with the following command:
6363
```
6464
make fake_ci
6565
```
66+
67+
## Graphiql
68+
69+
Once you start the app (`./gradlew bootRun`) you can view the Graphiql interface and interact with the GraphQL server at http://localhost:8080/graphiql
70+
71+
72+
Example query:
73+
```gql
74+
{
75+
product(id: 1) {
76+
id
77+
name
78+
type
79+
}
80+
}
81+
```

0 commit comments

Comments
 (0)