Skip to content

Commit b8ecd5e

Browse files
committed
ci: add support for python in GH actions
1 parent 4720ac6 commit b8ecd5e

File tree

6 files changed

+54
-87
lines changed

6 files changed

+54
-87
lines changed

.github/workflows/build.yml

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ on:
55
workflow_dispatch:
66

77
env:
8-
PACT_BROKER_BASE_URL: https://test.pactflow.io
8+
PACT_BROKER_BASE_URL: https://saf.pactflow.io
99
PACT_BROKER_TOKEN: ${{ secrets.PACTFLOW_TOKEN_FOR_CI_CD_WORKSHOP }}
10-
REACT_APP_API_BASE_URL: http://localhost:8080
1110
GIT_COMMIT: ${{ github.sha }}
1211
GIT_REF: ${{ github.ref }}
1312

@@ -18,11 +17,38 @@ jobs:
1817
- uses: actions/checkout@v2
1918
- uses: actions/setup-python@v4
2019
with:
21-
python-version: '3.8'
20+
python-version: "3.8"
21+
# - name: Install python version
22+
# uses: gabrielfalcao/pyenv-action@v10
23+
# with:
24+
# default: 3.8.13
25+
# command: pip install -U pip # upgrade pip after installing python
26+
# - name: Create virtualenv for python 3.5.7
27+
# run: pyenv local 3.8.13 && python3 -mvenv .venv
28+
# - name: venv
29+
# run: pyenv local 3.8.13 && python3 -mvenv .venv3813
30+
- name: install pyenv
31+
run: curl https://pyenv.run | bash
32+
- name: set pyenv on path
33+
run: |
34+
export PYENV_ROOT="$HOME/.pyenv"
35+
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH" >> .bashrc
36+
eval "$(pyenv init -)" >> .bashrc
37+
eval "$(pyenv virtualenv-init -)" >> .bashrc
38+
source ~/.bashrc
39+
echo PATH="$PYENV_ROOT/bin:$PATH" >> $GITHUB_ENV
40+
- name: Install poetry
41+
run: pip install poetry
42+
- name: Setup Virtual env
43+
run: make venv
2244
- name: Install
2345
run: make deps
24-
- name: Test
25-
run: make test
46+
- name: Activate virtual env
47+
run: |
48+
source .venv/bin/activate
49+
make test
50+
# - name: Test
51+
# run: make test
2652
- name: Publish pacts
2753
run: GIT_BRANCH=${GIT_REF:11} make publish_pacts
2854

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
.venv
22
.aws-sam
33
.idea
4+
.vscode
45
.python-version
5-
__pycache__
6+
__pycache__
7+
pacts
8+
.pytest_cache

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fake_ci: .env
3030

3131

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

3535
## =====================
3636
## Build/test tasks
@@ -142,10 +142,10 @@ venv:
142142
@echo "\n$(green)Use it! (populate .python-version)$(sgr0)"
143143
pyenv local ${PROJECT}
144144

145-
deploy:
145+
deploy_sam:
146146
scripts/deploy.sh
147147

148-
publish:
148+
publish_sam:
149149
scripts/publish.sh
150150

151151
logs:

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,34 @@ You're probably familiar with layered architectures such as Ports and Adaptors (
2525

2626
This code base is setup with this modularity in mind:
2727

28-
* [Lambda Handler](src/_lambda/product.py)
29-
* [Event Service](src/product/product_service.py)
30-
* Business Logic
31-
* [Product](src/product/product.py)
32-
* [Repository](src/product/product_repository.py)
28+
- [Lambda Handler](src/_lambda/product.py)
29+
- [Event Service](src/product/product_service.py)
30+
- Business Logic
31+
- [Product](src/product/product.py)
32+
- [Repository](src/product/product_repository.py)
3333

3434
The target of our [consumer pact test](tests/unit/product_service_pact_test.py) is the [Event Service](src/product/product_service.js), which is responsible for consuming a Product update event, and persisting it to a database (the Repository).
3535

3636
See also:
3737

38-
* https://dius.com.au/2017/09/22/contract-testing-serverless-and-asynchronous-applications/
39-
* https://dius.com.au/2018/10/01/contract-testing-serverless-and-asynchronous-applications---part-2/
38+
- https://dius.com.au/2017/09/22/contract-testing-serverless-and-asynchronous-applications/
39+
- https://dius.com.au/2018/10/01/contract-testing-serverless-and-asynchronous-applications---part-2/
4040

4141
## Usage
42+
4243
### Testing
4344

44-
* Run the unit tests: `make test`
45-
* Run a (local) lambda integration test: `make integration`
45+
- Run the unit tests: `make test`
46+
- Run a (local) lambda integration test: `make integration`
4647

4748
### Running
4849

49-
* Deploy the actual app: `make deploy` (see below for more background)
50-
* Publish a test event: `make publish`
51-
* View the lambda logs: `make logs`
50+
- Deploy the actual app: `make deploy_sam` (see below for more background)
51+
- Publish a test event: `make publish_sam`
52+
- View the lambda logs: `make logs`
5253

5354
Here is some sample output publishing and viewing the logs:
55+
5456
```
5557
➜ example-consumer-js-sns git:(master) ✗ npm run publish <aws:pact-dev>
5658

pacts/pactflow-example-consumer-python-sns-pactflow-example-provider-python-sns.json

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

tests/unit/product_service_pact_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from src.product.product_service import receive_product_update
77

88
CONSUMER_NAME = "pactflow-example-consumer-python-sns"
9-
PROVIDER_NAME = os.getenv("PACT_PROVIDER", "pactflow-example-provider-python-sns")
10-
PACT_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "pacts")
9+
PROVIDER_NAME = os.getenv("PACT_PROVIDER", "pactflow-example-provider-js-sns")
10+
PACT_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),"..","..", "pacts")
1111

1212
@pytest.fixture(scope="session")
1313
def consumer():

0 commit comments

Comments
 (0)