Skip to content

Commit

Permalink
Merge pull request #300 from GeospatialPython/Refactor_workflows
Browse files Browse the repository at this point in the history
Refactor workflows to support testing before deployment, and testing on Windows and MacOS.
  • Loading branch information
JamesParrott authored Sep 17, 2024
2 parents 89498e4 + 4724d21 commit 295db9b
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 17 deletions.
33 changes: 33 additions & 0 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions .github/workflows/cross_platform_tests.yml
Original file line number Diff line number Diff line change
@@ -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
28 changes: 26 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand All @@ -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

0 comments on commit 295db9b

Please sign in to comment.