Skip to content

Commit 2ba96c9

Browse files
committed
add tox for linting and testing and add ci/cd
Signed-off-by: Robert Marklund <robbelibobban@gmail.com>
1 parent b229afa commit 2ba96c9

File tree

8 files changed

+4124
-0
lines changed

8 files changed

+4124
-0
lines changed

.github/workflows/ci.yml

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
lint:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
os: [ubuntu-latest, windows-latest, macos-latest]
16+
python-version: ['3.11', '3.12', '3.13']
17+
defaults:
18+
run:
19+
shell: bash
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Set up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v4
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
29+
- name: Install Poetry
30+
uses: snok/install-poetry@v1
31+
with:
32+
version: latest
33+
virtualenvs-create: true
34+
virtualenvs-in-project: true
35+
36+
- name: Load cached venv
37+
id: cached-poetry-dependencies
38+
uses: actions/cache@v4
39+
with:
40+
path: .venv
41+
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
42+
43+
- name: Install dependencies
44+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
45+
run: poetry install --with dev
46+
47+
- name: Run linting with tox
48+
run: poetry run tox -e flake8,pylint,ruff
49+
50+
test:
51+
runs-on: ${{ matrix.os }}
52+
strategy:
53+
fail-fast: false
54+
matrix:
55+
os: [ubuntu-latest, windows-latest, macos-latest]
56+
python-version: ['3.11', '3.12', '3.13']
57+
defaults:
58+
run:
59+
shell: bash
60+
61+
steps:
62+
- uses: actions/checkout@v4
63+
64+
- name: Set up Python ${{ matrix.python-version }}
65+
uses: actions/setup-python@v4
66+
with:
67+
python-version: ${{ matrix.python-version }}
68+
69+
- name: Install Poetry
70+
uses: snok/install-poetry@v1
71+
with:
72+
version: latest
73+
virtualenvs-create: true
74+
virtualenvs-in-project: true
75+
76+
- name: Load cached venv
77+
id: cached-poetry-dependencies
78+
uses: actions/cache@v4
79+
with:
80+
path: .venv
81+
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
82+
83+
- name: Check poetry version
84+
run: poetry --version
85+
86+
- name: Install dependencies
87+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
88+
run: poetry install --with dev
89+
90+
- name: Run tests with tox
91+
run: poetry run tox -vvv -e py${{ matrix.python-version }}
92+
93+
security:
94+
runs-on: ubuntu-latest
95+
steps:
96+
- uses: actions/checkout@v4
97+
98+
- name: Set up Python
99+
uses: actions/setup-python@v4
100+
with:
101+
python-version: '3.12'
102+
103+
- name: Install Poetry
104+
uses: snok/install-poetry@v1
105+
with:
106+
version: latest
107+
virtualenvs-create: true
108+
virtualenvs-in-project: true
109+
110+
- name: Load cached venv
111+
id: cached-poetry-dependencies
112+
uses: actions/cache@v4
113+
with:
114+
path: .venv
115+
key: venv-${{ runner.os }}-3.12-${{ hashFiles('**/poetry.lock') }}
116+
117+
- name: Install dependencies
118+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
119+
run: poetry install --with dev
120+
121+
- name: Run security checks
122+
run: poetry run tox -e security
123+
124+
- name: Upload security reports
125+
uses: actions/upload-artifact@v4
126+
if: always()
127+
with:
128+
name: security-reports
129+
path: |
130+
bandit-report.json
131+
safety-report.json
132+
133+
build:
134+
needs: [lint, test]
135+
runs-on: ubuntu-latest
136+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
137+
138+
steps:
139+
- uses: actions/checkout@v4
140+
141+
- name: Set up Python
142+
uses: actions/setup-python@v4
143+
with:
144+
python-version: '3.12'
145+
146+
- name: Install Poetry
147+
uses: snok/install-poetry@v1
148+
with:
149+
version: latest
150+
virtualenvs-create: true
151+
virtualenvs-in-project: true
152+
153+
- name: Load cached venv
154+
id: cached-poetry-dependencies
155+
uses: actions/cache@v4
156+
with:
157+
path: .venv
158+
key: venv-${{ runner.os }}-3.12-${{ hashFiles('**/poetry.lock') }}
159+
160+
- name: Install dependencies
161+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
162+
run: poetry install --with dev
163+
164+
- name: Build package
165+
run: poetry build
166+
167+
- name: Check package
168+
run: poetry run twine check dist/*
169+
170+
- name: Upload build artifacts
171+
uses: actions/upload-artifact@v4
172+
with:
173+
name: dist
174+
path: dist/

.gitlab-ci.yml

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
stages:
2+
- lint
3+
- test
4+
- security
5+
- build
6+
7+
variables:
8+
POETRY_CACHE_DIR: "$CI_PROJECT_DIR/.cache/poetry"
9+
POETRY_VIRTUALENVS_IN_PROJECT: "true"
10+
11+
cache:
12+
paths:
13+
- .cache/poetry
14+
- .venv/
15+
- .tox/
16+
17+
.lint-template: &lint-template
18+
stage: lint
19+
before_script:
20+
- python -m pip install --upgrade pip
21+
- pip install poetry
22+
- poetry config cache-dir $POETRY_CACHE_DIR
23+
- poetry install --with dev
24+
script:
25+
- poetry run tox -e flake8,pylint,ruff
26+
artifacts:
27+
reports:
28+
junit: reports/
29+
paths:
30+
- .tox/
31+
expire_in: 1 week
32+
only:
33+
- merge_requests
34+
- main
35+
- develop
36+
37+
.test-template: &test-template
38+
stage: test
39+
before_script:
40+
- python -m pip install --upgrade pip
41+
- pip install poetry
42+
- poetry config cache-dir $POETRY_CACHE_DIR
43+
- poetry install --with dev
44+
script:
45+
- poetry run tox -e py$PYTHON_VERSION
46+
artifacts:
47+
reports:
48+
junit: reports/
49+
paths:
50+
- .tox/
51+
expire_in: 1 week
52+
only:
53+
- merge_requests
54+
- main
55+
- develop
56+
57+
# Linux jobs
58+
lint-linux:
59+
<<: *lint-template
60+
image: python:3.12-slim
61+
tags:
62+
- linux
63+
- docker
64+
65+
test-linux-311:
66+
<<: *test-template
67+
image: python:3.11-slim
68+
variables:
69+
PYTHON_VERSION: "311"
70+
tags:
71+
- linux
72+
- docker
73+
74+
test-linux-312:
75+
<<: *test-template
76+
image: python:3.12-slim
77+
variables:
78+
PYTHON_VERSION: "312"
79+
tags:
80+
- linux
81+
- docker
82+
83+
test-linux-313:
84+
<<: *test-template
85+
image: python:3.13-slim
86+
variables:
87+
PYTHON_VERSION: "313"
88+
tags:
89+
- linux
90+
- docker
91+
92+
# Windows jobs
93+
lint-windows:
94+
<<: *lint-template
95+
tags:
96+
- windows
97+
- shell
98+
99+
test-windows-311:
100+
<<: *test-template
101+
tags:
102+
- windows
103+
- shell
104+
variables:
105+
PYTHON_VERSION: "311"
106+
107+
test-windows-312:
108+
<<: *test-template
109+
tags:
110+
- windows
111+
- shell
112+
variables:
113+
PYTHON_VERSION: "312"
114+
115+
test-windows-313:
116+
<<: *test-template
117+
tags:
118+
- windows
119+
- shell
120+
variables:
121+
PYTHON_VERSION: "313"
122+
123+
# macOS jobs
124+
lint-macos:
125+
<<: *lint-template
126+
tags:
127+
- macos
128+
- shell
129+
130+
test-macos-311:
131+
<<: *test-template
132+
tags:
133+
- macos
134+
- shell
135+
variables:
136+
PYTHON_VERSION: "311"
137+
138+
test-macos-312:
139+
<<: *test-template
140+
tags:
141+
- macos
142+
- shell
143+
variables:
144+
PYTHON_VERSION: "312"
145+
146+
test-macos-313:
147+
<<: *test-template
148+
tags:
149+
- macos
150+
- shell
151+
variables:
152+
PYTHON_VERSION: "313"
153+
154+
# Security checks
155+
security:
156+
stage: security
157+
image: python:3.12-slim
158+
before_script:
159+
- python -m pip install --upgrade pip
160+
- pip install poetry
161+
- poetry config cache-dir $POETRY_CACHE_DIR
162+
- poetry install --with dev
163+
script:
164+
- poetry run tox -e security
165+
artifacts:
166+
reports:
167+
sast: gl-sast-report.json
168+
paths:
169+
- bandit-report.json
170+
- safety-report.json
171+
expire_in: 1 week
172+
only:
173+
- merge_requests
174+
- main
175+
- develop
176+
tags:
177+
- linux
178+
- docker
179+
180+
# Build stage
181+
build:
182+
stage: build
183+
image: python:3.12-slim
184+
before_script:
185+
- python -m pip install --upgrade pip
186+
- pip install poetry
187+
- poetry config cache-dir $POETRY_CACHE_DIR
188+
- poetry install --with dev
189+
script:
190+
- poetry build
191+
- poetry run twine check dist/*
192+
artifacts:
193+
paths:
194+
- dist/
195+
expire_in: 1 week
196+
only:
197+
- main
198+
- develop
199+
tags:
200+
- linux
201+
- docker

0 commit comments

Comments
 (0)