diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml new file mode 100644 index 00000000..86ec93f3 --- /dev/null +++ b/.github/actions/test/action.yml @@ -0,0 +1,33 @@ +name: + Test + +description: + Run pytest, and run the doctest runner (shapefile.py as a script). + +runs: + using: "composite" + steps: + # The Repo is required to already be checked out, e.g. by the calling workflow + + # The Python to be tested with is required to already be setup, with "python" and "pip" on the system Path + + - name: Doctests + shell: bash + run: python shapefile.py + + - name: Install test dependencies. + shell: bash + run: | + python -m pip install --upgrade pip + pip install -r requirements.test.txt + + - name: Pytest + shell: bash + run: | + pytest + + - name: Show versions for logs. + shell: bash + run: | + python --version + python -m pytest --version \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index b9f58955..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,53 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: build - -on: - push: - pull_request: - branches: [ master ] - workflow_dispatch: - -jobs: - pre-commit: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - - uses: pre-commit/action@v3.0.1 - test: - - strategy: - fail-fast: false - matrix: - python-version: [ - "2.7", - "3.5", - "3.6", - "3.7", - "3.8", - "3.9", - "3.10", - "3.11", - "3.12", - "3.13.0a2", - ] - - runs-on: ubuntu-latest - container: - image: python:${{ matrix.python-version }}-slim - - steps: - - uses: actions/checkout@v4 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install pytest - if [ -f requirements.test.txt ]; then pip install -r requirements.test.txt; fi - - name: Test with doctest - run: | - python shapefile.py - - name: Test with pytest - run: | - pytest diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 70db5f72..057d8179 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -23,13 +23,24 @@ jobs: uses: actions/setup-python@v2 with: python-version: '3.x' + + # In general tests should be run after building a distribution, to test that distribution. + # However as long as PyShp is a pure Python library, with pure Python deps (or no deps) + # then it's not crucial. + + # Prevent deployment of releases that fail any hooks (e.g. linting) or that fail any tests. + - name: Run tests and hooks + uses: ./.github/workflows/run_tests_and_hooks.yml + - name: Install dependencies run: | python -m pip install --upgrade pip pip install build - name: Build package run: python -m build + - name: Publish package + if: github.repository == 'GeospatialPython/pyshp' uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 with: user: __token__ diff --git a/.github/workflows/run_tests_and_hooks.yml b/.github/workflows/run_tests_and_hooks.yml new file mode 100644 index 00000000..438813d1 --- /dev/null +++ b/.github/workflows/run_tests_and_hooks.yml @@ -0,0 +1,75 @@ +# This workflow will run the pre-commit hooks (including linters), and the tests with a variety of Python versions + +name: Run pre-commit hooks and tests + +on: + push: + pull_request: + branches: [ master ] + workflow_call: + workflow_dispatch: + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - uses: pre-commit/action@v3.0.1 + + test_in_slim_Python_containers: + strategy: + fail-fast: false + matrix: + python-version: [ + "2.7", + "3.5", + "3.6", + "3.7", + "3.8", + "3.9", + "3.10", + "3.11", + "3.12", + "3.13.0a2", + ] + + runs-on: ubuntu-latest + container: + image: python:${{ matrix.python-version }}-slim + + steps: + - uses: actions/checkout@v4 + + - name: Run tests + uses: ./.github/actions/test + + + test_on_MacOS_and_Windows: + if: github.repository == 'GeospatialPython/pyshp' + strategy: + fail-fast: false + matrix: + python-version: [ + "3.12", + ] + os: [ + "macos-latest", + "windows-latest", + ] + # include: + # - os: "windows-latest" + # python-version: "3.13" + # - os: "macos-latest" + # python-version: "3.13" + + runs-on: matrix.os + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python_version }} + + - name: Run tests + uses: ./.github/actions/test