Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .github/workflows/README.md
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.
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
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
Comment on lines 45 to 53
Copy link

Copilot AI Feb 3, 2026

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.

Copilot uses AI. Check for mistakes.
56 changes: 56 additions & 0 deletions .github/workflows/publish.yml
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
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Publish to Test PyPI" step will fail if TEST_PYPI_API_TOKEN secret is not configured and a user manually triggers the workflow with test_pypi=true. Consider adding a condition to check if the secret exists before attempting upload, or document clearly in the workflow README that this secret must be configured for Test PyPI functionality. Alternatively, you could use 'continue-on-error: true' for this step.

Copilot uses AI. Check for mistakes.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in commit e83a061. Added continue-on-error: true to the Test PyPI upload step.


- 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/*
57 changes: 10 additions & 47 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
*.manifest
Expand All @@ -31,48 +34,17 @@ wheels/
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
Expand All @@ -82,20 +54,7 @@ ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

# IDEs
# IDE
.vscode/
.idea/
*.swp
Expand All @@ -105,3 +64,7 @@ venv.bak/
# OS
.DS_Store
Thumbs.db

# Temporary files
/tmp/
*.tmp
Loading