Skip to content

Commit dfebcf8

Browse files
authored
Add workflows for testing and releasing the utility
2 parents 7e1b5df + 4032277 commit dfebcf8

File tree

6 files changed

+83
-13
lines changed

6 files changed

+83
-13
lines changed

.github/workflows/release.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Release to PyPI
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.11"
19+
20+
- name: Install build dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install build twine
24+
25+
- name: Build package
26+
run: python -m build
27+
28+
- name: Publish to PyPI
29+
env:
30+
TWINE_USERNAME: __token__
31+
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
32+
run: twine upload dist/*

.github/workflows/tests.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.8", "3.9", "3.10", "3.11"]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install -e ".[dev]"
28+
29+
- name: Lint with ruff
30+
run: ruff check .
31+
32+
- name: Check formatting with black
33+
run: black --check .
34+
35+
- name: Run tests
36+
run: pytest tests/ -v

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ __pycache__
55
localstack_utils.egg-info
66
.ruff_cache
77
dist
8+
*.env

localstack_utils/container.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import logging
24
import re
35
import docker
@@ -69,4 +71,4 @@ def wait_for_ready(container, pattern):
6971
attempts += 1
7072

7173
if attempts >= MAX_LOG_COLLECTION_ATTEMPTS:
72-
raise "Could not find token: " + pattern.toString() + "in logs"
74+
raise RuntimeError(f"Could not find token: {pattern.pattern} in logs")

localstack_utils/localstack.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import re
2-
import sys
32
import docker
43
import logging
54
from localstack_utils.container import Container
@@ -41,14 +40,13 @@ def startup(self, docker_configuration):
4140

4241
try:
4342
self.localstack_container = Container.create_localstack_container(
44-
docker_configuration.pull_new_image,
45-
docker_configuration.image_name,
46-
docker_configuration.image_tag,
47-
docker_configuration.gateway_listen,
48-
docker_configuration.environment_variables,
49-
docker_configuration.port_mappings,
50-
docker_configuration.pro,
51-
docker_configuration.auto_remove_container,
43+
pull_new_image=docker_configuration.pull_new_image,
44+
image_name=docker_configuration.image_name,
45+
image_tag=docker_configuration.image_tag,
46+
gateway_listen=docker_configuration.gateway_listen,
47+
auto_remove=docker_configuration.auto_remove_container,
48+
environment_variables=docker_configuration.environment_variables,
49+
bind_ports=docker_configuration.port_mappings,
5250
)
5351

5452
self.setup_logger()
@@ -57,10 +55,10 @@ def startup(self, docker_configuration):
5755

5856
except docker.errors.APIError:
5957
if not docker_configuration.ignore_docker_runerrors:
60-
raise "Unable to start docker"
58+
raise RuntimeError("Unable to start docker")
6159

6260
except Exception:
63-
raise sys.exc_info()
61+
raise
6462

6563
def stop(self):
6664
self.localstack_container.stop()

tests/test_kinesis.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class TestKinesis(unittest.TestCase):
88
def setUp(self):
9-
startup_localstack()
9+
startup_localstack(image_name="localstack/localstack")
1010

1111
def tearDown(self):
1212
stop_localstack()
@@ -16,6 +16,7 @@ def test_create_stream(self):
1616
kinesis = boto3.client(
1717
service_name="kinesis",
1818
aws_access_key_id="test",
19+
region_name="us-east-1",
1920
aws_secret_access_key="test",
2021
endpoint_url="http://localhost:4566",
2122
)

0 commit comments

Comments
 (0)