Skip to content

Commit

Permalink
Ensure XPPM/YPPM consistency in CI
Browse files Browse the repository at this point in the history
Add a step to the linting workflow that ensures consistency in the
XPPM/YPPM codes.
  • Loading branch information
romanc committed Feb 10, 2025
1 parent c3986dd commit 163f8c1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ jobs:
- name: Install pre-commit
run: |
pip install pre-commit
- name: Run lint via pre-commit
run: |
pre-commit run --all-files
- name: Check advection code consistency
run: |
./.github/workflows/scripts/ensure_xppm_yppm_consistency.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#!/bin/bash
#
# Script to convert xppm.py/xtp_u.py into yppm/ytp_v.py. Can be deleted once we
# have a way to use the same codebase for x-direction and y-direction advection.
# Script to automatically convert `xppm.py` and `xtp_u.py` into `yppm.py` and
# `ytp_v.py` respectively. We use it as part of the linting workflow in the CI
# to ensure these files stay in sync.
#
# This script (and the corresponding linting workflow) can be deleted once we
# have a way to use the same codebase for x-direction and y-direction advection.

set -e -x
set -e

# Copy XPPM codes into YPPM files
cp pyFV3/stencils/xppm.py pyFV3/stencils/yppm.py
cp pyFV3/stencils/xtp_u.py pyFV3/stencils/ytp_v.py

# Fixup YPPM code
for fname in pyFV3/stencils/yppm.py pyFV3/stencils/ytp_v.py
do
sed -i 's/ub/vb/g' $fname
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/scripts/ensure_xppm_yppm_consistency.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Call the automatic conversion
./.github/workflows/scripts/convert_xppm_yppm.sh

# Check for uncommitted changes in the working tree
if [ -n "$(git status --porcelain)" ]; then
echo "It looks like x-direction and y-direction advection are out of sync. We found uncommitted"
echo "changes in working tree after YPPM was generated from XPPM sources. Please ensure to make"
echo "symmetrical changes to XPPM and YPPM codes."
echo ""
echo "If this is a false positive, please fix \".github/workflows/scripts/convert_xppm_yppm.sh\""
echo "or re-evaluate the need for this part of the linting workflow."
echo ""
echo "git status"
echo "----------"
git status
echo ""
echo "git diff"
echo "--------"
git --no-pager diff
echo ""

exit 1
else
echo "XPPM and YPPM are in sync."
fi

0 comments on commit 163f8c1

Please sign in to comment.