Skip to content

Commit

Permalink
Improve the DVC image diff workflow to support side-by-side compariso…
Browse files Browse the repository at this point in the history
…n of modified images
  • Loading branch information
seisman committed Apr 21, 2021
1 parent b528586 commit bd43348
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions .github/workflows/dvc-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,51 @@ jobs:
# | Status | Path |
# |----------|-------------------------------------|
# | added | pygmt/tests/baseline/test_image.png |
- name: Put list of images that were added or changed into report
# | deleted | pygmt/tests/baseline/test_image2.png |
# | modified | pygmt/tests/baseline/test_image3.png |
- name: Generate the image diff report
env:
repo_token: ${{ secrets.GITHUB_TOKEN }}
id: image-diff
run: |
echo -e "## Summary of changed images\n" > report.md
echo -e "This is an auto-generated report of images that have changed on the DVC remote\n" >> report.md
dvc diff --show-md master HEAD >> report.md
cat report.md
- name: Pull image data from cloud storage
run: dvc pull --remote upstream
- name: Put image diff(s) into report
env:
repo_token: ${{ secrets.GITHUB_TOKEN }}
id: image-diff
run: |
# Get just the filename of the changed image from the report
awk 'NF==5 && NR>=7 {print $4}' report.md > diff_files.txt
# Get just the filename of the added and modified image from the report
awk 'NF==5 && NR>=7 && $2=="added" {print $4}' report.md > added_files.txt
awk 'NF==5 && NR>=7 && $2=="modified" {print $4}' report.md > modified_files.txt
# Append each image to the markdown report
echo -e "## Image diff(s)\n" >> report.md
echo -e "<details>\n" >> report.md
# Modified images
echo -e "### Modified images\n" >> report.md
# Upload old images
while IFS= read -r line; do
cml-publish --title $line --md "$line" > modified_images_old.md < /dev/null
done < modified_files.txt
# Pull image data from cloud storage
dvc pull --remote upstream
# Upload new images
while IFS= read -r line; do
cml-publish --title $line --md "$line" > modified_images_new.md < /dev/null
done < modified_files.txt
# Append image report for modified images
echo -e "| Path | Old | New |" >> report.md
echo -e "|---|---|---|" >> report.md
paste modified_files.txt modified_images_old.md modified_images_new.md -d"|" | awk '{print "|", $0, "|"}' >> report.md
# Added images
echo -e "### Added images\n" >> report.md
while IFS= read -r line; do
echo -e "- $line \n" >> report.md
cml-publish --title $line --md "$line" >> report.md < /dev/null
done < diff_files.txt
done < adde_files.txt
echo -e "</details>\n" >> report.md
# Mention git commit SHA in the report
Expand Down

0 comments on commit bd43348

Please sign in to comment.