Skip to content

Commit 561247a

Browse files
authored
adding CI/CD workflows (#3)
* adding CI/CD workflows Co-authored-by: Alexander Hungenberg <[email protected]>
1 parent c59da31 commit 561247a

File tree

10 files changed

+910
-663
lines changed

10 files changed

+910
-663
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Default
2+
* @defreng

.github/dependabot.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: 2
2+
updates:
3+
4+
# Maintain dependencies for GitHub Actions
5+
- package-ecosystem: "github-actions"
6+
directory: "/"
7+
schedule:
8+
interval: "weekly"
9+
10+
# Maintain dependencies for poetry
11+
- package-ecosystem: "pip"
12+
directory: "/"
13+
schedule:
14+
interval: "weekly"

.github/workflows/cd.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: CD
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
workflow_dispatch:
8+
9+
env:
10+
FORCE_COLOR: "1" # Make tools pretty.
11+
PYTHON_LATEST: "3.11"
12+
13+
jobs:
14+
ci:
15+
uses: ./.github/workflows/ci.yml
16+
17+
deploy-pypi:
18+
needs: [ci]
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v3
22+
- uses: actions/setup-python@v4
23+
with:
24+
python-version: ${{ env.PYTHON_LATEST }}
25+
26+
- run: python -m pip install build twine
27+
- run: python -m build --sdist --wheel .
28+
29+
- name: Publish package
30+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
31+
uses: pypa/gh-action-pypi-publish@release/v1
32+
with:
33+
user: __token__
34+
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/ci.yml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
workflow_dispatch:
9+
workflow_call:
10+
11+
permissions:
12+
contents: read
13+
14+
env:
15+
FORCE_COLOR: "1" # Make tools pretty.
16+
PYTHON_LATEST: "3.11"
17+
POETRY_VIRTUALENVS_CREATE: false
18+
19+
20+
jobs:
21+
linting:
22+
name: Linting
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- uses: actions/checkout@v3
27+
- uses: actions/setup-python@v4
28+
with:
29+
python-version: ${{ env.PYTHON_LATEST }}
30+
- uses: snok/install-poetry@v1
31+
with:
32+
version: 1.3.0
33+
virtualenvs-create: true
34+
- name: Install dependencies
35+
run: |
36+
poetry self add "poetry-dynamic-versioning[plugin]"
37+
poetry install --only=dev
38+
39+
- name: black
40+
run: python -m black --check --diff .
41+
42+
- name: flake8
43+
run: python -m flake8 .
44+
45+
- name: isort
46+
run: python -m isort --check-only -v --profile black .
47+
48+
typing:
49+
name: Typing
50+
runs-on: ubuntu-latest
51+
52+
steps:
53+
- uses: actions/checkout@v3
54+
- uses: actions/setup-python@v4
55+
with:
56+
python-version: ${{ env.PYTHON_LATEST }}
57+
- uses: snok/install-poetry@v1
58+
with:
59+
version: 1.3.0
60+
virtualenvs-create: true
61+
- name: Install dependencies
62+
run: |
63+
poetry self add "poetry-dynamic-versioning[plugin]"
64+
poetry install
65+
66+
- name: mypy
67+
run: python -m mypy .
68+
69+
70+
tests:
71+
name: tests on ${{ matrix.python-version }}
72+
runs-on: ubuntu-22.04
73+
strategy:
74+
fail-fast: false
75+
matrix:
76+
python-version: ["3.10", "3.11"]
77+
78+
steps:
79+
- uses: actions/checkout@v3
80+
- uses: actions/setup-python@v4
81+
with:
82+
python-version: ${{ matrix.python-version }}
83+
- uses: snok/install-poetry@v1
84+
with:
85+
version: 1.3.0
86+
virtualenvs-create: true
87+
- name: Install dependencies
88+
run: |
89+
poetry self add "poetry-dynamic-versioning[plugin]"
90+
poetry install
91+
92+
- name: Setup Git
93+
run: |
94+
git config --global user.email "[email protected]"
95+
git config --global user.name "Your Name"
96+
97+
- run: poetry run pytest --cov=foxops_client
98+
env:
99+
COVERAGE_FILE: .coverage.${{ matrix.python-version }}
100+
101+
- name: Upload coverage data
102+
uses: actions/upload-artifact@v3
103+
with:
104+
name: coverage-data
105+
path: .coverage.*
106+
if-no-files-found: ignore
107+
108+
109+
coverage:
110+
name: Combine & check coverage
111+
runs-on: ubuntu-latest
112+
needs: [tests]
113+
114+
steps:
115+
- uses: actions/checkout@v3
116+
- uses: actions/setup-python@v4
117+
with:
118+
python-version: ${{env.PYTHON_LATEST}}
119+
- run: python -m pip install --upgrade coverage[toml]
120+
- uses: actions/download-artifact@v3
121+
with:
122+
name: coverage-data
123+
- name: Combine coverage & fail if it's <70%.
124+
run: |
125+
python -m coverage combine
126+
python -m coverage html --skip-covered --skip-empty
127+
python -m coverage report --fail-under=70
128+
- name: Upload HTML report
129+
uses: actions/upload-artifact@v3
130+
with:
131+
name: html-report
132+
path: htmlcov
133+
134+
135+
package:
136+
name: Build & verify package
137+
runs-on: ubuntu-latest
138+
139+
steps:
140+
- uses: actions/checkout@v3
141+
- uses: actions/setup-python@v4
142+
with:
143+
python-version: ${{ env.PYTHON_LATEST }}
144+
145+
- run: python -m pip install build twine check-wheel-contents
146+
- run: python -m build --sdist --wheel .
147+
- run: ls -l dist
148+
- run: check-wheel-contents dist/*.whl
149+
- name: Check long_description
150+
run: python -m twine check dist/*
151+
152+
153+
install-dev:
154+
name: Verify dev env
155+
runs-on: ${{ matrix.os }}
156+
strategy:
157+
fail-fast: false
158+
matrix:
159+
os: [ubuntu-latest, macos-latest, windows-latest]
160+
161+
steps:
162+
- uses: actions/checkout@v3
163+
- uses: actions/setup-python@v4
164+
with:
165+
python-version: ${{ env.PYTHON_LATEST }}
166+
- run: python -m pip install -e .
167+
- run: python -c 'import foxops_client; print(foxops_client.__version__)'

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.venv/
22
**/.pytest_cache/
33
**/.mypy_cache/
4+
.coverage
5+
.idea/

CONTRIBUTING.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Contributing
2+
3+
## Tests
4+
5+
The foxops API client relies mostly on e2e tests that execute calls against a running foxops (and Gitlab) server. The tests are located in the `tests` directory and are executed using `pytest`.
6+
7+
All the necessary test environment is spun up locally using docker images and the `pytest-docker-tools` plugin. You can find the relevant fixtures in the `tests/infrastucture` directory.
8+
9+
No additional configuration is needed to run the tests. The only requirement is that you have a running docker daemon.
10+
11+
```shell
12+
# Executing all tests from a "cold start" could take a while as the Gitlab docker image takes 2-3 minutes to start
13+
poetry run pytest
14+
15+
# instead, especially during development, it's recommended to keep the Gitlab container running and not terminate it at the end.
16+
poetry run pytest --reuse-containers
17+
```

0 commit comments

Comments
 (0)