Skip to content

Commit 6d9164c

Browse files
mjrenoHofer-Julian
authored andcommitted
ci(actions): add ci action to check fortran source formatting (MODFLOW-ORG#982)
1 parent 87c0a30 commit 6d9164c

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#! /bin/bash
2+
3+
#SEARCHPATHS=(src srcbmi utils)
4+
SEARCHPATHS=(src)
5+
EXCLUDEDIRS=(src/Utilities/Libraries/blas # external library blas
6+
src/Utilities/Libraries/daglib # external library dag
7+
src/Utilities/Libraries/rcm # external library rcm
8+
src/Utilities/Libraries/sparsekit # external library sparsekit
9+
src/Utilities/Libraries/sparskit2) # external library sparsekit2
10+
EXCLUDEFILES=(src/Utilities/InputOutput.f90) # excluded until refactored
11+
12+
fformatfails=()
13+
checkcount=0
14+
15+
for path in "${SEARCHPATHS[@]}"; do
16+
readarray -d '' files < <(find "${path}" -type f -print0 | grep -z '\.[fF]9[0,5]$')
17+
for file in "${files[@]}"; do
18+
exclude=0
19+
20+
for d in "${EXCLUDEDIRS[@]}"; do
21+
[[ "${d}" == $(dirname "${file}") ]] && exclude=1 && break; done
22+
if [[ ${exclude} == 1 ]]; then continue; fi
23+
24+
for f in "${EXCLUDEFILES[@]}"; do
25+
[[ "${f}" == "${file}" ]] && exclude=1 && break; done
26+
if [[ ${exclude} == 1 ]]; then continue; fi
27+
28+
((checkcount++))
29+
30+
if [[ ! -z $(fprettify -d -c ./distribution/.fprettify.yaml "${file}" 2>&1) ]]; then
31+
fformatfails+=("${file}")
32+
fi
33+
done
34+
done
35+
36+
echo -e "\nFortran source files checked: ${checkcount}"
37+
echo -e "Fortran source files failed: ${#fformatfails[@]}\n"
38+
39+
if [[ ${#fformatfails[@]} > 0 ]]; then
40+
for f in "${fformatfails[@]}"; do echo "${f}"; done
41+
42+
echo -e "\nTo verify file format diff and/or warn in local environment run:"
43+
echo -e " 'fprettify -d -c <path to modflow6>/distribution/.fprettify.yaml <filepath>'\n\n"
44+
45+
exit 1
46+
fi
47+
48+
exit 0

.github/workflows/ci-format.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: docs
2+
3+
on:
4+
push:
5+
branches: [ master, develop ]
6+
pull_request:
7+
branches: [ develop ]
8+
9+
jobs:
10+
fortan-format-check:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/[email protected]
15+
16+
- name: Setup Python
17+
uses: actions/[email protected]
18+
with:
19+
python-version: 3.9
20+
21+
- name: Install python packages
22+
run: |
23+
.github/common/install-python-std.sh
24+
25+
- name: Setup symbolic links on Linux
26+
run: |
27+
sudo ln -fs /usr/bin/gfortran-10 /usr/local/bin/gfortran
28+
sudo ln -fs /usr/bin/gcc-10 /usr/local/bin/gcc
29+
sudo ln -fs /usr/bin/g++-10 /usr/local/bin/g++
30+
31+
- name: Print python package versions
32+
run: |
33+
pip list
34+
35+
- name: Set and print branch name
36+
run: |
37+
.github/common/git-branch-export.sh
38+
39+
- name: Fortran source format check
40+
run: |
41+
.github/common/fortran-format-check.sh

0 commit comments

Comments
 (0)