diff --git a/.github/common/fortran-format-check.sh b/.github/common/fortran-format-check.sh new file mode 100755 index 00000000000..d542e004662 --- /dev/null +++ b/.github/common/fortran-format-check.sh @@ -0,0 +1,48 @@ +#! /bin/bash + +#SEARCHPATHS=(src srcbmi utils) +SEARCHPATHS=(src) +EXCLUDEDIRS=(src/Utilities/Libraries/blas # external library blas + src/Utilities/Libraries/daglib # external library dag + src/Utilities/Libraries/rcm # external library rcm + src/Utilities/Libraries/sparsekit # external library sparsekit + src/Utilities/Libraries/sparskit2) # external library sparsekit2 +EXCLUDEFILES=(src/Utilities/InputOutput.f90) # excluded until refactored + +fformatfails=() +checkcount=0 + +for path in "${SEARCHPATHS[@]}"; do + readarray -d '' files < <(find "${path}" -type f -print0 | grep -z '\.[fF]9[0,5]$') + for file in "${files[@]}"; do + exclude=0 + + for d in "${EXCLUDEDIRS[@]}"; do + [[ "${d}" == $(dirname "${file}") ]] && exclude=1 && break; done + if [[ ${exclude} == 1 ]]; then continue; fi + + for f in "${EXCLUDEFILES[@]}"; do + [[ "${f}" == "${file}" ]] && exclude=1 && break; done + if [[ ${exclude} == 1 ]]; then continue; fi + + ((checkcount++)) + + if [[ ! -z $(fprettify -d -c ./distribution/.fprettify.yaml "${file}" 2>&1) ]]; then + fformatfails+=("${file}") + fi + done +done + +echo -e "\nFortran source files checked: ${checkcount}" +echo -e "Fortran source files failed: ${#fformatfails[@]}\n" + +if [[ ${#fformatfails[@]} > 0 ]]; then + for f in "${fformatfails[@]}"; do echo "${f}"; done + + echo -e "\nTo verify file format diff and/or warn in local environment run:" + echo -e " 'fprettify -d -c /distribution/.fprettify.yaml '\n\n" + + exit 1 +fi + +exit 0 diff --git a/.github/common/install-python-std.sh b/.github/common/install-python-std.sh index 7cbbdb543ad..d28afc2309a 100755 --- a/.github/common/install-python-std.sh +++ b/.github/common/install-python-std.sh @@ -1,7 +1,7 @@ #!/bin/bash pip install wheel -pip install requests appdirs numpy matplotlib pytest pytest-xdist meson!=0.63.0 ninja +pip install requests appdirs numpy matplotlib pytest pytest-xdist meson!=0.63.0 ninja fprettify pip install https://github.com/modflowpy/flopy/zipball/develop pip install https://github.com/modflowpy/pymake/zipball/master pip install https://github.com/Deltares/xmipy/zipball/develop diff --git a/.github/workflows/ci-format.yml b/.github/workflows/ci-format.yml new file mode 100644 index 00000000000..a959e79ef0d --- /dev/null +++ b/.github/workflows/ci-format.yml @@ -0,0 +1,41 @@ +name: docs + +on: + push: + branches: [ master, develop ] + pull_request: + branches: [ develop ] + +jobs: + fortan-format-check: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2.3.4 + + - name: Setup Python + uses: actions/setup-python@v4.0.0 + with: + python-version: 3.9 + + - name: Install python packages + run: | + .github/common/install-python-std.sh + + - name: Setup symbolic links on Linux + run: | + sudo ln -fs /usr/bin/gfortran-10 /usr/local/bin/gfortran + sudo ln -fs /usr/bin/gcc-10 /usr/local/bin/gcc + sudo ln -fs /usr/bin/g++-10 /usr/local/bin/g++ + + - name: Print python package versions + run: | + pip list + + - name: Set and print branch name + run: | + .github/common/git-branch-export.sh + + - name: Fortran source format check + run: | + .github/common/fortran-format-check.sh