-
Notifications
You must be signed in to change notification settings - Fork 58
51 lines (40 loc) · 1.68 KB
/
exporter-validate-pr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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(".")')
head_keys=$(echo "$head_file" | jq -r 'paths | map(tostring) | join(".")')
# 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
done
echo "All exporter JSON files have only additions. No backward incompatibility changes detected."
shell: bash