From bca5d558ac83f64e6067c97c7fcc125773a4f2da Mon Sep 17 00:00:00 2001 From: Antony Lewis Date: Wed, 21 Aug 2024 09:10:06 +0100 Subject: [PATCH] action tests --- .github/workflows/build_wheels.yml | 12 ++-- .github/workflows/test_fortran.yml | 32 ++++++++++ .github/workflows/tests.yml | 63 ++++++++++++++++++++ .travis.yml | 94 ------------------------------ fortran/tests/run_tests.sh | 23 -------- fortran/tests/upload_tests.sh | 24 -------- 6 files changed, 101 insertions(+), 147 deletions(-) create mode 100644 .github/workflows/test_fortran.yml create mode 100644 .github/workflows/tests.yml delete mode 100644 .travis.yml delete mode 100644 fortran/tests/upload_tests.sh diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 248cf43b..0417a91e 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -12,12 +12,12 @@ jobs: os: [ macos-12, macos-13-xlarge, macos-14, ubuntu-latest, windows-latest ] steps: - - uses: fortran-lang/setup-fortran@main - if: matrix.os == 'windows-latest' - id: setup-fortran - with: - compiler: gcc - version: 13 +# - uses: fortran-lang/setup-fortran@main +# if: matrix.os == 'windows-latest' +# id: setup-fortran +# with: +# compiler: gcc +# version: 13 - run: ln -s $(which gfortran-14) /usr/local/bin/gfortran if: matrix.os != 'windows-latest' && matrix.os != 'ubuntu-latest' diff --git a/.github/workflows/test_fortran.yml b/.github/workflows/test_fortran.yml new file mode 100644 index 00000000..e9e88de1 --- /dev/null +++ b/.github/workflows/test_fortran.yml @@ -0,0 +1,32 @@ +name: Build and Test Fortran + +on: + push: + branches-ignore: + - 'test**' + pull_request: + +jobs: + fortran-test: + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != 'cmbant/camb') + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" + + - name: Run Build and Test Script + run: bash fortran/tests/run_tests.sh + + - name: Upload Test Files on Failure + if: failure() + uses: actions/upload-artifact@v4 + with: + name: test-output-${{ github.sha }} + path: fortran/testfiles/ + if-no-files-found: warn diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..057c0737 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,63 @@ +name: tests + +on: [push, pull_request] + +jobs: + tests: + runs-on: ubuntu-latest + if: > + (matrix.os == 'ubuntu-latest' || !startsWith(github.ref, 'refs/heads/test')) && + (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != 'cmbant/camb') + strategy: + fail-fast: false + matrix: + include: + - name: "Latest Python 3.12" + os: ubuntu-latest + python-version: 3.12 + - name: "OS X Python 3.8" + os: macos-latest + python-version: 3.8 + - name: "Windows Python 3.8" + os: windows-latest + python-version: 3.8 + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + allow-prereleases: true + + - run: ln -s $(which gfortran-14) /usr/local/bin/gfortran + if: matrix.os == 'macos-latest' + + - name: flake8 Lint + if: matrix.os == 'ubuntu-latest' + uses: py-actions/flake8@v2 + with: + args: --select=E713,E704,E703,E714,E10,E11,E20,E22,E23,E25,E27,E301,E302,E304,E9,F405,F406,F5,F6,F7,F8,W1,W2,W3,W6 --show-source --statistics + path: camb + max-line-length: "120" + + - name: Install dependencies + run: | + python --version + gfortran --version + pip install -e . + chmod +x fortran/tests/run_tests.sh + + - name: Run tests + run: | + python -c "import camb; print(camb.__version__)" + python -m unittest camb.tests.camb_test + + - name: HM code tests + if: matrix.os == 'ubuntu-latest' + run: | + git clone https://github.com/alexander-mead/HMcode_test_outputs.git + python -m unittest camb.tests.hmcode_test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 45e560dd..00000000 --- a/.travis.yml +++ /dev/null @@ -1,94 +0,0 @@ -os: linux -language: python - -git: - depth: false - -dist: jammy - -branches: - except: - - CAMB_sources - - rayleigh - -if: (type != pull_request) OR (type = pull_request AND TRAVIS_PULL_REQUEST_SLUG != 'cmbant/camb') - -jobs: - include: - - if: branch !~ ^test.* - name: "Focal + Python 3.8" - dist: focal - addons: - apt: - packages: - - gfortran - python: "3.8" - env: - - PYPI_DIST="true" - - if: branch !~ ^test.* - name: "GCC10 + Python anaconda" - dist: focal - addons: - apt: - packages: - - gfortran-10 - env: - - GCC_VERSION="10" - - CHANNEL="defaults" - - PYDIST="ANACONDA" - - FORTRAN="test" - language: minimal - - name: "Jammy + Python 3.12" - if: NOT commit_message =~ /\[pypi\]/ AND NOT commit_message =~ /\[testpypi\]/ - addons: - apt: - packages: - - gfortran - python: "3.12" - - if: branch !~ ^test.* - name: "GCC trunk cosmobox" - language: shell - services: - - docker - before_install: - - if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin; - fi - - docker pull cmbant/cosmobox:devel - install: - - chmod +x fortran/tests/run_tests.sh - script: - - docker run -v $(pwd):/camb -t cmbant/cosmobox:devel /bin/bash -c "cd /camb; fortran/tests/run_tests.sh" - after_failure: - - echo "docker fail" - -install: - - if [[ "$PYDIST" == "ANACONDA" ]]; then - wget -q https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh; - bash miniconda.sh -b -p $HOME/miniconda; - export PATH="$HOME/miniconda/bin:$PATH"; - hash -r; - conda config --set always_yes yes --set changeps1 no; - conda info -a; - conda create -q -n test-environment -c $CHANNEL numpy scipy sympy; - source activate test-environment; - fi - - if [[ "$FORTRAN" == "test" ]]; then - mkdir -p gfortran-symlinks; - ln -s /usr/bin/gfortran-$GCC_VERSION gfortran-symlinks/gfortran; - export PATH=$PWD/gfortran-symlinks:$PATH; - fi - - if [[ "$GCC_VERSION" == "10" ]]; then - export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libgfortran.so.5; - fi - - gfortran --version - - chmod +x fortran/tests/run_tests.sh - - pip install flake8 - -script: - - flake8 camb --select=E713,E704,E703,E714,E10,E11,E20,E22,E23,E25,E27,E301,E302,E304,E9,E741,F405,F406,F5,F6,F7,F8,W1,W2,W3,W6 --show-source --statistics - - fortran/tests/run_tests.sh - -after_failure: - - test $TRAVIS_PULL_REQUEST == "false" && test $PYPI_DIST == "true" && test $TRAVIS_REPO_SLUG == "cmbant/CAMB" && [ -d fortran/testfiles ] && bash fortran/tests/upload_tests.sh - diff --git a/fortran/tests/run_tests.sh b/fortran/tests/run_tests.sh index a487d4e8..eee121a5 100755 --- a/fortran/tests/run_tests.sh +++ b/fortran/tests/run_tests.sh @@ -1,28 +1,5 @@ set -e -gfortran --version -python --version -pip install -e . -python -c "import camb; print(camb.__version__)" -python -m unittest camb.tests.camb_test -rm -Rf HMcode_test_outputs -git clone https://github.com/alexander-mead/HMcode_test_outputs.git -python -m unittest camb.tests.hmcode_test -rm -Rf HMcode_test_outputs -pip uninstall -y camb -rm -Rf dist/* -rm -Rf build/* -rm -f camb/*.so - -case "$TRAVIS_BRANCH" in - devel*) - BRANCH="master" - ;; - *) - BRANCH="master" - ;; -esac - pushd fortran make clean diff --git a/fortran/tests/upload_tests.sh b/fortran/tests/upload_tests.sh deleted file mode 100644 index 1ad35f85..00000000 --- a/fortran/tests/upload_tests.sh +++ /dev/null @@ -1,24 +0,0 @@ -pushd fortran - -git clone -b ${TRAVIS_BRANCH}_travis --depth 1 "https://$GH_TOKEN@github.com/cmbant/CAMB_test_outputs" > /dev/null 2>&1 - -if [ $? -ne 0 ]; then -mkdir CAMB_test_outputs -cd CAMB_test_outputs -git init -git checkout -b ${TRAVIS_BRANCH}_travis -git remote add origin https://$GH_TOKEN@github.com/cmbant/CAMB_test_outputs -else -cd CAMB_test_outputs -fi - -git config user.name "Travis CI" -git config user.email "none@travis" -git rm -r * > /dev/null 2>&1 -cp -r ../testfiles/* . -git add --all . -git commit -m "Travis build $TRAVIS_BUILD_NUMBER for $TRAVIS_BRANCH commit $TRAVIS_COMMIT" -git push --quiet origin ${TRAVIS_BRANCH}_travis -#> /dev/null 2>&1 - -popd \ No newline at end of file