Run Tests: branch main by fyellin #235
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run Tests | |
run-name: "Run Tests: ${{ github.ref_type }} ${{ github.ref_name }} by ${{ github.triggering_actor }}" | |
on: | |
workflow_dispatch: | |
pull_request: | |
branches: [ main ] | |
push: | |
branches: [ main ] | |
schedule: | |
- cron: "20 11 * * 0" | |
jobs: | |
test: | |
name: Test cspyce | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
python-version: [ '3.9', '3.10', '3.11', '3.12' ] | |
fail-fast: false | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Get swig on MacOS | |
if: matrix.os == 'macos-latest' | |
run: | | |
brew update | |
brew install swig | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
python -m pip install -r requirements.txt | |
- name: Cache CSPICE source code | |
uses: actions/cache@v3 | |
env: | |
cache-name: cspice-source-code | |
with: | |
path: cspice | |
# If setup.py is modified, we want to invalidate the cache. It means that there | |
# has been some change to the build process (a new Spice version??) and we want | |
# to make sure new sources are pulled. | |
key: ${{ matrix.os }}-${{ runner.arch }}-${{ env.cache-name }}-${{ hashFiles('setup.py') }} | |
- name: Generate cspyce | |
run: | | |
python setup.py generate | |
- name: Determine compiler version for non-Windows | |
if: matrix.os != 'windows-latest' | |
run: | | |
gcc --version > compiler-version.txt | |
cat compiler-version.txt | |
- name: Determine compiler version for Windows | |
if: matrix.os == 'windows-latest' | |
# We ask Python what it uses as the compiler. I can't find anything simpler. | |
run: | | |
python3 -c 'import distutils.ccompiler as cc; x = cc.new_compiler(); x.initialize(); print(x.cc)' > compiler-version.txt | |
cat compiler-version.txt | |
- name: Cache libraries | |
id: cache-libraries | |
uses: actions/cache@v3 | |
env: | |
cache-name: cspice-libraries | |
with: | |
path: build/ | |
# We need to rebuild the cspice library if the source files have changed, | |
# if there is some change in the build process, or if the compiler version | |
# has changed. | |
key: ${{ matrix.os }}-${{ runner.arch }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('setup.py', 'compiler-version.txt', 'cspice/**/*') }} | |
- name: Compile C libraries | |
if: ${{ steps.cache-libraries.outputs.cache-hit != 'true' }} | |
run: | | |
python setup.py build_clib | |
- name: Build extensions | |
run: | | |
python setup.py build_ext --inplace | |
- name: Install cspyce | |
run: | | |
python -m pip install . | |
# We want to test operation with NumPy 1.x without needing a whole new matrix, | |
# so we arbitrarily choose that 3.10 should use 1.x instead of 2.x | |
- name: Maybe revert to NumPy 1.26 | |
if: matrix.python-version == '3.10' | |
run: | | |
python -m pip uninstall -y numpy | |
python -m pip install numpy==1.26.4 | |
- name: Test with coverage | |
run: | | |
pytest -v -rA --cov=./ --cov-report=xml | |
- name: Upload coverage report to codecov | |
uses: codecov/codecov-action@v4 | |
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12' | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
verbose: true |