Skip to content

Commit 40f013d

Browse files
committed
Move baseline png files to ert-testdata
To alleviate binary bloat in the Ert repository, the baseline png files has been removed from ert, and added to the repository ert-testdata. The test_screenshot workflow is configured to clone the baselines from ert-testdata and use those for running the screenshot tests. If a change is detected, it will pack all screenshots into an artifact. Another workflow, running from the origin repository with sufficient token accesses, will pick up the artifact and submit it as a new PR to ert-testdata. Merging this PR requires manual intervention.
1 parent bff67ef commit 40f013d

44 files changed

Lines changed: 135 additions & 51 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build_and_test.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,6 @@ jobs:
8282
test-type: ${{ matrix.test-type }}
8383
secrets: inherit
8484

85-
test-screenshots:
86-
needs: [run-pre-commit, check-typing]
87-
strategy:
88-
fail-fast: false
89-
matrix:
90-
python-version: [ '3.14' ]
91-
os: [ ubuntu-latest ]
92-
uses: ./.github/workflows/test_screenshots.yml
93-
with:
94-
os: ${{ matrix.os }}
95-
python-version: ${{ matrix.python-version }}
96-
secrets: inherit
97-
9885
test-slurm:
9986
needs: [run-pre-commit, check-typing]
10087
strategy:
Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,106 @@
11
name: Push screenshots to ert-testdata
22

33
on:
4+
workflow_run:
5+
workflows: ["Screenshot tests"]
6+
types: [completed]
47
workflow_dispatch:
8+
inputs:
9+
run-id:
10+
description: 'Run ID of a Screenshot tests workflow run to use as artifact source'
11+
required: true
12+
13+
permissions:
14+
contents: read
15+
pull-requests: write
516

617
jobs:
718
push-screenshots:
19+
name: Push updated screenshots to ert-testdata
820
runs-on: ubuntu-latest
21+
if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.event == 'pull_request'
22+
923
steps:
10-
- run: echo "Placeholder - not yet implemented"
24+
- name: Download screenshot artifact
25+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
26+
with:
27+
name: screenshot-results
28+
path: artifact
29+
run-id: ${{ inputs.run-id || github.event.workflow_run.id }}
30+
github-token: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Read metadata
33+
id: metadata
34+
run: |
35+
echo "pr_number=$(jq -r '.pr_number' artifact/metadata.json)" >> "$GITHUB_OUTPUT"
36+
echo "outcome=$(jq -r '.outcome' artifact/metadata.json)" >> "$GITHUB_OUTPUT"
37+
38+
- name: Checkout ert-testdata
39+
if: steps.metadata.outputs.outcome == 'failure'
40+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
41+
with:
42+
repository: equinor/ert-testdata
43+
ref: main
44+
token: ${{ secrets.ERTOMATIC_ERT_TESTDATA_TOKEN }}
45+
path: ert-testdata
46+
47+
- name: Copy updated screenshots into ert-testdata
48+
if: steps.metadata.outputs.outcome == 'failure'
49+
run: cp -r artifact/updated-screenshots/. ert-testdata/screenshotbaselines/
50+
51+
- name: Push branch and open PR in ert-testdata
52+
if: steps.metadata.outputs.outcome == 'failure'
53+
env:
54+
GH_TOKEN: ${{ secrets.ERTOMATIC_ERT_TESTDATA_TOKEN }}
55+
PR_NUMBER: ${{ steps.metadata.outputs.pr_number }}
56+
run: |
57+
BRANCH="update-screenshots-ert-pr-${PR_NUMBER}"
58+
cd ert-testdata
59+
git config user.name "github-actions[bot]"
60+
git config user.email "github-actions[bot]@users.noreply.github.com"
61+
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/equinor/ert-testdata.git"
62+
git checkout -b "$BRANCH"
63+
git add --all screenshotbaselines/
64+
git commit -m "Update screenshots for equinor/ert#${PR_NUMBER}"
65+
git push --force origin "$BRANCH"
66+
EXISTING=$(gh pr list \
67+
--repo equinor/ert-testdata \
68+
--head "$BRANCH" \
69+
--state open \
70+
--json number \
71+
--jq '.[0].number // empty')
72+
if [ -z "$EXISTING" ]; then
73+
PR_URL=$(gh pr create \
74+
--repo equinor/ert-testdata \
75+
--base main \
76+
--head "$BRANCH" \
77+
--title "Update screenshots for equinor/ert#${PR_NUMBER}" \
78+
--body "Automatically updated screenshot baselines triggered by https://github.com/equinor/ert/pull/${PR_NUMBER}")
79+
if [ "${PR_NUMBER}" != "0" ]; then
80+
gh pr comment "${PR_NUMBER}" \
81+
--repo equinor/ert \
82+
--body "Screenshots differ from baselines. A baseline update PR has been prepared: ${PR_URL}"
83+
fi
84+
fi
85+
86+
- name: Close stale ert-testdata PR if screenshots now pass
87+
if: steps.metadata.outputs.outcome == 'success'
88+
env:
89+
GH_TOKEN: ${{ secrets.ERTOMATIC_ERT_TESTDATA_TOKEN }}
90+
PR_NUMBER: ${{ steps.metadata.outputs.pr_number }}
91+
run: |
92+
BRANCH="update-screenshots-ert-pr-${PR_NUMBER}"
93+
EXISTING=$(gh pr list \
94+
--repo equinor/ert-testdata \
95+
--head "$BRANCH" \
96+
--state open \
97+
--json number \
98+
--jq '.[0].number // empty')
99+
if [ -n "$EXISTING" ]; then
100+
gh pr close "$EXISTING" --repo equinor/ert-testdata --delete-branch
101+
if [ "${PR_NUMBER}" != "0" ]; then
102+
gh pr comment "${PR_NUMBER}" \
103+
--repo equinor/ert \
104+
--body "Screenshot tests now pass. The baseline update PR equinor/ert-testdata#${EXISTING} has been closed."
105+
fi
106+
fi
Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,67 @@
1+
name: Screenshot tests
2+
13
on:
24
workflow_dispatch:
3-
workflow_call:
4-
inputs:
5-
os:
6-
type: string
7-
python-version:
8-
type: string
5+
pull_request:
96

107
permissions:
11-
contents: read
8+
contents: read
129

1310
env:
1411
UV_FROZEN: true
1512

1613
jobs:
1714
test-screenshots:
1815
name: Run screenshot tests
19-
timeout-minutes: 20
20-
runs-on: ${{ inputs.os }}
16+
timeout-minutes: 30
17+
runs-on: ubuntu-latest
2118

2219
steps:
2320
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
2421

2522
- uses: ./.github/actions/install_dependencies_qt
2623
with:
27-
os: ${{ inputs.os }}
24+
os: ubuntu-latest
2825

2926
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
3027
id: setup_python
3128
with:
32-
python-version: ${{ inputs.python-version }}
29+
python-version: '3.14'
3330

3431
- name: Install uv
3532
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
3633
with:
3734
enable-cache: true
3835
prune-cache: false
39-
python-version: ${{ inputs.python-version }}
36+
python-version: '3.14'
4037

4138
- name: Install ert
42-
run: |
43-
uv sync --group dev
39+
run: uv sync --group dev
40+
41+
- name: Fetch screenshot baselines from ert-testdata
42+
run: uv run just fetch-screenshot-baselines
4443

4544
- name: Run screenshot tests
46-
run: |
47-
uv run just screenshot-comparison-test
45+
id: screenshot-tests
46+
run: uv run just screenshot-comparison-test
47+
continue-on-error: true
4848

49-
- name: Pack updated screenshot in case of failure
50-
if: ${{ failure() }}
49+
- name: Pack updated screenshots
50+
if: steps.screenshot-tests.outcome == 'failure'
51+
run: uv run just pack-updated-screenshots
52+
53+
- name: Prepare artifact
54+
if: always()
5155
run: |
52-
uv run just pack-updated-screenshots
56+
mkdir -p artifact
57+
echo '{"pr_number": ${{ github.event.number || 0 }}, "outcome": "${{ steps.screenshot-tests.outcome }}"}' > artifact/metadata.json
58+
if [ -d updated-screenshots ]; then
59+
cp -r updated-screenshots artifact/
60+
fi
5361
54-
- name: Upload updated screenshot images from failed image comparison test
55-
id: upload-screenshot-images
56-
if: ${{ failure() }}
62+
- name: Upload artifact
63+
if: always()
5764
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
58-
continue-on-error: true
5965
with:
60-
name: updated-screenshots-${{ github.run_number }}-${{ github.run_id }}-${{ inputs.python-version }}
61-
path: updated-screenshots
62-
63-
- name: User instructions for fetching updated screenshots
64-
if: ${{ failure() && steps.upload-screenshot-images.outputs.artifact-id != '' }}
65-
run: |
66-
echo " * Ensure gh command line utility is installed"
67-
echo " * Do 'gh auth login' if you are not authenticated yet"
68-
echo "$ rm -rf .tmp; gh run download ${{ github.run_id }} -D .tmp -n updated-screenshots-${{ github.run_number }}-${{ github.run_id }}-${{ inputs.python-version }}; cp -a .tmp/* ."
69-
echo " * Then review your local changes and commit+squash them."
70-
echo ""
71-
echo "(This steps exits with a failure code in order to have its output highlighted in Github actions web interface)"
72-
exit 1
66+
name: screenshot-results
67+
path: artifact/
-57.9 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)