Sfoglia il codice sorgente

change the way release building/publishing is done

Adam Shaw 10 anni fa
parent
commit
79169c1df4
4 ha cambiato i file con 109 aggiunte e 30 eliminazioni
  1. 52 0
      build/build-release.sh
  2. 28 0
      build/publish-release.sh
  3. 0 30
      build/release.sh
  4. 29 0
      build/require-clean-working-tree.sh

+ 52 - 0
build/build-release.sh

@@ -0,0 +1,52 @@
+#!/usr/bin/env bash
+
+# always immediately exit upon error
+set -e
+
+# start in project root
+cd "`dirname $0`/.."
+
+./build/require-clean-working-tree.sh
+
+read -p "Have you already updated the changelog? (y/n): " updated_changelog
+if [[ "$updated_changelog" != "y" ]]
+then
+	echo "Go do that!"
+	exit 1
+fi
+
+read -p "Enter the new version number with no 'v' (for example '1.0.1'): " version
+if [[ ! "$version" ]]
+then
+	echo "Aborting."
+	exit 1
+fi
+
+# will do everything necessary for a release,
+# including bumping version in .json files
+grunt bump --setversion=$version
+grunt dist
+
+# save reference to current branch
+orig_ref=$(git symbolic-ref --quiet HEAD)
+
+# make a tagged detached commit of the dist files.
+# no-verify avoids commit hooks.
+# make this a boolean expression that doesn't exit upon error.
+git checkout --detach --quiet && \
+git add *.json && \
+git add -f dist/*.js dist/*.css dist/lang/*.js && \
+git commit -e -m "version $version" && \
+git tag -a "v$version" -m "version $version" || true
+
+# if failure building the commit, there will be leftover .json changes.
+# always discard. won't be harmful otherwise.
+git checkout "$orig_ref" -- *.json
+
+# go back to the original branch.
+# need to reset so dist files are not staged.
+# this will be executed regardless of whether the commit was built correctly.
+git symbolic-ref HEAD "$orig_ref"
+git reset
+
+echo "DONE"

+ 28 - 0
build/publish-release.sh

@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+
+# always immediately exit upon error
+set -e
+
+# start in project root
+cd "`dirname $0`/.."
+
+./build/require-clean-working-tree.sh
+
+read -p "Enter the version you want to publish, with no 'v' (for example '1.0.1'): " version
+if [[ ! "$version" ]]
+then
+	echo "Aborting."
+	exit 1
+fi
+
+# push the current branch (assumes tracking is set up) and the tag
+git push
+git push origin "v$version"
+
+# temporarily checkout the tag's commit for publishing to NPM
+current_branch=$(git symbolic-ref --quiet --short HEAD)
+git checkout --quiet "v$version"
+npm publish
+git checkout --quiet "$current_branch"
+
+echo "DONE"

+ 0 - 30
build/release.sh

@@ -1,30 +0,0 @@
-#!/usr/bin/env bash
-
-cd "`dirname $0`/.."
-
-read -p "Enter the new version number with no 'v' (for example '1.0.1'): " version
-
-if [[ ! "$version" ]]
-then
-	exit
-fi
-
-grunt bump --setversion=$version && \
-grunt dist && \
-git add -f dist/*.js dist/*.css dist/lang/*.js && \
-git commit -a -e -m "version $version" && \
-git tag -a v$version -m "version $version"
-
-status=$?
-
-# regardless of error/success
-git reset
-
-if [ $status -eq 0 ]
-then
-	echo
-	echo 'DONE. It is now up to you to run `'"git push origin master && git push origin v$version"'`'
-	echo
-	echo 'and `npm publish`'
-	echo
-fi

+ 29 - 0
build/require-clean-working-tree.sh

@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+
+# http://stackoverflow.com/questions/3878624/how-do-i-programmatically-determine-if-there-are-uncommited-changes
+
+# Update the index
+git update-index -q --ignore-submodules --refresh
+err=0
+
+# Disallow unstaged changes in the working tree
+if ! git diff-files --quiet --ignore-submodules --
+then
+	echo >&2 "You have unstaged changes."
+	git diff-files --name-status -r --ignore-submodules -- >&2
+	err=1
+fi
+
+# Disallow uncommitted changes in the index
+if ! git diff-index --cached --quiet HEAD --ignore-submodules --
+then
+	echo >&2 "Your index contains uncommitted changes."
+	git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
+	err=1
+fi
+
+if [ $err = 1 ]
+then
+	echo >&2 "Please commit or stash them."
+	exit 1
+fi