-
Notifications
You must be signed in to change notification settings - Fork 592
/
check-and-commit.sh
executable file
·77 lines (62 loc) · 1.78 KB
/
check-and-commit.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
set -euo pipefail
GIT_BRANCH="${GITHUB_REF/refs\/heads\//}"
git checkout $GIT_BRANCH
echo "On branch $GIT_BRANCH."
echo ""
echo "------- Checking Schema -------"
echo ""
# Commit the schema if outdated
if ! git diff --exit-code ./build/vega-lite-schema.json
then
## Only do this for master
if [[ $GIT_BRANCH == 'master' ]]; then
echo "Outdated schema."
exit 1
else
git add ./build/vega-lite-schema.json
git commit -m "chore: update schema [CI]"
fi
fi
echo ""
echo "------- Checking Examples -------"
echo ""
if git log -1 | grep "\[SVG\]" && [[ $GIT_BRANCH != 'master' ]]; then
echo "As the latest commit includes [SVG]. Rebuilding all SVGs."
yarn build:examples-full
else
yarn build:examples
fi
# Commit examples if outdated
# Note: we need to add all files first so that new files are included in `git diff --cached` too.
git add examples
if [[ $GIT_BRANCH == 'master' ]]; then
# Don't diff SVG as floating point calculation is not always consistent
if ! git diff --cached --word-diff=color --exit-code './examples/compiled/*.vg.json' './examples/specs/normalized/*.vl.json'
then
echo "Outdated examples."
exit 1
fi
else
if ! git diff --cached --word-diff=color --exit-code examples
then
git commit -m "chore: update examples [CI]"
fi
fi
echo ""
echo "------- Checking Code Formatting -------"
echo ""
if [[ $GIT_BRANCH != 'master' ]]; then
## For non-master branch, commit eslint fix and prettier changes if outdated
if ! git diff --exit-code site src test test-runtime
then
git add --all
git commit -m "style: auto-formatting [CI]"
fi
# should be empty
git status
# Then push all the changes (schema, examples, prettier)
git pull --rebase origin ${GITHUB_REF}
git push origin ${GITHUB_REF}
fi
exit 0