Skip to content

Refactor/update GitHub action #46

Refactor/update GitHub action

Refactor/update GitHub action #46

Workflow file for this run

name: Test and Tag and Publish
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
release:
types: [created]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v3
- 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 build pytest pytest-cov ruff toml
pip install -r requirements.txt
pip install -e .
- name: Lint with ruff
run: |
ruff check .
- name: Test with pytest
run: |
pytest --cov
- name: Build package
run: python -m build
create-tag:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build toml
- name: Get version from pyproject.toml
id: get_version
run: |
version=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
echo "version=$version" >> $GITHUB_OUTPUT
- name: Create and push tag
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git tag -a "v${{ steps.get_version.outputs.version }}" -m "Release v${{ steps.get_version.outputs.version }}"
git push origin "v${{ steps.get_version.outputs.version }}"
publish:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'created'
steps:
- uses: actions/checkout@v3
- 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 pytest pytest-cov ruff twine
pip install -r requirements.txt
pip install -e .
- name: Run tests
run: |
pytest --cov
- name: Build package
run: python -m build
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
python -m twine check dist/*
python -m twine upload --skip-existing dist/*