Skip to content

Commit bf3d185

Browse files
committed
add job to diff results if more than 1 branch is tested, added workflow dispatch to manually trigger diff test
1 parent eeff04d commit bf3d185

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

.github/workflows/unit_tests.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ on:
2121
pull_request:
2222
types: [opened, reopened, synchronize]
2323

24+
workflow_dispatch:
25+
inputs:
26+
version_to_compare:
27+
description: 'Name of branch to diff against current branch (default: develop)'
28+
default: 'develop'
29+
2430
jobs:
2531
# New job to determine which branches to test
2632
setup-matrix:
@@ -32,6 +38,8 @@ jobs:
3238
run: |
3339
if [ "${{ github.event_name }}" == "pull_request" ]; then
3440
echo "branches=[\"${{ github.head_ref }}\", \"develop\"]" >> $GITHUB_OUTPUT
41+
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
42+
echo "branches=[\"${{ github.ref_name }}\", \"${{ github.event.inputs.version_to_compare }}\"]" >> $GITHUB_OUTPUT
3543
else
3644
echo "branches=[\"${{ github.ref_name }}\"]" >> $GITHUB_OUTPUT
3745
fi
@@ -81,3 +89,51 @@ jobs:
8189
with:
8290
name: test_output_${{ matrix.branch }}
8391
path: ${{ runner.workspace }}/output/${{ matrix.branch }}/test_output
92+
93+
compare-output:
94+
needs: [setup-matrix, build]
95+
runs-on: ubuntu-latest
96+
# Only run if there are exactly 2 branches to compare
97+
if: fromJSON(needs.setup-matrix.outputs.branches)[1] != null
98+
steps:
99+
- name: Download all artifacts
100+
uses: actions/download-artifact@v4
101+
with:
102+
path: ${{ runner.workspace }}/artifacts
103+
104+
- name: Checkout diff_util.py from METplus
105+
uses: actions/checkout@v4
106+
with:
107+
repository: dtcenter/METplus
108+
sparse-checkout: |
109+
metplus/util/diff_util.py
110+
sparse-checkout-cone-mode: false
111+
path: METplus
112+
113+
- name: Set up Python
114+
uses: actions/setup-python@v5
115+
with:
116+
python-version: "3.12"
117+
118+
- name: Run diff_util.py
119+
run: |
120+
# Extract branch names from the setup-matrix output
121+
# assumes 1st branch is the current branch and the 2nd branch is the truth data
122+
OUTPUT_BRANCH=$(echo '${{ needs.setup-matrix.outputs.branches }}' | jq -r '.[0]')
123+
TRUTH_BRANCH=$(echo '${{ needs.setup-matrix.outputs.branches }}' | jq -r '.[1]')
124+
125+
# Define paths to the downloaded data
126+
# Note: upload-artifact v4 nested paths differently, usually named by 'name' provided in upload
127+
OUTPUT_DIR="${{ runner.workspace }}/artifacts/test_output_${OUTPUT_BRANCH}"
128+
TRUTH_DIR="${{ runner.workspace }}/artifacts/test_output_${TRUTH_BRANCH}"
129+
130+
echo "Comparing $OUTPUT_DIR and $TRUTH_DIR"
131+
132+
# Ensure directories exist before running script
133+
if [ -d "$OUTPUT_DIR" ] && [ -d "$TRUTH_DIR" ]; then
134+
python METplus/metplus/util/diff_util.py "$TRUTH_DIR" "$OUTPUT_DIR"
135+
else
136+
echo "One or both data directories are missing."
137+
ls ${{ runner.workspace }}/artifacts
138+
exit 1
139+
fi

0 commit comments

Comments
 (0)