-
Notifications
You must be signed in to change notification settings - Fork 11
Add test suite, CI/CD pipeline, and PyPI packaging infrastructure #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a134b9c
32b4373
1391076
e8edf1c
7079235
282026e
3326313
4bb8c60
56d4e9f
7ad8536
3e6ebac
b0b26b5
3025402
0d59951
0cd5287
e83a061
94ce668
96aeafd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # GitHub Actions Workflows | ||
|
|
||
| This directory contains the CI/CD workflows for pyDIWASP. | ||
|
|
||
| ## Workflows | ||
|
|
||
| ### CI - Tests and Linting (`ci.yml`) | ||
|
|
||
| This workflow runs automatically on: | ||
| - Push to `main`, `master`, or `develop` branches | ||
| - Pull requests targeting `main`, `master`, or `develop` branches | ||
| - Manual trigger via workflow_dispatch | ||
|
|
||
| **What it does:** | ||
| - Tests the code on Python 3.8, 3.9, 3.10, 3.11, and 3.12 | ||
| - Runs flake8 linting to check code quality | ||
| - Runs the full test suite with pytest | ||
| - Generates code coverage reports | ||
| - Uploads coverage to Codecov (optional) | ||
|
|
||
| ### Publish to PyPI (`publish.yml`) | ||
|
|
||
| This workflow can be triggered: | ||
| - Automatically when a new release is published on GitHub | ||
| - Manually via the Actions tab (workflow_dispatch) | ||
|
|
||
| **What it does:** | ||
| - Builds the Python distribution (sdist and wheel) | ||
| - Validates the distribution with twine | ||
| - Publishes to Test PyPI (if manually triggered with test_pypi=true) | ||
| - Publishes to PyPI (on release or manual trigger with test_pypi=false) | ||
|
|
||
| **Setup Required:** | ||
| To use the PyPI publishing workflow, you need to: | ||
| 1. Create an API token on PyPI (https://pypi.org/manage/account/token/) | ||
| 2. Add the token as a secret named `PYPI_API_TOKEN` in your repository settings | ||
| 3. (Optional) Create a Test PyPI token and add as `TEST_PYPI_API_TOKEN` for testing | ||
|
|
||
| ## Running Tests Locally | ||
|
|
||
| To run the tests locally: | ||
|
|
||
| ```bash | ||
| # Install dependencies | ||
| pip install -r requirements.txt | ||
| pip install pytest pytest-cov flake8 | ||
|
|
||
| # Run tests | ||
| pytest tests/ -v | ||
|
|
||
| # Run tests with coverage | ||
| pytest tests/ -v --cov=. --cov-report=term | ||
|
|
||
| # Run linting | ||
| flake8 . --exclude=.git,__pycache__,.pytest_cache,build,dist,*.egg-info | ||
| ``` | ||
|
|
||
| ## Test Suite | ||
|
|
||
| The test suite includes: | ||
|
|
||
| 1. **Core Tests** (`tests/test_core.py`): | ||
| - Wavenumber calculations | ||
| - Significant wave height calculations | ||
| - Data validation functions | ||
| - Transfer functions (elevation, pressure) | ||
|
|
||
| 2. **API Tests** (`tests/test_api.py`): | ||
| - Spectrum information extraction (infospec) | ||
| - Spectrum interpolation (interpspec) | ||
| - Spectrum file writing (writespec) | ||
|
|
||
| 3. **Integration Tests** (`tests/test_integration.py`): | ||
| - Full directional spectrum analysis workflow | ||
| - Multiple estimation methods (IMLM, EMEP) | ||
| - File I/O operations | ||
| - Peak frequency detection | ||
| - Data validation integration | ||
|
|
||
| **Total: 25 tests** documenting the existing capabilities of pyDIWASP. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| name: CI - Tests and Linting | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main, master, develop ] | ||
| pull_request: | ||
| branches: [ main, master, develop ] | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Test on Python ${{ matrix.python-version }} | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -r requirements.txt | ||
| pip install pytest pytest-cov flake8 | ||
|
|
||
| - name: Lint with flake8 | ||
| run: | | ||
| # Stop the build if there are Python syntax errors or undefined names | ||
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=.git,__pycache__,.pytest_cache,build,dist,*.egg-info | ||
| # Exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude=.git,__pycache__,.pytest_cache,build,dist,*.egg-info | ||
|
|
||
| - name: Run tests with pytest | ||
| run: | | ||
| pytest tests/ -v --cov=. --cov-report=xml --cov-report=term | ||
|
|
||
| - name: Upload coverage to Codecov | ||
| uses: codecov/codecov-action@v4 | ||
| if: matrix.python-version == '3.11' | ||
| with: | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
| file: ./coverage.xml | ||
| flags: unittests | ||
| name: codecov-umbrella | ||
| fail_ci_if_error: false | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| name: Publish to PyPI | ||
|
|
||
| on: | ||
| release: | ||
| types: [published] | ||
| workflow_dispatch: | ||
| inputs: | ||
| test_pypi: | ||
| description: 'Publish to Test PyPI instead of PyPI' | ||
| required: false | ||
| default: 'true' | ||
| type: boolean | ||
|
|
||
| jobs: | ||
| build-and-publish: | ||
| name: Build and publish Python distribution to PyPI | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
|
|
||
| - name: Install build dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install build twine | ||
|
|
||
| - name: Build distribution | ||
| run: | | ||
| python -m build | ||
|
|
||
| - name: Check distribution | ||
| run: | | ||
| twine check dist/* | ||
|
|
||
| - name: Publish to Test PyPI | ||
| if: github.event_name == 'workflow_dispatch' && inputs.test_pypi | ||
| continue-on-error: true | ||
| env: | ||
| TWINE_USERNAME: __token__ | ||
| TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }} | ||
| run: | | ||
| twine upload --repository testpypi dist/* | ||
|
Comment on lines
41
to
48
|
||
|
|
||
| - name: Publish to PyPI | ||
| if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && !inputs.test_pypi) | ||
| env: | ||
| TWINE_USERNAME: __token__ | ||
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | ||
| run: | | ||
| twine upload dist/* | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov action v4 typically requires a CODECOV_TOKEN to be set in repository secrets for uploads to work. Without this token, the upload step will fail (though fail_ci_if_error is set to false, so it won't block the CI). Consider either: 1) adding documentation about setting up the CODECOV_TOKEN secret, 2) adding a token parameter to the action configuration, or 3) removing this step if Codecov integration is not needed. See the Codecov documentation for details on setting up tokens with v4.