Skip to content

Commit bb1c7d9

Browse files
committed
Improve the DVC image diff workflow to support side-by-side comparison of modified images
1 parent b528586 commit bb1c7d9

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

.github/workflows/dvc-diff.yml

+36-13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ jobs:
2424
- name: Setup continuous machine learning (CML)
2525
uses: iterative/setup-cml@v1.0.0
2626

27+
- name: Pull image data from cloud storage
28+
run: dvc pull --remote upstream
29+
2730
# Produce the markdown diff report, which should look like:
2831
# ## Summary of changed images
2932
#
@@ -32,32 +35,52 @@ jobs:
3235
# | Status | Path |
3336
# |----------|-------------------------------------|
3437
# | added | pygmt/tests/baseline/test_image.png |
35-
- name: Put list of images that were added or changed into report
38+
# | deleted | pygmt/tests/baseline/test_image2.png |
39+
# | modified | pygmt/tests/baseline/test_image3.png |
40+
- name: Generate the image diff report
41+
env:
42+
repo_token: ${{ secrets.GITHUB_TOKEN }}
43+
id: image-diff
3644
run: |
3745
echo -e "## Summary of changed images\n" > report.md
3846
echo -e "This is an auto-generated report of images that have changed on the DVC remote\n" >> report.md
3947
dvc diff --show-md master HEAD >> report.md
40-
cat report.md
4148
42-
- name: Pull image data from cloud storage
43-
run: dvc pull --remote upstream
44-
45-
- name: Put image diff(s) into report
46-
env:
47-
repo_token: ${{ secrets.GITHUB_TOKEN }}
48-
id: image-diff
49-
run: |
50-
# Get just the filename of the changed image from the report
51-
awk 'NF==5 && NR>=7 {print $4}' report.md > diff_files.txt
49+
# Get just the filename of the added and modified image from the report
50+
awk 'NF==5 && NR>=7 && $2=="added" {print $4}' report.md > added_files.txt
51+
awk 'NF==5 && NR>=7 && $2=="modified" {print $4}' report.md > modified_files.txt
5252
5353
# Append each image to the markdown report
5454
echo -e "## Image diff(s)\n" >> report.md
5555
echo -e "<details>\n" >> report.md
5656
57+
# Added images
58+
echo -e "### Added images\n" >> report.md
5759
while IFS= read -r line; do
5860
echo -e "- $line \n" >> report.md
5961
cml-publish --title $line --md "$line" >> report.md < /dev/null
60-
done < diff_files.txt
62+
done < added_files.txt
63+
64+
# Modified images
65+
echo -e "### Modified images\n" >> report.md
66+
# Upload new images
67+
while IFS= read -r line; do
68+
cml-publish --title $line --md "$line" > modified_images_new.md < /dev/null
69+
done < modified_files.txt
70+
71+
# Pull images in the master branch from cloud storage
72+
git checkout master
73+
dvc pull --remote upstream
74+
# Upload old images
75+
while IFS= read -r line; do
76+
cml-publish --title $line --md "$line" > modified_images_old.md < /dev/null
77+
done < modified_files.txt
78+
79+
# Append image report for modified images
80+
echo -e "| Path | Old | New |" >> report.md
81+
echo -e "|---|---|---|" >> report.md
82+
gpaste modified_files.txt modified_images_old.md modified_images_new.md |
83+
gawk 'function basename(file) {sub(".*/", "", file);return file} {printf("| %s | %s | %s |\n", basename($1), $2, $3)}'
6184
6285
echo -e "</details>\n" >> report.md
6386

0 commit comments

Comments
 (0)