Skip to content

Fix ControlSerial package/module naming and update test patch targets #4

Fix ControlSerial package/module naming and update test patch targets

Fix ControlSerial package/module naming and update test patch targets #4

Workflow file for this run

name: Tests and Release
on:
push:
branches: [ main, master, develop ]
tags:
- 'v*'
pull_request:
branches: [ main, master ]
jobs:
test:
name: Run Tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04, windows-latest, macos-latest]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
exclude:
# Optional: exclude some combinations to speed up
- os: macos-latest
python-version: '3.7'
- os: macos-latest
python-version: '3.8'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for better debugging
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Install package
run: |
pip install -e .
- name: Verify installation
run: |
python -c "import ControlSerial; print('ControlSerial imported successfully')"
python -c "import crc8; print('crc8 imported successfully')"
- name: Run tests with pytest
run: |
pytest tests/ -v --cov=ControlSerial --cov-report=xml --cov-report=term
continue-on-error: false
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests
name: codecov-${{ matrix.os }}-py${{ matrix.python-version }}
fail_ci_if_error: false
- name: Run tests with unittest (fallback)
if: failure()
run: |
cd ${{ github.workspace }}
python -m pip install -r requirements-dev.txt
python tests/run_tests.py
lint:
name: Code Quality Checks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install linting tools
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Check code formatting with black
run: |
black --check ControlSerial/ tests/
continue-on-error: true
- name: Check import sorting with isort
run: |
isort --check-only ControlSerial/ tests/
continue-on-error: true
- name: Lint with flake8
run: |
# Stop the build if there are Python syntax errors or undefined names
flake8 ControlSerial/ tests/ --count --select=E9,F63,F7,F82 --show-source --statistics
# Exit-zero treats all errors as warnings
flake8 ControlSerial/ tests/ --count --exit-zero --max-complexity=10 --max-line-length=100 --statistics
continue-on-error: true
release:
name: Create Draft Release
needs: [test, lint]
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
run: |
python -m build
- name: Get tag name
id: tag_name
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Generate release notes
id: release_notes
run: |
# Get commits since last tag
PREVIOUS_TAG=$(git describe --abbrev=0 --tags $(git rev-list --tags --skip=1 --max-count=1) 2>/dev/null || echo "")
if [ -z "$PREVIOUS_TAG" ]; then
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges)
else
COMMITS=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges)
fi
# Create release notes
cat > release_notes.md << EOF
# ControlSerial ${{ steps.tag_name.outputs.TAG }}
## What's Changed
${COMMITS}
## Installation
\`\`\`bash
pip install ControlSerial==${{ steps.tag_name.outputs.TAG }}
\`\`\`
Or install from source:
\`\`\`bash
git clone https://github.com/${{ github.repository }}.git
cd ControlSerial
git checkout ${{ steps.tag_name.outputs.TAG }}
pip install -e .
\`\`\`
## Testing
All tests have passed on Python 3.7-3.11 across Linux, Windows, and macOS.
## Zenodo Archival
This release will be automatically archived on Zenodo. The DOI will be available shortly after publication.
## Full Changelog
See [CHANGELOG.md](CHANGELOG.md) for complete details.
EOF
cat release_notes.md
- name: Create Draft Release
uses: softprops/action-gh-release@v1
with:
draft: true
prerelease: false
name: Release ${{ steps.tag_name.outputs.TAG }}
body_path: release_notes.md
files: |
dist/*
LICENSE
README.md
tests/README.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Post-release instructions
run: |
echo "::notice title=Draft Release Created::A draft release has been created. Review it at https://github.com/${{ github.repository }}/releases"
echo "::notice title=Next Steps::1. Review the draft release, 2. Publish it, 3. Zenodo will automatically archive it, 4. Update documentation with the Zenodo DOI"
notify:
name: Notification
needs: [test, lint]
if: failure()
runs-on: ubuntu-latest
steps:
- name: Notify on failure
run: |
echo "::error title=Tests Failed::Some tests failed. Please check the workflow logs."