Last active
December 14, 2016 18:46
-
-
Save adamkirkwood/c034d7fc8965890044e2de5eea00da08 to your computer and use it in GitHub Desktop.
Cut Github-ready releases for your Sketch files
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
#!/usr/bin/env bash | |
BASEFILENAME=API-Connect-Patterns | |
EXTENSIONNAME=sketch | |
SKETCHFILE=`$BASEFILENAME.$EXTENSIONNAME` | |
CURRENT_BRANCH=$(git symbolic-ref --short -q HEAD) | |
CURRENT_VERSION=$(node -e "console.log(require('./package.json').version);") | |
# Prevent cutting releases from master branch | |
if [ "$CURRENT_BRANCH" != "master" ]; then | |
echo "You may only cut releases from the master branch" | |
exit 1 | |
fi | |
# Check for uncommited changes or untracked files | |
if ! [[ -z $(git status -s) ]]; then | |
echo "Resolve any uncommited changes or untracked files to Git before cutting a release." | |
git status -s | |
exit 1 | |
fi | |
# Check for version bumping scheme | |
if [ -z "$1" ]; then | |
echo "A release version or bump type must be specified" | |
echo "[<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease | from-git]" | |
exit 1 | |
fi | |
# Bump version number | |
npm version $1 --no-git-tag-version -m "" | |
# Check if the release already exists | |
GITTAG=$(git ls-remote origin refs/tags/$RELEASE_VERSION) | |
if [ "$GITTAG" != "" ]; then | |
echo "Tag for package.json version already exists, aborting release" | |
exit 1 | |
fi | |
# Export screenshots | |
sketchtool export artboards --output=$(pwd)/screenshots --formats=jpg --overwriting=yes $SKETCHFILE | |
# Stage any changes/additions to Git | |
git add ./screenshots | |
# Generate versioned archival copy in ./archive | |
VERSION=$(node -e "console.log(require('./package.json').version);") | |
RELEASE_VERSION="v$VERSION" | |
VERSIONED_SKETCHFILENAME=`$BASEFILENAME-$RELEASE_VERSION.$EXTENSIONNAME` | |
cp ./$SKETCHFILE ./archive/$VERSIONED_SKETCHFILENAME | |
git commit -am "add screenshots for $RELEASE_VERSION" | |
git tag -a $RELEASE_VERSION -m "Release $RELEASE_VERSION" | |
git push origin $RELEASE_VERSION |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment