#!/bin/bash

# Load .zprofile if it exists
if [ -f ~/.zprofile ]; then
    source ~/.zprofile
fi

# Load .bash_profile if it exists
if [ -f ~/.bash_profile ]; then
    source ~/.bash_profile
fi

# Load .bashrc if it exists (optional)
if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi

# Load .zshrc if it exists (optional)
if [ -f ~/.zshrc ]; then
    source ~/.zshrc
fi


echo $PATH

echo "Current workspace: ${PWD}"
#cd ../dart_framework && git pull origin master
#cd ../${JOB_NAME}

#bash ./assets/script/shell/check_rev.sh

flutter pub upgrade --major-versions
flutter packages upgrade
flutter pub get

## 현재 리비전 체크
REV_OLD=`cat git_rev.txt`
git rev-list --all HEAD --all --count > git_rev.txt
REV_NEW=`cat git_rev.txt`

echo "$REV_OLD"
echo "$REV_NEW"

RESULT=FALSE
if [ ${REV_OLD} -ne ${REV_NEW} ] ; then
    RESULT=TRUE
fi

#파일로 출력
#echo $RESULT > result.txt
#파일에 내용 읽기
#RESULT=$(head -n 1 result.txt)

if [ ${RESULT} == "TRUE" ] ; then
    echo "Build Start!"
    flutter clean
    flutter pub upgrade --major-versions
    flutter packages upgrade
    flutter pub get
    flutter pub run build_runner build --delete-conflicting-outputs
    echo "Build End!"
fi