-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
clone-and-validate.sh
executable file
·47 lines (40 loc) · 1.2 KB
/
clone-and-validate.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
#!/bin/bash
FOLDER=$1
CLONE=$2
IS_CI="${CI:-false}"
BASE=$(pwd)
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
if [ "$IS_CI" = true ]; then
sudo apt-get update && sudo apt-get install jq
fi
for folder in $FOLDER/*; do
[ -d "$folder" ] || continue # only directories
cd $BASE
NAME=$(cat $folder/package.json | jq -r '.name')
CLONE_DIR="__${NAME}__clone__"
# sync to read-only clones
if [ "$CLONE" = true ]; then
# clone, delete files in the clone, and copy (new) files over
# this handles file deletions, additions, and changes seamlessly
git clone --depth 1 https://$GITHUB_API_TOKEN@github.com/gatsbyjs/$NAME.git $CLONE_DIR
cd $CLONE_DIR
find . | grep -v ".git" | grep -v "^\.*$" | xargs rm -rf # delete all files (to handle deletions in monorepo)
cp -r $BASE/$folder/. .
rm -rf yarn.lock
yarn import # generate a new yarn.lock file based on package-lock.json
git add .
git commit --message "$COMMIT_MESSAGE"
git push origin master
else
# validate
cd $folder
npm audit &&
npm install &&
# check both npm and yarn, sometimes yarn registry lags behind
rm -rf node_modules &&
yarn &&
npm run build ||
exit 1
fi
cd $BASE
done