Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(actions): add ci action to check fortran source formatting #982

Merged
merged 2 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/common/fortran-format-check.sh
Original file line number Diff line number Diff line change
@@ -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 <path to modflow6>/distribution/.fprettify.yaml <filepath>'\n\n"

exit 1
fi

exit 0
2 changes: 1 addition & 1 deletion .github/common/install-python-std.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/ci-format.yml
Original file line number Diff line number Diff line change
@@ -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