Update vercel.sh (#1983)

bugfix/slow-month-change
Omar López 2022-02-25 13:13:56 -07:00 committed by GitHub
parent 546f627177
commit 48f969eae5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 42 additions and 24 deletions

View File

@ -1,8 +1,10 @@
# github submodule repo address without https:// prefix
SUBMODULE_GITHUB=github.com/calcom/website
# github submodule repo addresses without https:// prefix
# .gitmodules submodule path
SUBMODULE_PATH=apps/website
# This didn't work ¯\_(ツ)_/¯
# declare -A remotes=(
# ["apps/website"]="github.com/calcom/website"
# ["apps/api"]="github.com/calcom/api"
# )
# github access token is necessary
# add it to Environment Variables on Vercel
@ -15,27 +17,43 @@ fi
set -e
# get submodule commit
output=`git submodule status --recursive` # get submodule info
no_prefix=${output#*-} # get rid of the prefix
COMMIT=${no_prefix% *} # get rid of the suffix
output=$(git submodule status --recursive) # get submodule info
# set up an empty temporary work directory
rm -rf tmp || true # remove the tmp folder if exists
mkdir tmp # create the tmp folder
cd tmp # go into the tmp folder
# Extract each submodule commit hash and path
submodules=$(echo $output | sed "s/ -/__/g" | sed "s/ /=/g" | sed "s/-//g" | tr "__" "\n")
# checkout the current submodule commit
git config --global init.defaultBranch main
git config --global advice.detachedHead false
git init # initialise empty repo
git remote add origin https://$GITHUB_ACCESS_TOKEN@$SUBMODULE_GITHUB # add origin of the submodule
git fetch --depth=1 origin $COMMIT # fetch only the required version
git checkout $COMMIT # checkout on the right commit
# move the submodule from tmp to the submodule path
cd .. # go folder up
rm -rf tmp/.git # remove .git
mv tmp/* $SUBMODULE_PATH/ # move the submodule to the submodule path
for submodule in $submodules; do
IFS="=" read COMMIT SUBMODULE_PATH <<<"$submodule"
# clean up
rm -rf tmp # remove the tmp folder
# This should be a hash table but couldn't make it work ¯\_(ツ)_/¯
# SUBMODULE_GITHUB=$remotes[$SUBMODULE_PATH]
if [ "$SUBMODULE_PATH" == "apps/website" ]; then
SUBMODULE_GITHUB=github.com/calcom/website
fi
if [ "$SUBMODULE_PATH" == "apps/api" ]; then
SUBMODULE_GITHUB=github.com/calcom/api
fi
# set up an empty temporary work directory
rm -rf tmp || true # remove the tmp folder if exists
mkdir tmp # create the tmp folder
cd tmp # go into the tmp folder
# checkout the current submodule commit
git init # initialise empty repo
git remote add $SUBMODULE_PATH https://$GITHUB_ACCESS_TOKEN@$SUBMODULE_GITHUB # add origin of the submodule
git fetch --depth=1 $SUBMODULE_PATH $COMMIT # fetch only the required version
git checkout $COMMIT # checkout on the right commit
# move the submodule from tmp to the submodule path
cd .. # go folder up
rm -rf tmp/.git # remove .git
mv tmp/* $SUBMODULE_PATH/ # move the submodule to the submodule path
# clean up
rm -rf tmp # remove the tmp folder
done