Skip to content

Commit

Permalink
Initial folder diff workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeLonewolf committed Oct 8, 2023
1 parent 2cd228c commit 8f6a018
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .github/workflows/build-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ jobs:
echo "MAIN_STATS<<EOF" >> $GITHUB_ENV
echo -e "$MAIN_STATS" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Capture main branch sample clips
id: main-samples
run: |
npm start & command_pid=$!
sleep 5
npm run generate_samples
kill $command_pid
mv samples samples-main
- name: Checkout PR Branch 🛎️
uses: actions/checkout@v3
- name: Use Node.js 18.16.1
Expand All @@ -52,6 +60,14 @@ jobs:
cp src/configs/config.aws.js src/config.js
mkdir -p dist/shield-docs
cp -r shieldlib/docs/* dist/shield-docs
- name: Capture PR branch sample clips
id: pr-samples
run: |
npm start & command_pid=$!
sleep 5
npm run generate_samples
kill $command_pid
mv samples samples-pr
- name: Upload Build artifact
uses: actions/upload-artifact@v3
with:
Expand All @@ -71,6 +87,11 @@ jobs:
echo '${{ env.MAIN_STATS }}'
echo '${{ env.PR_STATS }}'
npm exec ts-node scripts/stats_compare '${{ env.MAIN_STATS }}' '${{ env.PR_STATS }}' > pr/stats-difference.md
- name: Generate map diff sample clips
id: map-diff-samples
run: |
mv sample_differences.md pr/
mv samples-diff pr/
- name: Save PR artifacts
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/deploy-pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ jobs:
<img src="https://preview.ourmap.us/pr/${{ env.PR_NUM }}/sprites/sprite.png" />
<img src="https://preview.ourmap.us/pr/${{ env.PR_NUM }}/sprites/[email protected]" />
## Map sample differences
" > pr_preview.md
echo pr/sample_differences.md >> pr_preview.md
- uses: tibdex/github-app-token@v1
id: checks_token
with:
Expand Down
55 changes: 55 additions & 0 deletions scripts/folder_diff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
# Compare two folders of images and produce an .md file of differences

# Check if the right number of arguments are passed
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <folder1> <folder2>"
exit 1
fi

FOLDER1="$1"
FOLDER2="$2"
OUTPUT_FOLDER="samples-diff"

# Create the output folder if it doesn't exist
mkdir -p "$OUTPUT_FOLDER"

# Loop through files in FOLDER1
for file in "$FOLDER1"/*.png; do
# Extract just the base filename without the path
basefile=$(basename "$file")

# Check if file exists in FOLDER2
if [ -e "$FOLDER2/$basefile" ]; then
# Compare the files
cmp -s "$FOLDER1/$basefile" "$FOLDER2/$basefile"

# If files are different ($? is the exit status of last command, 1 means different for cmp)
if [ $? -eq 1 ]; then
# Copy the files to the output folder with the appropriate naming scheme
cp "$FOLDER1/$basefile" "$OUTPUT_FOLDER/${basefile%.*}_before.png"
cp "$FOLDER2/$basefile" "$OUTPUT_FOLDER/${basefile%.*}_after.png"
fi
fi
done

OUTPUT_MD="sample_differences.md"

# Start the table with headers
echo "| Sample Name | Before | After |" > $OUTPUT_MD
echo "|-------------|--------|-------|" >> $OUTPUT_MD

# Loop through *_before.png files in the output folder
for before_file in "$OUTPUT_FOLDER"/*_before.png; do
# Extract just the base filename without the path and the '_before' suffix
basefile=$(basename "$before_file" _before.png)

# Construct the path to the corresponding after file
after_file="$OUTPUT_FOLDER/${basefile}_after.png"

# Check if the after file exists
if [ -e "$after_file" ]; then
# Add an entry to the markdown table
echo "| $basefile | ![before]($before_file) | ![after]($after_file) |" >> $OUTPUT_MD
fi
done
2 changes: 1 addition & 1 deletion src/js/shield_defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ export function loadShields() {
textColor: Color.shields.brown,
colorLighten: Color.shields.brown,
},
["HIST"],
["XYZA"], //Change to be removed before merging
Color.shields.brown
);

Expand Down

0 comments on commit 8f6a018

Please sign in to comment.