forked from OpenLineage/OpenLineage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-spec-snapshot.sh
executable file
·45 lines (39 loc) · 1.51 KB
/
run-spec-snapshot.sh
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
#!/bin/bash
# Copy changed spec JSON files to website static folder
# This is necessary to keep within repo history of all the spec versions
# Initialize CHANGE_DONE to 0 (no changes detected by default)
CHANGE_DONE=0
# Use process substitution to avoid subshell problem
while read -r LINE; do
# Ignore registry files
if [[ $LINE =~ "registry.json" ]]; then
continue
fi
# Extract target file name from $id field in spec files using jq
URL=$(cat "$LINE" | jq -r '.["$id"]')
# Extract target location in website repo
LOC="website/static/${URL#*//*/}"
LOC_DIR="${LOC%/*}"
# Create dir if necessary, and copy files
mkdir -p "$LOC_DIR"
cp "$LINE" "$LOC"
echo $LOC
# Check if the file is tracked by Git
if git ls-files --error-unmatch "$LOC" &>/dev/null; then
# The file is tracked by Git
# Check if the copied file differs from the committed version and is not staged
if ! git diff --quiet HEAD -- "$LOC"; then
# Check if the differences are not already staged
if git diff --quiet --cached -- "$LOC"; then
echo "Change detected in $LINE: $LOC differs from committed version but is not staged"
CHANGE_DONE=1 # Mark as change detected
fi
fi
else
# The file is untracked by Git
echo "Change detected in $LINE: $LOC is untracked"
CHANGE_DONE=1 # Mark as change detected
fi
done < <(git diff --name-only HEAD -- 'spec/*.json' 'spec/OpenLineage.yml')
# Exit with the value of CHANGE_DONE (0 if no changes, 1 if there were changes)
exit $CHANGE_DONE