|
21 | 21 | pull_request: |
22 | 22 | types: [opened, reopened, synchronize] |
23 | 23 |
|
| 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 | + |
24 | 30 | jobs: |
25 | 31 | # New job to determine which branches to test |
26 | 32 | setup-matrix: |
|
32 | 38 | run: | |
33 | 39 | if [ "${{ github.event_name }}" == "pull_request" ]; then |
34 | 40 | 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 |
35 | 43 | else |
36 | 44 | echo "branches=[\"${{ github.ref_name }}\"]" >> $GITHUB_OUTPUT |
37 | 45 | fi |
|
81 | 89 | with: |
82 | 90 | name: test_output_${{ matrix.branch }} |
83 | 91 | 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