Skip to content

Commit 163f8c1

Browse files
committed
Ensure XPPM/YPPM consistency in CI
Add a step to the linting workflow that ensures consistency in the XPPM/YPPM codes.
1 parent c3986dd commit 163f8c1

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

.github/workflows/lint.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ jobs:
1717
- name: Install pre-commit
1818
run: |
1919
pip install pre-commit
20-
2120
- name: Run lint via pre-commit
2221
run: |
2322
pre-commit run --all-files
23+
24+
- name: Check advection code consistency
25+
run: |
26+
./.github/workflows/scripts/ensure_xppm_yppm_consistency.sh

convert_xppm_yppm.sh renamed to .github/workflows/scripts/convert_xppm_yppm.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
#!/bin/bash
22
#
3-
# Script to convert xppm.py/xtp_u.py into yppm/ytp_v.py. Can be deleted once we
4-
# have a way to use the same codebase for x-direction and y-direction advection.
3+
# Script to automatically convert `xppm.py` and `xtp_u.py` into `yppm.py` and
4+
# `ytp_v.py` respectively. We use it as part of the linting workflow in the CI
5+
# to ensure these files stay in sync.
56
#
7+
# This script (and the corresponding linting workflow) can be deleted once we
8+
# have a way to use the same codebase for x-direction and y-direction advection.
69

7-
set -e -x
10+
set -e
811

12+
# Copy XPPM codes into YPPM files
913
cp pyFV3/stencils/xppm.py pyFV3/stencils/yppm.py
1014
cp pyFV3/stencils/xtp_u.py pyFV3/stencils/ytp_v.py
1115

16+
# Fixup YPPM code
1217
for fname in pyFV3/stencils/yppm.py pyFV3/stencils/ytp_v.py
1318
do
1419
sed -i 's/ub/vb/g' $fname
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# Call the automatic conversion
4+
./.github/workflows/scripts/convert_xppm_yppm.sh
5+
6+
# Check for uncommitted changes in the working tree
7+
if [ -n "$(git status --porcelain)" ]; then
8+
echo "It looks like x-direction and y-direction advection are out of sync. We found uncommitted"
9+
echo "changes in working tree after YPPM was generated from XPPM sources. Please ensure to make"
10+
echo "symmetrical changes to XPPM and YPPM codes."
11+
echo ""
12+
echo "If this is a false positive, please fix \".github/workflows/scripts/convert_xppm_yppm.sh\""
13+
echo "or re-evaluate the need for this part of the linting workflow."
14+
echo ""
15+
echo "git status"
16+
echo "----------"
17+
git status
18+
echo ""
19+
echo "git diff"
20+
echo "--------"
21+
git --no-pager diff
22+
echo ""
23+
24+
exit 1
25+
else
26+
echo "XPPM and YPPM are in sync."
27+
fi

0 commit comments

Comments
 (0)