5454 compare-baseline :
5555 name : Compare baseline Python ${{ inputs.python-version }} with MPL ${{ inputs.matplotlib-version }}
5656 runs-on : ubuntu-latest
57+ env :
58+ IS_PR : ${{ github.event.pull_request }}
5759 defaults :
5860 run :
5961 shell : bash -el {0}
@@ -75,22 +77,25 @@ jobs:
7577 - name : Cache Baseline Figures
7678 id : cache-baseline
7779 uses : actions/cache@v4
80+ if : ${{ env.IS_PR }}
7881 with :
7982 path : ./ultraplot/tests/baseline # The directory to cache
80- # Key is based on OS, Python/Matplotlib versions, and the PR number
81- key : ${{ runner.os }}-baseline-pr -${{ github.event.pull_request.number }}-${{ inputs.python-version }}-${{ inputs.matplotlib-version }}
83+ # Key is based on OS, Python/Matplotlib versions, and the base commit SHA
84+ key : ${{ runner.os }}-baseline-base -${{ github.event.pull_request.base.sha }}-${{ inputs.python-version }}-${{ inputs.matplotlib-version }}
8285 restore-keys : |
83- ${{ runner.os }}-baseline-pr -${{ github.event.pull_request.number }}-${{ inputs.python-version }}-${{ inputs.matplotlib-version }}-
86+ ${{ runner.os }}-baseline-base -${{ github.event.pull_request.base.sha }}-${{ inputs.python-version }}-${{ inputs.matplotlib-version }}-
8487
8588 # Conditional Baseline Generation (Only runs on cache miss)
8689 - name : Generate baseline from main
8790 # Skip this step if the cache was found (cache-hit is true)
88- if : steps.cache-baseline.outputs.cache-hit != 'true'
91+ if : steps.cache-baseline.outputs.cache-hit != 'true' || !env.IS_PR
8992 run : |
9093 mkdir -p ultraplot/tests/baseline
91- # Checkout the base branch (e.g., 'main') to generate the official baseline
92- git fetch origin ${{ github.event.pull_request.base.sha }}
93- git checkout ${{ github.event.pull_request.base.sha }}
94+ # Checkout the base commit for PRs; otherwise regenerate from current ref
95+ if [ -n "${{ github.event.pull_request.base.sha }}" ]; then
96+ git fetch origin ${{ github.event.pull_request.base.sha }}
97+ git checkout ${{ github.event.pull_request.base.sha }}
98+ fi
9499
95100 # Install the Ultraplot version from the base branch's code
96101 pip install --no-build-isolation --no-deps .
@@ -103,7 +108,9 @@ jobs:
103108 ultraplot/tests
104109
105110 # Return to the PR branch for the rest of the job
106- git checkout ${{ github.sha }}
111+ if [ -n "${{ github.event.pull_request.base.sha }}" ]; then
112+ git checkout ${{ github.sha }}
113+ fi
107114
108115 # Image Comparison (Uses cached or newly generated baseline)
109116 - name : Image Comparison Ultraplot
0 commit comments