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/cross_platform_tests.yml b/.github/workflows/cross_platform_tests.yml new file mode 100644 index 00000000..141c9661 --- /dev/null +++ b/.github/workflows/cross_platform_tests.yml @@ -0,0 +1,35 @@ +# This workflow will run the tests on a variety of operating systems and architectures. + +name: Run tests on low availability Github hosted runners + +on: + # Optionally run only, until the availability of the required Github hosted + # runners does not slow down CI. + workflow_call: + workflow_dispatch: + +jobs: + run_tests: + if: github.repository == 'GeospatialPython/pyshp' + strategy: + fail-fast: false + matrix: + python-version: [ + "3.12", + ] + os: [ + # "macos-12", + "ubuntu-24.04", + # "windows-2022", + ] + + 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 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 70db5f72..9a1fa30a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -13,23 +13,47 @@ on: types: [published] jobs: - deploy: + test: + # 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 this would only test the packaging process, not so much the code as there are + # no binaries. runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: '3.x' + + - name: Run tests and hooks + uses: ./.github/workflows/run_tests_and_hooks.yml + + deploy: + # Prevent deployment of releases that fail any hooks (e.g. linting) or that fail any tests. + needs: test + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + + - 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/build.yml b/.github/workflows/run_tests_and_hooks.yml similarity index 53% rename from .github/workflows/build.yml rename to .github/workflows/run_tests_and_hooks.yml index b9f58955..c8972afa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/run_tests_and_hooks.yml @@ -1,12 +1,12 @@ -# 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 +# This workflow will run the pre-commit hooks (including linters), and the tests with a variety of Python versions -name: build +name: Run pre-commit hooks and tests on: push: pull_request: branches: [ master ] + workflow_call: workflow_dispatch: jobs: @@ -16,8 +16,8 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 - uses: pre-commit/action@v3.0.1 - test: + run_tests_in_containers: strategy: fail-fast: false matrix: @@ -40,14 +40,7 @@ jobs: 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 + + - name: Run tests + uses: ./.github/actions/test +