Skip to content

Instantly share code, notes, and snippets.

@sebastienkb
Created December 18, 2019 10:04
Show Gist options
  • Save sebastienkb/8c1cc5c4fcd856023bad378fe2718c69 to your computer and use it in GitHub Desktop.
Save sebastienkb/8c1cc5c4fcd856023bad378fe2718c69 to your computer and use it in GitHub Desktop.
Script to help safe-check and release an internal CocoaPod
#!/bin/bash
function fail() {
echo "❌ $1"
exit 1
}
function success() {
echo "✅ $1"
}
function release() {
local SCRIPT_NAME="$1"
local POD_NAME="$2"
local VERSION="$3"
local CHECK_RULE=true
local SPEC_REPO="your-cocoapods-specs-repo"
if [[ $4 == "--force" ]]; then
CHECK_RULE=false
success "Forcing release by ignoring some checks"
fi
if [[ "$#" -le 1 ]]; then
fail "Usage: $SCRIPT_NAME POD_NAME VERSION [--force]"
fi
cd "$POD_NAME"
local PODSPEC_NAME=$(ls *.podspec)
if [ -z "$PODSPEC_NAME" ]; then
fail "Could not find $PODSPEC_NAME in current location"
fi
if [[ $(cat "$PODSPEC_NAME" | grep "\.version =" | grep -c "$VERSION") == 0 ]]; then
fail "Version in $PODSPEC_NAME does not match version $VERSION, please edit $PODSPEC_NAME, git push and try again.\nbash# open $(pwd)/$PODSPEC_NAME"
fi
git update-index --refresh && git diff-index --quiet HEAD --
if [[ $CHECK_RULE && $? != 0 ]]; then
fail "You have uncommitted changes in git. Please commit or stash your changes."
fi
git fetch --all
git fetch --tags
if [[ $CHECK_RULE && $(git log origin/master..master | wc -l | sed -e 's/^[[:space:]]*//') > 0 ]]; then
fail "You have unpushed changes in git. Please push your commits."
fi
if [[ $(git ls-remote --tags origin $VERSION | wc -l | sed -e 's/^[[:space:]]*//') > 0 ]]; then
fail "Tag '$VERSION' already exists on origin. Either remove the tag on origin or put the next version."
fi
if [[ $CHECK_RULE && $(git describe --tags "$(git rev-list --tags --max-count=1)") == "$VERSION" && $(git tag -l --points-at HEAD) != "$VERSION" ]]; then
fail "Tag '$VERSION' exists but is not your last commit. Either remove the tag locally or put the next version."
fi
git tag "$VERSION" && success "Committed tag $VERSION"
git push origin "$VERSION" && success "Pushed tag $VERSION"
pod repo push "$SPEC_REPO" "$PODSPEC_NAME" --allow-warnings
if [[ $? != 0 ]]; then
git tag -d $VERSION
git push --delete origin $VERSION
fail "Could not push to $SPEC_REPO, removed tags."
fi
success "Pushed to $SPEC_REPO"
pod repo update && success "Local repo updated"
echo "👉 You may need to run 'pod update --repo-update' for changes to take effect."
}
release "$0" "$1" "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment