Skip to content

Commit bd43348

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

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

.github/workflows/dvc-diff.yml

+32-14
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,51 @@ jobs:
3232
# | Status | Path |
3333
# |----------|-------------------------------------|
3434
# | added | pygmt/tests/baseline/test_image.png |
35-
- name: Put list of images that were added or changed into report
35+
# | deleted | pygmt/tests/baseline/test_image2.png |
36+
# | modified | pygmt/tests/baseline/test_image3.png |
37+
- name: Generate the image diff report
38+
env:
39+
repo_token: ${{ secrets.GITHUB_TOKEN }}
40+
id: image-diff
3641
run: |
3742
echo -e "## Summary of changed images\n" > report.md
3843
echo -e "This is an auto-generated report of images that have changed on the DVC remote\n" >> report.md
3944
dvc diff --show-md master HEAD >> report.md
40-
cat report.md
41-
42-
- name: Pull image data from cloud storage
43-
run: dvc pull --remote upstream
4445
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
46+
# Get just the filename of the added and modified image from the report
47+
awk 'NF==5 && NR>=7 && $2=="added" {print $4}' report.md > added_files.txt
48+
awk 'NF==5 && NR>=7 && $2=="modified" {print $4}' report.md > modified_files.txt
5249
5350
# Append each image to the markdown report
5451
echo -e "## Image diff(s)\n" >> report.md
5552
echo -e "<details>\n" >> report.md
5653
54+
# Modified images
55+
echo -e "### Modified images\n" >> report.md
56+
# Upload old images
57+
while IFS= read -r line; do
58+
cml-publish --title $line --md "$line" > modified_images_old.md < /dev/null
59+
done < modified_files.txt
60+
61+
# Pull image data from cloud storage
62+
dvc pull --remote upstream
63+
64+
# Upload new images
65+
while IFS= read -r line; do
66+
cml-publish --title $line --md "$line" > modified_images_new.md < /dev/null
67+
done < modified_files.txt
68+
69+
# Append image report for modified images
70+
echo -e "| Path | Old | New |" >> report.md
71+
echo -e "|---|---|---|" >> report.md
72+
paste modified_files.txt modified_images_old.md modified_images_new.md -d"|" | awk '{print "|", $0, "|"}' >> report.md
73+
74+
# Added images
75+
echo -e "### Added images\n" >> report.md
5776
while IFS= read -r line; do
5877
echo -e "- $line \n" >> report.md
5978
cml-publish --title $line --md "$line" >> report.md < /dev/null
60-
done < diff_files.txt
61-
79+
done < adde_files.txt
6280
echo -e "</details>\n" >> report.md
6381
6482
# Mention git commit SHA in the report

0 commit comments

Comments
 (0)