소스 검색

Add GitHub Actions to build, run tests, and Python static code analysis (#525)

This adds a CI workflow with build and test running on Ubuntu 16.04 and 18.04. The build job is not parallelized and is meant for clear and relatively fast check of compilation and building in general. This way it is clear if the compilation failed when the test job failed without examining the output. (Duplicating what is currently running on Travis.)

The test job needs to build first, but the main focus is to run tests, so the compilation is parallelized (depending on nproc) and thus potentially less readable. This runs the whole test suite. Failing tests (file names) are displayed.

The test job requires at least 50% success rate (using the --min-success flag). There is currently 45% of tests failing. Test uses nc_spm_full_v2alpha2 location from fatra.cnr.ncsu.edu for tests.

Additional work flow adds a static code analysis/code quality check/linting using Flake8 for Python code in lib/python, gui/wxpython, scripts and temporal directories (separately). As an experiment, who approaches are employed in dealing with current errors. lib/python uses a configuration file which ignores code in testsuite directories and ignores a lot of errors specified in the configuration. The other directories use the default settings and the failure is ignored using GitHub Actions configuration.

Helper files are placed to .github/workflows (possibly to be moved if general enough).
Vaclav Petras 5 년 전
부모
커밋
4bb3a3ad88
7개의 변경된 파일327개의 추가작업 그리고 0개의 파일을 삭제
  1. 18 0
      .github/workflows/apt.txt
  2. 46 0
      .github/workflows/build.sh
  3. 75 0
      .github/workflows/ci.yml
  4. 85 0
      .github/workflows/flake8.yml
  5. 6 0
      .github/workflows/test_simple.sh
  6. 14 0
      .github/workflows/test_thorough.sh
  7. 83 0
      lib/python/.flake8

+ 18 - 0
.github/workflows/apt.txt

@@ -0,0 +1,18 @@
+bison
+build-essential
+flex
+libbz2-dev
+libcairo-dev
+libfftw3-dev
+libgdal-dev
+libgl1-mesa-dev
+libglu1-mesa-dev
+libnetcdf-dev
+libopenblas-dev
+libpng-dev
+libproj-dev
+libreadline-dev
+libzstd-dev
+python3-six
+sqlite3
+zlib1g-dev

+ 46 - 0
.github/workflows/build.sh

@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+
+# The make step requires something like:
+# export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PREFIX/lib"
+# further steps additionally require:
+# export PATH="$PATH:$PREFIX/bin"
+
+# fail on non-zero return code from a subprocess
+set -e
+
+# print commands
+set -x
+
+if [ -z "$1" ]
+then
+    echo "Usage: $0 PREFIX"
+    exit 1
+fi
+
+# non-existent variables as an errors
+set -u
+
+export INSTALL_PREFIX=$1
+
+./configure \
+    --prefix="$INSTALL_PREFIX/" \
+    --enable-largefile \
+    --with-cxx \
+    --with-zstd \
+    --with-bzlib \
+    --with-blas \
+    --with-lapack \
+    --with-readline \
+    --with-openmp \
+    --with-pthread \
+    --with-tiff \
+    --with-freetype \
+    --with-freetype-includes="/usr/include/freetype2/" \
+    --with-proj-share=/usr/share/proj \
+    --with-geos \
+    --with-sqlite \
+    --with-fftw \
+    --with-netcdf
+
+make
+make install

+ 75 - 0
.github/workflows/ci.yml

@@ -0,0 +1,75 @@
+name: CI
+
+on:
+- push
+- pull_request
+
+jobs:
+  build:
+    name: ${{ matrix.os }} build
+
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os:
+        - ubuntu-16.04
+        - ubuntu-18.04
+      fail-fast: false
+
+    steps:
+    - uses: actions/checkout@v2
+    - name: Get dependencies
+      run: |
+        sudo apt-get update -y
+        sudo apt-get install -y wget git gawk findutils
+        xargs -a <(awk '! /^ *(#|$)/' ".github/workflows/apt.txt") -r -- \
+            sudo apt-get install -y --no-install-recommends --no-install-suggests
+    - name: Create installation directory
+      run: |
+        mkdir $HOME/install
+    - name: Ensure one core for compilation
+      run: |
+        echo "::set-env name=MAKEFLAGS::-j1"
+    - name: Set LD_LIBRARY_PATH for compilation
+      run: |
+        echo "::set-env name=LD_LIBRARY_PATH::$HOME/install/lib"
+    - name: Build
+      run: .github/workflows/build.sh $HOME/install
+
+  test:
+    name: ${{ matrix.os }} tests
+
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os:
+        - ubuntu-16.04
+        - ubuntu-18.04
+      fail-fast: false
+
+    steps:
+    - uses: actions/checkout@v2
+    - name: Get dependencies
+      run: |
+        sudo apt-get update -y
+        sudo apt-get install -y wget git gawk findutils
+        xargs -a <(awk '! /^ *(#|$)/' ".github/workflows/apt.txt") -r -- \
+            sudo apt-get install -y --no-install-recommends --no-install-suggests
+    - name: Create installation directory
+      run: |
+        mkdir $HOME/install
+    - name: Set number of cores for compilation
+      run: |
+        echo "::set-env name=MAKEFLAGS::-j$(nproc)"
+    - name: Set LD_LIBRARY_PATH for compilation
+      run: |
+        echo "::set-env name=LD_LIBRARY_PATH::$HOME/install/lib"
+    - name: Build
+      run: .github/workflows/build.sh $HOME/install
+    - name: Add the bin directory to PATH
+      run: |
+        echo "::add-path::$HOME/install/bin"
+    - name: Test executing of the grass command
+      run: .github/workflows/test_simple.sh
+    - name: Run tests
+      run: .github/workflows/test_thorough.sh

+ 85 - 0
.github/workflows/flake8.yml

@@ -0,0 +1,85 @@
+name: Code quality check
+
+on:
+- push
+- pull_request
+
+jobs:
+  flake8-lib-python:
+
+    runs-on: ubuntu-18.04
+
+    steps:
+    - uses: actions/checkout@v1
+    - name: Set up Python
+      uses: actions/setup-python@v1
+      with:
+        python-version: 3.8
+    - name: Install
+      run: |
+        python -m pip install --upgrade pip
+        pip install flake8
+    - name: Run Flake8
+      run: |
+        cd lib/python
+        flake8 --count --statistics --show-source .
+
+  flake8-wxgui:
+
+    continue-on-error: true
+    runs-on: ubuntu-18.04
+
+    steps:
+    - uses: actions/checkout@v1
+    - name: Set up Python
+      uses: actions/setup-python@v1
+      with:
+        python-version: 3.8
+    - name: Install
+      run: |
+        python -m pip install --upgrade pip
+        pip install flake8
+    - name: Run Flake8
+      run: |
+        cd gui/wxpython
+        flake8 --count --statistics --show-source .
+
+  flake8-scripts:
+
+    continue-on-error: true
+    runs-on: ubuntu-18.04
+
+    steps:
+    - uses: actions/checkout@v1
+    - name: Set up Python
+      uses: actions/setup-python@v1
+      with:
+        python-version: 3.8
+    - name: Install
+      run: |
+        python -m pip install --upgrade pip
+        pip install flake8
+    - name: Run Flake8
+      run: |
+        cd scripts
+        flake8 --count --statistics --show-source .
+
+  flake8-temporal-modules:
+
+    continue-on-error: true
+    runs-on: ubuntu-18.04
+
+    steps:
+    - uses: actions/checkout@v1
+    - name: Set up Python
+      uses: actions/setup-python@v1
+      with:
+        python-version: 3.8
+    - name: Install
+      run: |
+        python -m pip install --upgrade pip
+        pip install flake8
+    - name: Run Flake8
+      run: |
+        cd temporal
+        flake8 --count --statistics --show-source .

+ 6 - 0
.github/workflows/test_simple.sh

@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+# fail on non-zero return code from a subprocess
+set -e
+
+grass79 --tmp-location EPSG:4326 --exec g.region res=0.1 -p

+ 14 - 0
.github/workflows/test_thorough.sh

@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+
+# fail on non-zero return code from a subprocess
+set -e
+
+grass79 --tmp-location XY --exec \
+    g.extension g.download.location
+grass79 --tmp-location XY --exec \
+    g.download.location url=http://fatra.cnr.ncsu.edu/data/nc_spm_full_v2alpha2.tar.gz dbase=$HOME
+
+grass79 --tmp-location XY --exec \
+    python3 -m grass.gunittest.main \
+        --grassdata $HOME --location nc_spm_full_v2alpha2 --location-type nc \
+        --min-success 50

+ 83 - 0
lib/python/.flake8

@@ -0,0 +1,83 @@
+[flake8]
+ignore =
+    E265,
+    F821,
+    E501,
+    W503,
+    E117,
+    E121,
+    E122,
+    E123,
+    E124,
+    E125,
+    E126,
+    E127,
+    E128,
+    E129,
+    E201,
+    E202,
+    E203,
+    E211,
+    E221,
+    E222,
+    E225,
+    E226,
+    E228,
+    E231,
+    E241,
+    E251,
+    E261, # at least two spaces before inline comment
+    E262, # inline comment should start with '# '
+    E266, # too many leading '#' for block comment
+    E271,
+    E272,
+    E301,
+    E302,
+    E303,
+    E305,
+    E402, # module level import not at top of file
+    E722, # do not use bare 'except'
+    E741, # ambiguous variable name 'l'
+    W291,
+    W292,
+    W293,
+    W391,
+    W504,
+    E101, # indentation contains mixed spaces and tabs
+    E111, # indentation is not a multiple of four
+    E114, # indentation is not a multiple of four (comment)
+    E116, # unexpected indentation (comment)
+    E242, # tab after ','
+    W191, # indentation contains tabs
+    E401, # multiple imports on one line
+    E502, # the backslash is redundant between brackets
+    E701, # multiple statements on one line (colon)
+    E702, # multiple statements on one line (semicolon)
+    E703, # statement ends with a semicolon
+    E711, # comparison to None should be 'if cond is None:'
+    E712, # comparison to True should be 'if cond is True:' or 'if cond:'
+    E713, # test for membership should be 'not in'
+    E721, # do not compare types, use 'isinstance()'
+    E731, # do not assign a lambda expression, use a def
+    F401, # '.reader.BandReferenceReader' imported but unused
+    F403, # 'from ctypes import *' used; unable to detect undefined names
+    F405, # 'RasterRow' may be undefined, or defined from star imports: ctypes, grass.pygrass.raster, grass.pygrass.vector
+    F811, # redefinition of unused 'utils' from line 26
+    F841, # local variable 't0' is assigned to but never used
+    F901, # 'raise NotImplemented' should be 'raise NotImplementedError'
+    W605, # invalid escape sequence '\_'
+
+max-line-length = 150
+exclude =
+    .git,
+    __pycache__,
+    .env,
+    .venv,
+    env,
+    venv,
+    ENV,
+    env.bak,
+    venv.bak,
+    ctypes,
+    pydispatch,
+    testsuite,