|
| 1 | +name: Build and Test |
| 2 | +# 1. Build and test WecOptTool |
| 3 | +# - check that WecOptTool builds on a matrix of OS + Python versions |
| 4 | +# - check that all tests pass on the same matrix |
| 5 | +# - report the test code coverage |
| 6 | +# 2. Check that the documentation builds correctly |
| 7 | + |
| 8 | +on: |
| 9 | + pull_request: |
| 10 | + branches: [ main, dev ] |
| 11 | + |
| 12 | +jobs: |
| 13 | + wecopttool_test: |
| 14 | + name: Build (${{ matrix.python-version }}, ${{ matrix.os }}) |
| 15 | + runs-on: ${{ matrix.os }} |
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + os: ["ubuntu-latest", "macos-latest", "windows-latest"] |
| 20 | + python-version: ["3.10", "3.11"] # CHANGE: Python version |
| 21 | + |
| 22 | + steps: |
| 23 | + # Checkout the WecOptTool repo |
| 24 | + - uses: actions/checkout@v3 |
| 25 | + |
| 26 | + # Cache the conda environment >>> |
| 27 | + # The cache key includes the OS, the date, the hash of the pyproject.toml file, and the cache number. |
| 28 | + # A new cache is created if: |
| 29 | + # - this is the first time today that this file is run (date changes) |
| 30 | + # - the content of pyproject.toml changes |
| 31 | + # - you manually change the value of the CACHE_NUMBER below |
| 32 | + # Else the existing cache is used. |
| 33 | + - name: Setup Mambaforge |
| 34 | + uses: conda-incubator/setup-miniconda@v2 |
| 35 | + with: |
| 36 | + miniforge-variant: Mambaforge |
| 37 | + miniforge-version: latest |
| 38 | + activate-environment: test-env |
| 39 | + use-mamba: true |
| 40 | + |
| 41 | + # save the date to include in the cache key |
| 42 | + - name: Get Date |
| 43 | + id: get-date |
| 44 | + run: echo "DATE=$(/bin/date -u '+%Y%m%d')" >> $GITHUB_ENV |
| 45 | + shell: bash |
| 46 | + |
| 47 | + # create a conda yaml file |
| 48 | + # for some reason Windows installs capytaine 1.4 instead of latest. |
| 49 | + # CHANGE: Capytaine version |
| 50 | + - name: Create environment.yml file |
| 51 | + run: | |
| 52 | + echo "name: test-env" >> environment.yml; |
| 53 | + echo " " >> environment.yml |
| 54 | + echo "dependencies:" >> environment.yml |
| 55 | + echo " - python=${{ matrix.python-version }}" >> environment.yml |
| 56 | + echo " - capytaine" >> environment.yml |
| 57 | + echo " - wavespectra" >> environment.yml |
| 58 | + cat environment.yml |
| 59 | +
|
| 60 | + # use the cache if it exists |
| 61 | + - uses: actions/cache@v3 |
| 62 | + env: |
| 63 | + CACHE_NUMBER: 0 # increase to reset cache manually |
| 64 | + with: |
| 65 | + path: ${{ env.CONDA }}/envs |
| 66 | + key: conda-${{ runner.os }}--${{ runner.arch }}--${{ env.DATE }}-${{ hashFiles('pyproject.toml') }}-${{ env.CACHE_NUMBER }} |
| 67 | + id: cache |
| 68 | + |
| 69 | + # if cache key has changed, create new cache |
| 70 | + - name: Update environment |
| 71 | + run: mamba env update -n test-env -f environment.yml |
| 72 | + if: steps.cache.outputs.cache-hit != 'true' |
| 73 | + # <<< Cache the conda environment |
| 74 | + |
| 75 | + # install libglu on ubuntu. |
| 76 | + - name: Install libglu |
| 77 | + if: matrix.os == 'ubuntu-latest' |
| 78 | + run: sudo apt-get install libglu1 |
| 79 | + |
| 80 | + # install WecOptTool, pytest/coveralls, and gmsh/pygmsh |
| 81 | + - name: Install WecOptTool |
| 82 | + shell: bash -l {0} |
| 83 | + run: | |
| 84 | + conda activate test-env |
| 85 | + python3 -m pip install --upgrade pip |
| 86 | + pip3 install gmsh pygmsh coveralls pytest |
| 87 | + pip3 install . |
| 88 | +
|
| 89 | + # run all tests & coverage |
| 90 | + - name: Run Test |
| 91 | + shell: bash -l {0} |
| 92 | + run: coverage run -m pytest |
| 93 | + |
| 94 | + # upload coverage data |
| 95 | + - name: Upload coverage data to coveralls.io |
| 96 | + shell: bash -l {0} |
| 97 | + run: coveralls --service=github |
| 98 | + env: |
| 99 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 100 | + COVERALLS_FLAG_NAME: ${{ matrix.os }}-${{ matrix.python-version }} |
| 101 | + COVERALLS_PARALLEL: true |
| 102 | + |
| 103 | + |
| 104 | + coveralls: |
| 105 | + name: Indicate completion to coveralls.io |
| 106 | + needs: wecopttool_test |
| 107 | + runs-on: ubuntu-latest |
| 108 | + container: python:3-slim |
| 109 | + steps: |
| 110 | + - name: Finished |
| 111 | + run: | |
| 112 | + pip3 install --upgrade coveralls |
| 113 | + coveralls --finish |
| 114 | + env: |
| 115 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 116 | + |
| 117 | + |
| 118 | + documentation_test: |
| 119 | + name: Build documentation |
| 120 | + runs-on: ubuntu-latest |
| 121 | + |
| 122 | + steps: |
| 123 | + - uses: actions/checkout@v3 |
| 124 | + - uses: actions/setup-python@v4 |
| 125 | + with: |
| 126 | + python-version: '3.11' # CHANGE: Python version |
| 127 | + |
| 128 | + - name: Install dependencies |
| 129 | + run: sudo apt-get install libglu1 pandoc gifsicle |
| 130 | + |
| 131 | + - name: Install WecOptTool for documentation |
| 132 | + shell: bash -l {0} |
| 133 | + run: | |
| 134 | + python3 -m pip install --upgrade pip |
| 135 | + pip3 install wheel coveralls |
| 136 | + pip3 install .[dev,geometry] |
| 137 | +
|
| 138 | + - name: Build documentation |
| 139 | + shell: bash -l {0} |
| 140 | + run: | |
| 141 | + git fetch --tags |
| 142 | + python3 docs/build_docs.py |
0 commit comments