From efaf05b54ba49fd8ea567d7de6d3bd266a83f403 Mon Sep 17 00:00:00 2001 From: Maurice McCabe Date: Mon, 2 Sep 2024 18:50:59 -0700 Subject: [PATCH] Feature logging (#2) * logging, error handling, comments * bump version * missing build dependency * trigger build in PR and publish in master * version handling * missing dependency --- .github/workflows/publish-to-pypi.yml | 46 +++++++++++++++++++++++---- setup.py | 1 + version.py | 2 ++ 3 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 version.py diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index d4c5ad0..fb4cea4 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -1,12 +1,16 @@ -name: Publish Python Package +name: Build and Test Python Package on: + pull_request: + branches: + - '**' # Triggers on all branches with open PRs + push: branches: - - master + - master # Triggers on pushes to the main branch jobs: - build-and-publish: + build-and-test: runs-on: ubuntu-latest steps: @@ -19,18 +23,48 @@ jobs: python-version: '3.x' - name: Install dependencies - run: pip install -r requirements.txt + run: | + pip install setuptools wheel + pip install -r requirements.txt - name: Get current version id: get_version run: | - VERSION=$(python -c "exec(open('setup.py').read()); print(__version__)") + VERSION=$(python -c "from version import __version__; print(__version__)") echo "VERSION=$VERSION" >> $GITHUB_ENV - name: Build the package run: | python setup.py sdist bdist_wheel + # - name: Run tests + # run: | + # pip install pytest + # pytest + + publish-and-tag: + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + needs: build-and-test + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install dependencies + run: | + pip install setuptools wheel + pip install -r requirements.txt + + - name: Build the package + run: | + python setup.py sdist bdist_wheel + - name: Publish to PyPI env: TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} @@ -40,10 +74,8 @@ jobs: twine upload dist/* - name: Create Git tag - if: success() run: | git config user.name "GitHub Actions" git config user.email "actions@github.com" git tag -a v${{ env.VERSION }} -m "Release version ${{ env.VERSION }}" git push origin v${{ env.VERSION }} - diff --git a/setup.py b/setup.py index 87d03f8..cffd4ea 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ from setuptools import setup, find_packages +from version import __version__ __version__ = "0.2.0" diff --git a/version.py b/version.py new file mode 100644 index 0000000..c26f122 --- /dev/null +++ b/version.py @@ -0,0 +1,2 @@ +# version.py +__version__ = "0.2.0"