From 040d976665d4e31bdf72f132bedb2e24ec3ca827 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Fri, 12 Dec 2025 17:59:20 +1000 Subject: [PATCH 1/3] replace images with hashes --- .github/workflows/build-ultraplot.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-ultraplot.yml b/.github/workflows/build-ultraplot.yml index 7d6f1660..8ff091b5 100644 --- a/.github/workflows/build-ultraplot.yml +++ b/.github/workflows/build-ultraplot.yml @@ -78,7 +78,7 @@ jobs: git checkout ${{ github.event.pull_request.base.sha }} python -c "import ultraplot as plt; plt.config.Configurator()._save_yaml('ultraplot.yml')" pytest -W ignore \ - --mpl-generate-path=./baseline/ \ + --mpl-generate-hash-library=./baseline/baseline_hashes.json\ --mpl-default-style="./ultraplot.yml"\ ultraplot/tests git checkout ${{ github.sha }} # Return to PR branch @@ -89,7 +89,7 @@ jobs: python -c "import ultraplot as plt; plt.config.Configurator()._save_yaml('ultraplot.yml')" pytest -W ignore \ --mpl \ - --mpl-baseline-path=./baseline/ \ + --mpl-hash-library=./baseline/baseline_hashes.json\ --mpl-results-path=./results/ \ --mpl-generate-summary=html \ --mpl-default-style="./ultraplot.yml" \ From c4f2b9c27f35068819b6824418ae4ad24f4e9636 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Fri, 12 Dec 2025 18:19:22 +1000 Subject: [PATCH 2/3] hashes need baselines --- .github/workflows/build-ultraplot.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-ultraplot.yml b/.github/workflows/build-ultraplot.yml index 8ff091b5..77fa3874 100644 --- a/.github/workflows/build-ultraplot.yml +++ b/.github/workflows/build-ultraplot.yml @@ -78,6 +78,7 @@ jobs: git checkout ${{ github.event.pull_request.base.sha }} python -c "import ultraplot as plt; plt.config.Configurator()._save_yaml('ultraplot.yml')" pytest -W ignore \ + --mpl-generate-path=./baseline/ \ --mpl-generate-hash-library=./baseline/baseline_hashes.json\ --mpl-default-style="./ultraplot.yml"\ ultraplot/tests From ac60058f136bdee9a77846bf04742cb1da597322 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Fri, 12 Dec 2025 20:24:26 +1000 Subject: [PATCH 3/3] use github cache --- .github/workflows/build-ultraplot.yml | 40 ++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-ultraplot.yml b/.github/workflows/build-ultraplot.yml index 77fa3874..7574c6bc 100644 --- a/.github/workflows/build-ultraplot.yml +++ b/.github/workflows/build-ultraplot.yml @@ -71,30 +71,56 @@ jobs: cache-environment: true cache-downloads: false + # Cache Baseline Figures (Restore step) + - name: Cache Baseline Figures + id: cache-baseline + uses: actions/cache@v4 + with: + path: ./baseline # The directory to cache + # Key is based on OS, Python/Matplotlib versions, and the base commit SHA + key: ${{ runner.os }}-baseline-${{ inputs.python-version }}-${{ inputs.matplotlib-version }}-${{ github.event.pull_request.base.sha }} + restore-keys: | + ${{ runner.os }}-baseline-${{ inputs.python-version }}-${{ inputs.matplotlib-version }}- + + # Conditional Baseline Generation (Only runs on cache miss) - name: Generate baseline from main + # Skip this step if the cache was found (cache-hit is true) + if: steps.cache-baseline.outputs.cache-hit != 'true' run: | mkdir -p baseline + # Checkout the base branch (e.g., 'main') to generate the official baseline git fetch origin ${{ github.event.pull_request.base.sha }} git checkout ${{ github.event.pull_request.base.sha }} + + # Install the Ultraplot version from the base branch's code + pip install --no-build-isolation --no-deps . + + # Generate the baseline images and hash library python -c "import ultraplot as plt; plt.config.Configurator()._save_yaml('ultraplot.yml')" pytest -W ignore \ --mpl-generate-path=./baseline/ \ --mpl-generate-hash-library=./baseline/baseline_hashes.json\ --mpl-default-style="./ultraplot.yml"\ ultraplot/tests - git checkout ${{ github.sha }} # Return to PR branch + # Return to the PR branch for the rest of the job + git checkout ${{ github.sha }} + + # Image Comparison (Uses cached or newly generated baseline) - name: Image Comparison Ultraplot run: | + # Re-install the Ultraplot version from the current PR branch + pip install --no-build-isolation --no-deps . + mkdir -p results python -c "import ultraplot as plt; plt.config.Configurator()._save_yaml('ultraplot.yml')" pytest -W ignore \ - --mpl \ - --mpl-hash-library=./baseline/baseline_hashes.json\ - --mpl-results-path=./results/ \ - --mpl-generate-summary=html \ - --mpl-default-style="./ultraplot.yml" \ - ultraplot/tests + --mpl \ + --mpl-hash-library=./baseline/baseline_hashes.json\ + --mpl-results-path=./results/ \ + --mpl-generate-summary=html \ + --mpl-default-style="./ultraplot.yml" \ + ultraplot/tests # Return the html output of the comparison even if failed - name: Upload comparison failures