Skip to content

Commit

Permalink
Update release script for a more modern-ish release process (#1086)
Browse files Browse the repository at this point in the history
  • Loading branch information
younata committed Sep 17, 2023
1 parent edaedc1 commit 5ac0475
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ build/
.idea
DerivedData/
Nimble.framework.zip
Nimble.xcframework.zip

# Carthage
#
Expand Down
98 changes: 52 additions & 46 deletions script/release
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@ POD_NAME=Nimble
PODSPEC=Nimble.podspec

POD=${COCOAPODS:-"bundle exec pod"}
CARTHAGE=${CARTHAGE:-"carthage"}
GH=${GH:-"gh"}

function help {
echo "Usage: release VERSION RELEASE_NOTES [-f]"
echo "Usage: release VERSION [-f]"
echo
echo "VERSION should be the version to release, should not include the 'v' prefix"
echo "RELEASE_NOTES should be a file that lists all the release notes for this version"
echo " if file does not exist, creates a git-style commit with a diff as a comment"
echo
echo "FLAGS"
echo " -f Forces override of tag"
echo
echo " Example: ./release 1.0.0-rc.2 ./release-notes.txt"
echo
echo "HINT: use 'git diff <PREVIOUS_TAG>...HEAD' to build the release notes"
echo " Example: ./release 1.0.0-rc.2"
echo
exit 2
}
Expand All @@ -28,23 +26,35 @@ function die {
exit 1
}

if [ $# -lt 2 ]; then
if [ $# -lt 1 ]; then
help
fi

VERSION=$1
RELEASE_NOTES=$2
FORCE_TAG=$3
FORCE_TAG=$2

VERSION_TAG="v$VERSION"

echo "-> Verifying Local Directory for Release"

if [ -z "`which $POD`" ]; then
die "Cocoapods is required to produce a release. Aborting."
die "Cocoapods is required to produce a release. Install with rubygems using 'gem install cocoapods'. Aborting."
fi
echo " > Cocoapods is installed"

if [ -z "`which $CARTHAGE`" ]; then
die "Carthage is required to produce a release. Install with brew using 'brew install carthage'. Aborting."
fi
echo " > Carthage is installed"

if [ -z "`which $GH`" ]; then
die "gh (github CLI) is required to produce a release. Install with brew using 'brew install gh'. Aborting."
fi

echo " > Verifying you are authenticated with the github CLI"
$GH auth status > /dev/null || die "You are not authenticated with the github CLI. Please authenticate using '$GH auth login'."
echo " > Logged in with github CLI"

echo " > Is this a reasonable tag?"

echo $VERSION_TAG | grep -q "^vv"
Expand All @@ -69,27 +79,6 @@ else
echo " > Yes, tag is unique"
fi

if [ ! -f "$RELEASE_NOTES" ]; then
echo " > Failed to find $RELEASE_NOTES. Prompting editor"
RELEASE_NOTES=/tmp/nimble.release.notes
LATEST_TAG=`git for-each-ref refs/tags --sort=-refname --format="%(refname:short)" | grep -E "^v\d+\.\d+\.\d+(-\w+(\.\d)?)?\$" | ruby -e 'puts STDIN.read.split("\n").sort { |a,b| Gem::Version.new(a.gsub(/^v/, "")) <=> Gem::Version.new(b.gsub(/^v/, "")) }.last'`
echo " > Latest tag ${LATEST_TAG}"
echo "${POD_NAME} v$VERSION" > $RELEASE_NOTES
echo "================" >> $RELEASE_NOTES
echo >> $RELEASE_NOTES
echo "# Changelog from ${LATEST_TAG}..HEAD" >> $RELEASE_NOTES
git log ${LATEST_TAG}..HEAD | sed -e 's/^/# /' >> $RELEASE_NOTES
$EDITOR $RELEASE_NOTES
diff -q $RELEASE_NOTES ${RELEASE_NOTES}.backup > /dev/null 2>&1
STATUS=$?
rm ${RELEASE_NOTES}.backup
if [ $STATUS -eq 0 ]; then
rm $RELEASE_NOTES
die "No changes in release notes file. Aborting."
fi
fi
echo " > Release notes: $RELEASE_NOTES"

if [ ! -f "$PODSPEC" ]; then
die "Cannot find podspec: $PODSPEC. Aborting."
fi
Expand All @@ -115,11 +104,10 @@ git config --get user.signingkey > /dev/null || {
}
echo " > Found PGP key for git"

# Verify cocoapods trunk ownership
# Veify cocoapods trunk ownership
pod trunk me | grep -q "$POD_NAME" || die "You do not have access to pod repository $POD_NAME. Aborting."
echo " > Verified ownership to $POD_NAME pod"


echo "--- Releasing version $VERSION (tag: $VERSION_TAG)..."

function restore_podspec {
Expand All @@ -132,7 +120,6 @@ echo "-> Ensuring no differences to origin/$REMOTE_BRANCH"
git fetch origin || die "Failed to fetch origin"
git diff --quiet HEAD "origin/$REMOTE_BRANCH" || die "HEAD is not aligned to origin/$REMOTE_BRANCH. Cannot update version safely"


echo "-> Setting podspec version"
cat "$PODSPEC" | grep 's.version' | grep -q "\"$VERSION\""
SET_PODSPEC_VERSION=$?
Expand All @@ -145,17 +132,24 @@ else
}

git add ${PODSPEC} || { restore_podspec; die "Failed to add ${PODSPEC} to INDEX"; }
git commit -m "Bumping version to $VERSION" || { restore_podspec; die "Failed to push updated version: $VERSION"; }

echo "--- Updating Docs ---"
./script/build_docs.zsh
git add docs || { git co docs; die "Failed to add docs to INDEX"; }

git commit -m "[$VERSION_TAG] Update docs and podspec" || { restore_podspec; die "Failed to push updated version: $VERSION"; }
fi

RELEASE_NOTES="Version ${VERSION}. Open https://github.com/Quick/Nimble/releases/tag/$VERSION_TAG for full release notes."

if [ -z "$FORCE_TAG" ]; then
echo "-> Tagging version"
git tag -s "$VERSION_TAG" -F "$RELEASE_NOTES" || die "Failed to tag version"
git tag -s "$VERSION_TAG" -m "$RELEASE_NOTES" || die "Failed to tag version"
echo "-> Pushing tag to origin"
git push origin "$VERSION_TAG" || die "Failed to push tag '$VERSION_TAG' to origin"
else
echo "-> Tagging version (force)"
git tag -f -s "$VERSION_TAG" -F "$RELEASE_NOTES" || die "Failed to tag version"
git tag -s -f "$VERSION_TAG" -m "$RELEASE_NOTES" || die "Failed to tag version"
echo "-> Pushing tag to origin (force)"
git push origin "$VERSION_TAG" -f || die "Failed to push tag '$VERSION_TAG' to origin"
fi
Expand All @@ -165,23 +159,35 @@ if [ $SET_PODSPEC_VERSION -ne 0 ]; then
echo " > Pushed version to origin"
fi

echo
echo "---------------- Released as $VERSION_TAG ----------------"
echo

echo
echo "Pushing to pod trunk..."

# NOTE: remove allow-warnings after v9.0.0 of Nimble
$POD trunk push "$PODSPEC" --allow-warnings --skip-import-validation
$POD trunk push "$PODSPEC"

echo "Creating a carthage archive to include in the release"
$CARTHAGE build --archive --use-xcframeworks
zip -r Nimble.xcframework.zip Carthage/Build/Nimble.xcframework

# Check version tag to determine whether to mark the release as a prerelease version or not.
echo $VERSION_TAG | grep -q -E "^v\d+\.\d+\.\d+\$"
if [ $? -eq 0 ]; then
PRERELEASE_FLAGS=""
else
PRERELEASE_FLAGS="-p"
fi

echo "Creating a github release using auto-generated notes."

$GH release create -R Quick/Nimble $VERSION_TAG Nimble.xcframework.zip Nimble.framework.zip --generate-notes $PRERELEASE_FLAGS

echo
echo "================ Finalizing the Release ================"
echo
echo " - Opening GitHub to mark this as a release..."
echo " - Paste the contents of $RELEASE_NOTES into the release notes. Tweak for GitHub styling."
echo " - Opening GitHub to allow for any edits to the release notes."
echo " - You should add a Highlights section at the top to call out any notable changes or fixes."
echo " - In particular, any breaking changes should be listed under Highlights."
echo " - Announce!"

open "https://github.com/Quick/Nimble/releases/new?tag=$VERSION_TAG"
open "https://github.com/Quick/Nimble/releases/tag/$VERSION_TAG"

rm ${PODSPEC}.backup

0 comments on commit 5ac0475

Please sign in to comment.