sync.sh
· 1021 B · Bash
Ham
#!/bin/bash
set -e # bail on errors
GLOB=$1
IS_CI="${CI:-false}"
BASE=$(pwd)
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
for folder in $GLOB; do
[ -d "$folder" ] || continue
cd $BASE
if [ -n "$(git status --porcelain)" ]; then
git add .
git commit -m "chore: update template"
git push origin main
fi
NAME=${folder##*/}
CLONE_DIR="__${NAME}__clone__"
# sync to read-only clones
# clone, delete files in the clone, and copy (new) files over
# this handles file deletions, additions, and changes seamlessly
# note: redirect output to dev/null to avoid any possibility of leaking token
git clone --quiet --depth 1 git@github.com:shadcn/${NAME}.git $CLONE_DIR > /dev/null
cd $CLONE_DIR
find . | grep -v ".git" | grep -v "^\.*$" | xargs rm -rf # delete all files (to handle deletions in monorepo)
cp -r $BASE/$folder/. .
if [ -n "$(git status --porcelain)" ]; then
git add .
git commit -m "$COMMIT_MESSAGE"
git push origin main
fi
cd $BASE
rm -rf $CLONE_DIR
done
1 | #!/bin/bash |
2 | |
3 | set -e # bail on errors |
4 | GLOB=$1 |
5 | IS_CI="${CI:-false}" |
6 | BASE=$(pwd) |
7 | COMMIT_MESSAGE=$(git log -1 --pretty=%B) |
8 | |
9 | for folder in $GLOB; do |
10 | [ -d "$folder" ] || continue |
11 | cd $BASE |
12 | |
13 | if [ -n "$(git status --porcelain)" ]; then |
14 | git add . |
15 | git commit -m "chore: update template" |
16 | git push origin main |
17 | fi |
18 | |
19 | NAME=${folder##*/} |
20 | CLONE_DIR="__${NAME}__clone__" |
21 | |
22 | # sync to read-only clones |
23 | # clone, delete files in the clone, and copy (new) files over |
24 | # this handles file deletions, additions, and changes seamlessly |
25 | # note: redirect output to dev/null to avoid any possibility of leaking token |
26 | git clone --quiet --depth 1 git@github.com:shadcn/${NAME}.git $CLONE_DIR > /dev/null |
27 | cd $CLONE_DIR |
28 | find . | grep -v ".git" | grep -v "^\.*$" | xargs rm -rf # delete all files (to handle deletions in monorepo) |
29 | cp -r $BASE/$folder/. . |
30 | |
31 | if [ -n "$(git status --porcelain)" ]; then |
32 | git add . |
33 | git commit -m "$COMMIT_MESSAGE" |
34 | git push origin main |
35 | fi |
36 | |
37 | cd $BASE |
38 | rm -rf $CLONE_DIR |
39 | done |
40 |