# enforce project dir
cd ${CI_PROJECT_DIR}
# setup origin with rw permissions
git config --global user.name "${GITLAB_USER_LOGIN}" && git config --global user.email "${GITLAB_USER_EMAIL}"
git remote set-url origin "https://${GITLAB_USER_LOGIN}:${CI_PAT}@gitlab.com/${CI_PROJECT_PATH}.git"
git fetch

yarn config set python /usr/bin/python2.7

git pull origin ${MAIN_BRANCH_NAME}
# switch to release branch
(git checkout ${RELEASE_BRANCH_NAME} && git pull) || git checkout -b ${RELEASE_BRANCH_NAME}
git merge origin/${MAIN_BRANCH_NAME}
# init packages in parent theme
cd ../${PARENT_THEME}
yarn install
# build assets
cd ${CI_PROJECT_DIR}
yarn install --frozen-lockfile
yarn run build
# increase theme version
awk -F '.' 'BEGIN{OFS="."}/Version/{$3=$3+1}1' style.css > style2.css && mv style2.css style.css
# force add build folder and commit
git add -f build/*
git add style.css
# commit build and push
git commit -am "@cibuild ${CI_COMMIT_MESSAGE}" || true # dont panic
git push -u origin ${RELEASE_BRANCH_NAME}
