Skip to content

Theme editor changes #59

Theme editor changes

Theme editor changes #59

name: Validate Exporter JSON Changes
on:
pull_request:
paths:
- '**/exporter*.json'
jobs:
validate_exporter_json:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Fetch Base and Head References
run: |
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }}
git fetch origin ${{ github.head_ref }}:${{ github.head_ref }}
- name: Validate JSON Changes
run: |
changed_files=$(git diff --name-only ${{ github.base_ref }} ${{ github.head_ref }} | grep 'exporter.*\.json$')
if [ -z "$changed_files" ]; then
echo "No exporter JSON files have changed."
exit 0
fi
# Loop through each changed file
for file in $changed_files; do
# Fetch the base and head versions of the file
base_file=$(git show ${{ github.base_ref }}:$file)
head_file=$(git show ${{ github.head_ref }}:$file)
# Compare the JSON keys
base_keys=$(echo "$base_file" | jq -r 'paths | map(tostring) | join(".")' | sed 's/\./\\./g')
head_keys=$(echo "$head_file" | jq -r 'paths | map(tostring) | join(".")' | sed 's/\./\\./g')
# Check for removed keys
removed_keys=$(comm -23 <(echo "$base_keys" | sort) <(echo "$head_keys" | sort))
if [ -n "$removed_keys" ]; then
echo "Backward incompatibility change detected in $file. The following keys were removed:"
echo "$removed_keys"
exit 1
fi
# Check for changed values
for key in $base_keys; do
base_value=$(echo "$base_file" | jq -r --arg key "$key" '.[$key]')
head_value=$(echo "$head_file" | jq -r --arg key "$key" '.[$key]')
if [ "$base_value" != "$head_value" ]; then
echo "Backward incompatibility change detected in $file. The value of key '$key' was changed from '$base_value' to '$head_value'."
exit 1
fi
done
done
echo "All exporter JSON files have only additions. No backward incompatibility changes detected."
shell: bash