Skip to content

Commit 8128db0

Browse files
authored
Merge pull request #2 from pactflow/add_gh_pipeline
Add gh pipeline
2 parents 793d6c4 + 52dfb27 commit 8128db0

File tree

4 files changed

+91
-43
lines changed

4 files changed

+91
-43
lines changed

.github/workflows/build.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
workflow_dispatch:
6+
7+
env:
8+
PACT_BROKER_BASE_URL: https://testdemo.pactflow.io
9+
PACT_BROKER_TOKEN: ${{ secrets.PACTFLOW_TOKEN_FOR_CI_CD_WORKSHOP }}
10+
BASE_URL: http://localhost:5000
11+
GIT_COMMIT: ${{ github.sha }}
12+
GIT_REF: ${{ github.ref }}
13+
14+
jobs:
15+
test:
16+
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
# note currently PACT_PROVIDER isn't used in the code
20+
pact_provider:
21+
[
22+
"pactflow-example-provider-python",
23+
# "pactflow-example-provider-dredd",
24+
# "pactflow-example-provider-restassured",
25+
# "pactflow-example-provider-postman",
26+
# "pactflow-example-provider",
27+
# 'pactflow-example-bi-directional-provider-dotnet'
28+
]
29+
steps:
30+
- uses: actions/checkout@v3
31+
- uses: actions/setup-python@v3
32+
with:
33+
python-version: '3.8'
34+
architecture: 'x64'
35+
- run: pip install -r requirements.txt
36+
- name: Test for ${{ matrix.pact_provider }}
37+
run: make test
38+
env:
39+
PACT_PROVIDER: ${{ matrix.pact_provider }}
40+
- name: Publish pacts
41+
run: GIT_BRANCH=${GIT_REF:11} make publish_pacts
42+
env:
43+
PACT_PROVIDER: ${{ matrix.pact_provider }}
44+
45+
# Runs on branches as well, so we know the status of our PRs
46+
can-i-deploy:
47+
runs-on: ubuntu-latest
48+
needs: test
49+
steps:
50+
- uses: actions/checkout@v2
51+
- run: docker pull pactfoundation/pact-cli:latest
52+
- name: Can I deploy?
53+
run: GIT_BRANCH=${GIT_REF:11} make can_i_deploy
54+
55+
# Only deploy from master
56+
deploy:
57+
runs-on: ubuntu-latest
58+
needs: can-i-deploy
59+
steps:
60+
- uses: actions/checkout@v2
61+
- run: docker pull pactfoundation/pact-cli:latest
62+
- name: Deploy
63+
run: GIT_BRANCH=${GIT_REF:11} make deploy
64+
if: github.ref == 'refs/heads/master'

.travis.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

Makefile

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Default to the read only token - the read/write token will be present on Travis CI.
2-
# It's set as a secure environment variable in the .travis.yml file
1+
# Default to the read only token - the read/write token will be present on GitHub Action.
2+
# It's set as a secure environment variable in the build.yml file
33
PACTICIPANT := "pactflow-example-consumer-python"
44
GITHUB_WEBHOOK_UUID := "04510dc1-7f0a-4ed2-997d-114bfa86f8ad"
55
PACT_CLI="docker run --rm -v ${PWD}:${PWD} -e PACT_BROKER_BASE_URL -e PACT_BROKER_TOKEN -e PACT_BROKER_USERNAME -e PACT_BROKER_PASSWORD pactfoundation/pact-cli:latest"
66

77
# Only deploy from master
8-
ifeq ($(TRAVIS_BRANCH),master)
8+
ifeq ($(GIT_BRANCH),master)
99
DEPLOY_TARGET=deploy
1010
else
1111
DEPLOY_TARGET=no_deploy
@@ -20,17 +20,17 @@ all: test
2020
ci: test publish_pacts can_i_deploy $(DEPLOY_TARGET)
2121

2222
# Run the ci target from a developer machine with the environment variables
23-
# set as if it was on Travis CI.
23+
# set as if it was on GitHub Action.
2424
# Use this for quick feedback when playing around with your workflows.
2525
fake_ci: .env
2626
CI=true \
27-
TRAVIS_COMMIT=`git rev-parse --short HEAD`+`date +%s` \
28-
TRAVIS_BRANCH=`git rev-parse --abbrev-ref HEAD` \
27+
GIT_COMMIT=`git rev-parse --short HEAD`+`date +%s` \
28+
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD` \
2929
REACT_APP_API_BASE_URL=http://localhost:8080 \
3030
make ci
3131

3232
publish_pacts: .env
33-
@"${PACT_CLI}" publish ${PWD}/pacts --consumer-app-version ${TRAVIS_COMMIT} --tag ${TRAVIS_BRANCH}
33+
@"${PACT_CLI}" publish ${PWD}/pacts --consumer-app-version ${GIT_COMMIT} --tag ${GIT_BRANCH}
3434

3535
## =====================
3636
## Build/test tasks
@@ -43,24 +43,32 @@ test: .env
4343
## Deploy tasks
4444
## =====================
4545

46-
deploy: deploy_app tag_as_prod
46+
deploy: deploy_app tag record_deployment
4747

4848
no_deploy:
4949
@echo "Not deploying as not on master branch"
5050

5151
can_i_deploy: .env
52+
echo "can_i_deploy"
5253
@"${PACT_CLI}" broker can-i-deploy \
5354
--pacticipant ${PACTICIPANT} \
54-
--version ${TRAVIS_COMMIT} \
55-
--to prod \
55+
--version ${GIT_COMMIT} \
56+
--to-environment production \
5657
--retry-while-unknown 0 \
5758
--retry-interval 10
5859

5960
deploy_app:
6061
@echo "Deploying to prod"
6162

62-
tag_as_prod: .env
63-
@"${PACT_CLI}" broker create-version-tag --pacticipant ${PACTICIPANT} --version ${TRAVIS_COMMIT} --tag prod
63+
tag: .env
64+
@"${PACT_CLI}" broker create-version-tag \
65+
--pacticipant ${PACTICIPANT} \
66+
--version ${GIT_COMMIT} \
67+
--auto-create-version \
68+
--tag ${GIT_BRANCH}
69+
70+
record_deployment: .env
71+
@"${PACT_CLI}" broker record-deployment --pacticipant ${PACTICIPANT} --version ${GIT_COMMIT} --environment production
6472

6573
## =====================
6674
## Pactflow set up tasks
@@ -94,17 +102,6 @@ create_or_update_github_webhook:
94102
test_github_webhook:
95103
@curl -v -X POST ${PACT_BROKER_BASE_URL}/webhooks/${GITHUB_WEBHOOK_UUID}/execute -H "Authorization: Bearer ${PACT_BROKER_TOKEN}"
96104

97-
## ======================
98-
## Travis CI set up tasks
99-
## ======================
100-
101-
travis_login:
102-
@docker run --rm -v ${HOME}/.travis:/root/.travis -it lirantal/travis-cli login --pro
103-
104-
# Requires PACT_BROKER_TOKEN to be set
105-
travis_encrypt_pact_broker_token:
106-
@docker run --rm -v ${HOME}/.travis:/root/.travis -v ${PWD}:${PWD} --workdir ${PWD} lirantal/travis-cli encrypt --pro PACT_BROKER_TOKEN="${PACT_BROKER_TOKEN}"
107-
108105
## ======================
109106
## Misc
110107
## ======================

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# Example Consumer
22

3-
[![Build Status](https://travis-ci.com/pactflow/example-consumer-python.svg?branch=master)](https://travis-ci.com/pactflow/example-consumer-python)
3+
![Build](https://github.com/pactflow/example-consumer-python/workflows/Build/badge.svg)
44

5-
[![Pact Status](https://test.pactflow.io/pacts/provider/pactflow-example-provider-python/consumer/pactflow-example-consumer-python/latest/badge.svg?label=provider)](https://test.pactflow.io/pacts/provider/pactflow-example-provider-python/consumer/pactflow-example-consumer-python/latest) (latest pact)
5+
[![Can I deploy Status](https://testdemo.pactflow.io/pacticipants/pactflow-example-consumer-python/branches/master/latest-version/can-i-deploy/to-environment/production/badge.svg)](https://testdemo.pactflow.io/overview/provider/pactflow-example-consumer-python/consumer/pactflow-example-consumer-python)
66

7-
[![Pact Status](https://test.pactflow.io/matrix/provider/pactflow-example-provider-python/latest/prod/consumer/pactflow-example-consumer-python/latest/prod/badge.svg?label=provider)](https://test.pactflow.io/pacts/provider/pactflow-example-provider-python/consumer/pactflow-example-consumer-python/latest/prod) (prod/prod pact)
7+
[![Pact Status](https://testdemo.pactflow.io/pacts/provider/pactflow-example-provider-python/consumer/pactflow-example-consumer-python/latest/badge.svg)](https://testdemo.pactflow.io/pacts/provider/pactflow-example-provider-python/consumer/pactflow-example-consumer-python/latest) (latest pact)
8+
9+
[![Pact Status](https://testdemo.pactflow.io/pacts/provider/pactflow-example-provider-python/consumer/pactflow-example-consumer-python/latest/master/badge.svg)](https://testdemo.pactflow.io/pacts/provider/pactflow-example-provider-python/consumer/pactflow-example-consumer-python/latest/master) (master/master pact)
810

911
This is an example of a Python consumer using Pact to create a consumer driven contract, and sharing it via [Pactflow](https://pactflow.io).
1012

11-
It is using a public tenant on Pactflow, which you can access [here](https://test.pactflow.io) using the credentials `dXfltyFMgNOFZAxr8io9wJ37iUpY42M`/`O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1`. The latest version of the Example Consumer/Example Provider pact is published [here](https://test.pactflow.io/pacts/provider/pactflow-example-provider-python/consumer/pactflow-example-consumer-python/latest).
13+
It is using a public tenant on Pactflow, which you can access [here](https://testdemo.pactflow.io) using the credentials `dXfltyFMgNOFZAxr8io9wJ37iUpY42M`/`O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1`. The latest version of the Example Consumer/Example Provider pact is published [here](https://testdemo.pactflow.io/pacts/provider/pactflow-example-provider-python/consumer/pactflow-example-consumer-python/latest).
1214

1315
The project uses a Makefile to simulate a very simple build pipeline with two stages - test and deploy.
1416

@@ -32,7 +34,7 @@ make test
3234

3335
To run the "fake ci" task:
3436
```
35-
export PACT_BROKER_BASE_URL=https://test.pactflow.io
37+
export PACT_BROKER_BASE_URL=https://testdemo.pactflow.io
3638
export PACT_BROKER_USERNAME=dXfltyFMgNOFZAxr8io9wJ37iUpY42M
3739
export PACT_BROKER_PASSWORD=O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1
3840
make fake_ci

0 commit comments

Comments
 (0)