Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit 83990c8b40db0fc7602c0bca8267c357ebef1c2b @richardhodgson richardhodgson committed
Showing with 127 additions and 0 deletions.
  1. +3 −0 Makefile
  2. +15 −0 README.md
  3. +42 −0 bin/usenode-release
  4. +30 −0 tests/create-mock-project
  5. +37 −0 tests/test-release
3 Makefile
@@ -0,0 +1,3 @@
+
+test:
+ ./tests/test-release
15 README.md
@@ -0,0 +1,15 @@
+# Goals
+
+- Provide simple script to release and publish usenode projects
+- Keep usenode publish code in once place
+-- Get version
+-- Read version in
+-- Tag in github
+-- Npm publish
+- Provide a Makefile template for any new usenode projects
+- Document
+
+# Todo
+
+- Npm publish
+- Makefile template
42 bin/usenode-release
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+CURRENT_DIR=$(pwd)
+
+PROJECT=$1
+NEW_VERSION=$2
+PACKAGE="$PROJECT/package.json"
+
+if [ "x$PROJECT" = "x" ]; then
+ echo "Usage: usenode-publish path/to/project [new_version]"
+ exit 0
+fi
+
+if [ ! -r $PACKAGE ]; then
+ echo "Could not find package.json at $PACKAGE"
+ exit 0
+fi
+
+PROJECT_NAME=`cat $PACKAGE | egrep '"name"' | awk -F \" '/([\d]*)/{ print $4}'`
+echo "Publishing '$PROJECT_NAME'."
+
+CURRENT_VERSION=`cat $PACKAGE | egrep '"version"' | awk -F \" '/([\d]*)/{ print $4}'`
+echo "Current version is $CURRENT_VERSION."
+
+if [ "x$NEW_VERSION" = "x" ]; then
+ echo "Enter the new version:"
+ read NEW_VERSION
+fi
+
+if [ "$CURRENT_VERSION "== "$NEW_VERSION" ]; then
+ echo "Cannot create release, $NEW_VERSION is the current version."
+ exit 0
+fi
+
+echo "Creating version $NEW_VERSION"
+sed /version/s/$CURRENT_VERSION/$NEW_VERSION/ $PACKAGE > $PACKAGE.tmp && mv $PACKAGE.tmp $PACKAGE
+
+(cd $PROJECT
+git commit -m "Version for release $NEW_VERSION" package.json
+git tag v$NEW_VERSION
+git push origin master
+git push --tags)
30 tests/create-mock-project
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+MOCKPROJECT=$1
+
+if [ "x$MOCKPROJECT" = "x" ]; then
+ echo "Usage: create-mock-project path/to/project"
+ exit 0
+fi
+
+echo "Mocking project at $1"
+
+rm -fr $MOCKPROJECT $MOCKPROJECT-head
+mkdir $MOCKPROJECT
+
+CURRENT_DIR=$(pwd)
+
+(cd $MOCKPROJECT
+git init
+echo '{' > package.json
+echo '"name": "mockproject",' >> package.json
+echo '"version": "1.2.3"' >> package.json
+echo '}' >> package.json
+git add package.json
+git commit -m "Adding package.json" package.json)
+
+(git clone --bare $MOCKPROJECT $MOCKPROJECT-head)
+
+(cd $MOCKPROJECT
+MOCKPROJECT_NAME=`basename $MOCKPROJECT`
+git remote add origin ../$MOCKPROJECT_NAME-head)
37 tests/test-release
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+ROOT=`dirname $0`
+MOCKPROJECT=$ROOT/../../usenode-release-mockproject
+
+function assert {
+ ACTUAL=$1
+ EXPECTED=$2
+ MESSAGE=$3
+
+ if [ "$ACTUAL" == "$EXPECTED" ]; then
+ echo "PASS: $MESSAGE"
+ else
+ echo "FAIL: $MESSAGE"
+ echo " Failed asserting that '$ACTUAL' is equal to '$EXPECTED'."
+ fi
+}
+
+# Test input validation
+MISSING_ARGUMENTS=`$ROOT/../bin/usenode-release`
+assert "$MISSING_ARGUMENTS" "Usage: usenode-publish path/to/project [new_version]" "Script outputs usage message if no arguments are passed"
+
+CANNOT_FIND_PACKAGE_JSON=`$ROOT/../bin/usenode-release $MOCKPROJECT-does-not-exist`
+assert "$CANNOT_FIND_PACKAGE_JSON" "Could not find package.json at $MOCKPROJECT-does-not-exist/package.json" "Script throws an error if cannot find package.json at project location"
+
+# Test package.json is updated
+$ROOT/create-mock-project $MOCKPROJECT > /dev/null
+$ROOT/../bin/usenode-release $MOCKPROJECT 2.3.4
+
+PACKAGE_VERSION_NUMBER=`cat $MOCKPROJECT/package.json | egrep '"version"'`
+assert "$PACKAGE_VERSION_NUMBER" '"version": "2.3.4"' "Version number is updated in package.json"
+
+PACKAGE_COMMIT_MESSAGE_FROM_LOG=`cd $MOCKPROJECT; git log package.json | egrep 'Version'`
+assert "$PACKAGE_COMMIT_MESSAGE_FROM_LOG" " Version for release 2.3.4" "Changes to package.json are commited"
+
+REMOTE_LOG=`cd $MOCKPROJECT-head; git log | egrep 'Version'`
+assert "$REMOTE_LOG" " Version for release 2.3.4" "Changes are pushed to remote"

0 comments on commit 83990c8

Please sign in to comment.
Something went wrong with that request. Please try again.