From e389b0090d5170931f4bb41514769e46b78552c7 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Sat, 9 Nov 2024 20:19:55 -0700 Subject: [PATCH] Set up CI with GitHub Actions --- .github/workflows/lint.yml | 32 +++++++++++++++++++++ .github/workflows/test.yml | 58 ++++++++++++++++++++++++++++++++++++++ .travis.yml | 41 --------------------------- 3 files changed, 90 insertions(+), 41 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..fbfb9f8 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,32 @@ +name: Lint + +on: [push, pull_request] + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + + lint: + name: Check for lint and format code to a standard style + if: + github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: conda-incubator/setup-miniconda@v3 + with: + miniforge-version: latest + python-version: 3.12 + auto-activate-base: false + + - name: Install black and flake8 + run: pip install black flake8 + + - name: Format code + run: | + flake8 . + black . diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..1db0bba --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,58 @@ +name: Test + +on: [push, pull_request] + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + + test: + name: Run unit tests + if: + github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository + + runs-on: ${{ matrix.os }} + + defaults: + run: + shell: bash -l {0} + + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + python-version: ["3.10", "3.11", "3.12", "3.13"] + + steps: + - uses: actions/checkout@v4 + + - uses: conda-incubator/setup-miniconda@v3 + with: + miniforge-version: latest + activate-environment: gridmet_bmi + environment-file: environment.yml + python-version: ${{ matrix.python-version }} + + - name: Show conda installation info + run: | + conda info + conda list + + - name: Build and install package + run: | + make install + + - name: Run unit tests + run: | + make test + + - name: Test BMI + if: ${{ matrix.python-version == '3.12' }} + run: | + make test-bmi + + - name: Run examples + working-directory: ${{ github.workspace }}/examples + run: | + python debug.py diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a8ba358..0000000 --- a/.travis.yml +++ /dev/null @@ -1,41 +0,0 @@ -language: generic -os: - - linux - - osx -env: - matrix: - - CONDA_ENV="3.8" - - CONDA_ENV="3.9" - global: - - CONDA_PREFIX=$HOME/conda - - MINICONDA_URL_BASE="https://repo.anaconda.com/miniconda/Miniconda3-latest" -jobs: - include: - - stage: lint - os: linux - script: - - pip install flake8 - - make lint -before_install: - - | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - OS="MacOSX-x86_64" - else - OS="Linux-x86_64" - fi - - curl $MINICONDA_URL_BASE-$OS.sh > $HOME/miniconda.sh - - bash $HOME/miniconda.sh -b -p $CONDA_PREFIX - - export PATH="$CONDA_PREFIX/bin:$PATH" - - hash -r - - conda config --set always_yes yes --set changeps1 no - - conda create -n test_env python=$CONDA_ENV --file=requirements.txt -c conda-forge - - source activate test_env - - conda info -a && conda list -install: - - pip install -e . -before_script: -- conda install --file=requirements-testing.txt -c conda-forge -script: - - pytest --cov=gridmet_bmi --cov-report=xml:$(pwd)/coverage.xml -vvv - - bmi-test gridmet_bmi:BmiGridmet --config-file=./examples/gridmet_bmi.yaml --root-dir=./examples -vvv -after_success: coveralls