Created
June 14, 2017 08:58
-
-
Save fuxx/04baa6e469befc9b9e175863b7903622 to your computer and use it in GitHub Desktop.
Cocoapods auto tagging private repo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# dont allow any error | |
set -e | |
set -o xtrace | |
set -x | |
export LANG=en_US.UTF-8 | |
export LANGUAGE=en_US.UTF-8 | |
export LC_ALL=en_US.UTF-8 | |
PATH="$PATH:/usr/local/bin" | |
if [ -z "${bamboo_podname}" ] || [ -z "${bamboo_podspecfilename}" ]; then | |
echo "podname or podspecfilename is not set. Both are required in your Bamboo plan variables to run the autotag script." | |
exit -1 | |
fi | |
# grep current version and lookup cocoa pods folder if tag already exists | |
spec_version=`egrep -o "s.version[ ].+(\"|')([0-9]+.[0-9]+.[0-9]+)(\"|')" "${bamboo_podspecfilename}" | egrep -o "([0-9]+.[0-9+].[0-9]+)"` | |
spec_folder="~/.cocoapods/repos/<Private Pod Repo Name (Use pod repo list)>/${bamboo_podname}/$spec_version" | |
# if no version is found quit | |
if [ "$spec_version" == "" ];then | |
echo "Getting version failed. Did the format changed?" | |
exit 1 | |
fi | |
# if version is same, we dont need to tag | |
if [ -d "$spec_folder" ]; then | |
echo "Version already exists. Everything fine" | |
exit 0 | |
fi | |
# get current commit and tag | |
commit_hash=`git rev-parse HEAD` | |
# If no hash found, quit | |
if [ "$commit_hash" == "" ];then | |
echo "Failed to get commit hash" | |
exit 3 | |
fi | |
# Add remote repo and double check if tag already exists, we only tag new versions! | |
git remote add central "${bamboo_planRepository_1_repositoryUrl}" || true | |
set +e | |
git ls-remote --exit-code --tags central "$spec_version" | |
if [ $? -eq 0 ]; then | |
echo "## Tag already exist" | |
exit 0 | |
fi | |
set -e | |
# Unshallow repository | |
git fetch --tags --unshallow central | |
# check if version already exists | |
git tag -f "$spec_version" "${bamboo_planRepository_1_revision}" | |
#git push central tag "$spec_version" | |
git push central --tags --force | |
# check if tag could be set | |
git ls-remote --exit-code --tags central "$spec_version" | |
# tag for pods | |
# Create temp folder where pod specs will be checked out too | |
tempfolder=`mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'` | |
# Add exit handler to clean up created folders | |
function onExit { | |
echo "Cleaning up $tempfolder" | |
rm -Rf $tempfolder | |
} | |
trap onExit EXIT | |
# checkout private podspec repo to tempfolder | |
git clone <your private pod repo> "$tempfolder" | |
# set destination path | |
podSpecPath="$tempfolder/${bamboo_podname}/$spec_version" | |
# Check that we dont overwrite a pod spec file! | |
if [ -d "$podSpecPath" ]; then | |
echo "Folder for version already exists! Aborting..." | |
exit 4 | |
fi | |
# create folder for version | |
mkdir "$podSpecPath" | |
# Copy pod spec | |
cp "${bamboo_podspecfilename}" "$podSpecPath" | |
cd "$podSpecPath" | |
# Commit pod spec and push | |
git add . | |
git commit -m "[Update] ${bamboo_podname} ($spec_version)" | |
git push -u origin master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment