From 1c73485a60e10de920746a7ba309d29c3f199f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Sat, 30 Sep 2023 18:50:17 +0200 Subject: [PATCH] TST: test on GHA --- .circleci/config.yml | 230 ------------------------------ .github/workflows/build-test.yaml | 89 ++++++++++++ 2 files changed, 89 insertions(+), 230 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/build-test.yaml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index b5d98335..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,230 +0,0 @@ -version: 2.1 - -commands: - set-env: - description: "Set environment variables." - steps: - - run: - name: "Set environment variables." - command: | - echo 'export ROCKSTAR_DIR=$HOME/rockstar-galaxies' >> $BASH_ENV - echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROCKSTAR_DIR' >> $BASH_ENV - echo 'export YT_DATA=$HOME/yt_test' >> $BASH_ENV - - install-with-yt-dev: - description: "Install dependencies with yt from source." - steps: - - run: - name: "Install dependencies with yt from source." - command: | - set -x - source $BASH_ENV - sudo apt update - sudo apt upgrade - sudo apt install -y dvipng texlive-latex-extra - sudo apt install -y libopenmpi-dev openmpi-bin gcc-9 - python -m venv $HOME/venv - source $HOME/venv/bin/activate - python -m pip install --upgrade pip - pip install mpi4py - export MAX_BUILD_CORES=2 - python -m pip install git+https://github.com/yt-project/yt - - export YT_ASTRO_DIR=$(pwd) - # install rockstar - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 100 - if [ ! -f $ROCKSTAR_DIR/VERSION ]; then - git clone https://bitbucket.org/pbehroozi/rockstar-galaxies $ROCKSTAR_DIR - pushd $ROCKSTAR_DIR - - # apply patches necessary for compat with Ubuntu 22.04 - git apply $YT_ASTRO_DIR/rockstar-patches/cflags.patch --whitespace=fix - - make lib - popd - fi - echo $ROCKSTAR_DIR > rockstar.cfg - - # never attempt to build h5py from source - python -m pip install h5py --only-binary h5py - - # install yt_astro_analysis with extra dev dependencies - python -m pip install . - python -m pip install --requirement requirements/tests.txt - - # configure yt - mkdir -p $HOME/.config/yt # avoid a warning from yt - yt config set --global yt suppress_stream_logging True - yt config set --global yt test_data_dir $YT_DATA - yt config set --global yt log_level 30 - - download-test-data: - description: "Download test data." - steps: - - run: - name: "Download test data." - no_output_timeout: 20m - command: | - if [ ! -f $YT_DATA/enzo_tiny_cosmology/DD0046/DD0046 ]; then - source $BASH_ENV - source $HOME/venv/bin/activate - mkdir -p $YT_DATA - girder-cli --api-url https://girder.hub.yt/api/v1 download 577c09480d7c6b0001ad5be2 $YT_DATA/enzo_tiny_cosmology - fi - - build-and-test: - description: "Build yt_astro_analysis and run tests (pytest)." - steps: - - run: - name: "Build yt_astro_analysis and run tests." - command: | - source $BASH_ENV - source $HOME/venv/bin/activate - python -m pip install -e . - pytest --color=yes -ra -s - - build-docs: - description: "Test the docs build." - steps: - - run: - name: "Test the docs build." - command: | - source $HOME/venv/bin/activate - python -m pip install --upgrade pip - python -m pip install --requirement requirements/docs.txt - cd doc/source - python -m sphinx -M html "." "_build" -W - -executors: - python: - parameters: - tag: - type: string - default: latest - docker: - - image: cimg/python:<< parameters.tag >> - -jobs: - run-tests: - parameters: - tag: - type: string - default: latest - executor: - name: python - tag: << parameters.tag >> - - working_directory: ~/yt_astro_analysis - - steps: - - checkout - - set-env - - - restore_cache: - name: "Restore dependencies cache." - key: python-<< parameters.tag >>-dependencies-bonxie - - - install-with-yt-dev - - - save_cache: - name: "Save dependencies cache" - key: python-<< parameters.tag >>-dependencies-bonxie - paths: - - ~/.cache/pip - - ~/venv - - ~/yt-git - - ~/rockstar-galaxies - - - restore_cache: - name: "Restore test data cache." - key: test-data-bonxie - - - download-test-data - - - save_cache: - name: "Save test data cache." - key: test-data-bonxie - paths: - - ~/yt_test - - - restore_cache: - name: "Restore test answers." - key: python-<< parameters.tag >>-test-answers-bonxie-pytest - - - build-and-test - - - save_cache: - name: "Save test answers cache." - key: python-<< parameters.tag >>-test-answers-bonxie-pytest - paths: - - ~/test_results - - docs-test: - parameters: - tag: - type: string - default: latest - executor: - name: python - tag: << parameters.tag >> - - working_directory: ~/yt_astro_analysis - - steps: - - checkout - - set-env - - - restore_cache: - name: "Restore dependencies cache." - key: python-<< parameters.tag >>-dependencies-bonxie - - - install-with-yt-dev - - - save_cache: - name: "Save dependencies cache" - key: python-<< parameters.tag >>-dependencies-bonxie - paths: - - ~/.cache/pip - - ~/venv - - ~/yt-git - - ~/rockstar-galaxies - - - build-docs - -workflows: - version: 2 - - normal-tests: - jobs: - - run-tests: - name: "Python 3.9 tests" - tag: "3.9" - - - run-tests: - name: "Python 3.11 tests" - tag: "3.11" - - - docs-test: - name: "Test docs build" - tag: "3.9" - - weekly: - triggers: - - schedule: - cron: "0 0 * * 2" - filters: - branches: - only: - - main - jobs: - - run-tests: - name: "Python 3.9 tests" - tag: "3.9" - - - run-tests: - name: "Python 3.11 tests" - tag: "3.11" - - - docs-test: - name: "Test docs build" - tag: "3.9" diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml new file mode 100644 index 00000000..1e5b88fb --- /dev/null +++ b/.github/workflows/build-test.yaml @@ -0,0 +1,89 @@ +name: Build and Test + +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + schedule: + # run this every Wednesday at 3 am UTC + - cron: 0 3 * * 3 + +jobs: + + get_yt_data: + runs-on: ubuntu-latest + steps: + - name: Fetch yt data + run: | + pipx run girder-client \ + --api-url https://girder.hub.yt/api/v1 \ + download 577c09480d7c6b0001ad5be2 enzo_tiny_cosmology + + - run: ls enzo_tiny_cosmology + + - uses: actions/upload-artifact@v3 + with: + name: enzo_tiny_cosmology + path: enzo_tiny_cosmology + + build: + name: "py${{ matrix.python-version }} on ${{ matrix.os }}" + needs: + - get_yt_data + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + python-version: + - '3.9' + - '3.10' + - '3.11' + + runs-on: ${{ matrix.os }} + + concurrency: + # auto-cancel any in-progress job *on the same branch* + group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.tests-type }}-py${{ matrix.python-version }}-${{ matrix.os }}-${{ matrix.test-runner }} + cancel-in-progress: true + + steps: + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Checkout repo + uses: actions/checkout@v3 + - name: Set up Conda + uses: s-weigand/setup-conda@v1 + with: + update-conda: true + conda-channels: conda-forge + activate-conda: true + python-version: ${{matrix.python-version}} + + - name: Build + run: | + conda install rockstar-galaxies yt h5py + conda install --file=requirements/tests.txt --yes + python -m pip install -e . --no-deps + + - run: python -m pip list + + - name: Configure yt + run: | + yt config set --local yt test_data_dir $(pwd)/yt_data + yt config set --local yt suppress_stream_logging True + yt config set --local yt log_level 30 + + - run: cat yt.toml + + - uses: actions/download-artifact@v3 + with: + name: enzo_tiny_cosmology + path: yt_data/enzo_tiny_cosmology + + - run: ls yt_data/enzo_tiny_cosmology + - run: pytest --color=yes -ra