Skip to content

Commit a187466

Browse files
authored
feat: test and publishing setup
feat: test and publishing setup
2 parents f9347da + 3e471cc commit a187466

14 files changed

Lines changed: 1165 additions & 35 deletions

File tree

.github/workflows/build.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Build and Package
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
tags: [ 'v*' ]
7+
workflow_dispatch:
8+
inputs:
9+
publish_to_testpypi:
10+
description: 'Publish to TestPyPI'
11+
required: false
12+
default: false
13+
type: boolean
14+
publish_to_pypi:
15+
description: 'Publish to PyPI'
16+
required: false
17+
default: false
18+
type: boolean
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- name: Set up Python
28+
uses: actions/setup-python@v4
29+
with:
30+
python-version: '3.11'
31+
32+
- name: Install build dependencies
33+
run: |
34+
python -m pip install --upgrade pip
35+
pip install build twine
36+
37+
- name: Install pipenv
38+
run: |
39+
pip install pipenv
40+
41+
- name: Install dependencies
42+
run: |
43+
pipenv install --dev --deploy
44+
45+
- name: Run tests
46+
run: |
47+
pipenv run test
48+
49+
- name: Build package
50+
run: |
51+
python -m build
52+
53+
- name: Check package
54+
run: |
55+
twine check dist/*
56+
57+
- name: Upload build artifacts
58+
uses: actions/upload-artifact@v4
59+
with:
60+
name: python-package-distributions
61+
path: dist/
62+
63+
publish-to-testpypi:
64+
name: Publish to TestPyPI
65+
if: startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish_to_testpypi == 'true')
66+
needs: build
67+
runs-on: ubuntu-latest
68+
environment:
69+
name: testpypi
70+
url: https://test.pypi.org/p/retraction-check
71+
permissions:
72+
id-token: write
73+
74+
steps:
75+
- name: Download build artifacts
76+
uses: actions/download-artifact@v4
77+
with:
78+
name: python-package-distributions
79+
path: dist/
80+
81+
- name: Publish to TestPyPI
82+
uses: pypa/gh-action-pypi-publish@release/v1
83+
with:
84+
repository-url: https://test.pypi.org/legacy/
85+
86+
publish-to-pypi:
87+
name: Publish to PyPI
88+
if: startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish_to_pypi == 'true')
89+
needs: build
90+
runs-on: ubuntu-latest
91+
environment:
92+
name: pypi
93+
url: https://pypi.org/p/retraction-check
94+
permissions:
95+
id-token: write
96+
97+
steps:
98+
- name: Download build artifacts
99+
uses: actions/download-artifact@v4
100+
with:
101+
name: python-package-distributions
102+
path: dist/
103+
104+
- name: Publish to PyPI
105+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/code-quality.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Code Quality
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
code-quality:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: '3.11'
20+
21+
- name: Install pipenv
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install pipenv
25+
26+
- name: Install dependencies
27+
run: |
28+
pipenv install --dev --deploy
29+
30+
- name: Check code formatting
31+
run: |
32+
pipenv run format-check
33+
34+
- name: Run linting
35+
run: |
36+
pipenv run lint
37+
38+
- name: Run type checking
39+
run: |
40+
pipenv run type-check
41+
42+
- name: Run security check (if bandit is available)
43+
run: |
44+
pipenv run python -m pip list | grep bandit || echo "Bandit not installed, skipping security check"
45+
continue-on-error: true

.github/workflows/test.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
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', '3.12']
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
24+
- name: Install pipenv
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install pipenv
28+
29+
- name: Install dependencies
30+
run: |
31+
pipenv install --dev --deploy
32+
33+
- name: Run linting
34+
run: |
35+
pipenv run lint
36+
37+
- name: Run type checking
38+
run: |
39+
pipenv run type-check
40+
41+
- name: Run tests with coverage
42+
run: |
43+
pipenv run test-cov
44+
45+
- name: Upload coverage to Codecov
46+
uses: codecov/codecov-action@v3
47+
with:
48+
file: ./coverage.xml
49+
flags: unittests
50+
name: codecov-umbrella
51+
fail_ci_if_error: false

Pipfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@ bibtexparser = "*"
88
requests = "*"
99

1010
[dev-packages]
11+
pytest = "*"
12+
pytest-cov = "*"
13+
pytest-mock = "*"
14+
black = "*"
15+
flake8 = "*"
16+
mypy = "*"
17+
types-requests = "*"
1118

1219
[requires]
1320
python_version = "3.12"
21+
22+
[scripts]
23+
test = "pytest tests/ -v"
24+
test-cov = "pytest tests/ --cov=retraction_check --cov-report=html --cov-report=term --cov-report=xml"
25+
test-watch = "pytest tests/ -v --tb=short -x"
26+
lint = "flake8 retraction_check/ tests/ --max-line-length=88 --extend-ignore=E203,W503"
27+
format = "black retraction_check/ tests/"
28+
format-check = "black --check retraction_check/ tests/"
29+
type-check = "mypy retraction_check/"
30+
check-all = "bash -c 'pipenv run format-check && pipenv run lint && pipenv run type-check && pipenv run test-cov'"

0 commit comments

Comments
 (0)