Skip to content

Commit

Permalink
ci(actions): add ci action to check fortran source formatting (MODFLO…
Browse files Browse the repository at this point in the history
  • Loading branch information
mjreno authored and Hofer-Julian committed Jul 14, 2022
1 parent 87c0a30 commit 6d9164c
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
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
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

0 comments on commit 6d9164c

Please sign in to comment.