Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: check ecobalyse-data sync for PR #915

Merged
merged 7 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/ecobalyse-data-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: ecobalyse-data sync

on:
pull_request:
branches: [ master, staging ]
workflow_dispatch:

jobs:
check-ecobalyse-data-sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Check synchronization with ecobalyse-data for generated JSON
run: ./bin/check-ecobalyse-data-sync.sh
73 changes: 73 additions & 0 deletions bin/check-ecobalyse-data-sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash
set -euo pipefail

# Directory where files will be downloaded
TEMP_DIR=$(mktemp -d)
ECOBALYSE_DATA_BRANCH="${ECOBALYSE_DATA_BRANCH:-main}"
ECOBALYSE_DATA_REPO="${ECOBALYSE_DATA_REPO:-MTES-MCT/ecobalyse-data}"
RAW_GITHUB_URL="https://raw.githubusercontent.com/${ECOBALYSE_DATA_REPO}/${ECOBALYSE_DATA_BRANCH}"
DIFFERENCES_FOUND=0

# Cleanup function
cleanup() {
rm -rf "$TEMP_DIR"
}
trap cleanup EXIT

# Files to check
FILES=(
"public/data/food/ingredients.json"
"public/data/food/processes.json"
"public/data/textile/materials.json"
"public/data/textile/processes.json"
"public/data/object/processes.json"
)

echo "Downloading files from ecobalyse-data repository (branch: ${ECOBALYSE_DATA_BRANCH})..."

# Create necessary directories in TEMP_DIR
for file in "${FILES[@]}"; do
mkdir -p "$TEMP_DIR/$(dirname "$file")"
done

# Download each file
for file in "${FILES[@]}"; do
curl -s "$RAW_GITHUB_URL/$file" -o "$TEMP_DIR/$file" || {
echo "--⚠️ Failed to download $file from ecobalyse-data repository"
continue
}
done

echo "Comparing JSON files between ecobalyse-data and ecobalyse repositories..."

for file in "${FILES[@]}"; do
if [ -f "$file" ]; then
other_file="$TEMP_DIR/$file"

if [ -f "$other_file" ]; then
# Compare files and store the diff output
diff_output=$(diff -u "$file" "$other_file" || true)
if [ -n "$diff_output" ]; then
echo "--❌ $file is different:"
echo "$diff_output"
DIFFERENCES_FOUND=1
else
echo "--✅ $file is synchronized"
fi
else
echo "--⚠️ $file does not exist in ecobalyse-data repository"
DIFFERENCES_FOUND=1
fi
else
echo "--⚠️ $file does not exist in ecobalyse repository"
DIFFERENCES_FOUND=1
fi
done

if [ $DIFFERENCES_FOUND -eq 1 ]; then
echo "❌ Differences found between repositories ecobalyse-data and ecobalyse"
exit 1
else
echo "✅ All JSON files are synchronized"
exit 0
fi