#!/bin/bash
+selfdir=$(dirname $(readlink -f $0))
self=`basename $0`
+selfpath=$selfdir/$self
version=$1
+version_xyz=`echo $version | awk 'BEGIN { FS="." } { printf("%d.%d.%d", $1, $2, $3); }'`
branch=$2
user=$3
action=$4
tagForVersion=v${version}
+shift 4
+
+rundir=`pwd`
+versiondir=$rundir/$version
###############################################################################
eval $1=\${repositories[$(($2 * 2 + 1))]}
}
+function version_xyz {
+ echo $version
+}
+
###############################################################################
function msg {
git clone ssh://${user}@www.simantics.org:29418/$1
}
+function add {
+ echo "git add $@"
+ git add $@
+}
+
function branch {
echo "git branch $1"
git branch $1
}
+function commit {
+ echo "git commit $@"
+ git commit $@
+}
+
function fetch {
echo "git fetch --all"
git fetch --all
}
function status {
- git status
+ git status $@
+}
+
+function diff {
+ git diff --stat --patch $@
+}
+
+function log {
+ git log --pretty --oneline --graph --decorate=full $@
}
function listTags {
git branch -a
}
+function repl {
+ local from=$1
+ local to=$2
+ shift 2
+ for i in $@; do
+ echo "Replacing $from' with '$to' in file $i"
+ cat $i | awk "{ gsub(\"$from\", \"$to\"); print }" > $i.tmp
+ mv $i.tmp $i
+ done
+}
+
+function bumpSequenceNumber {
+ echo "bumpSequenceNumber '$1'"
+ cat $i | awk '
+BEGIN {
+ regex="sequenceNumber=\"[0-9]+\"";
+ cmd = "date +%s"
+ cmd | getline epoch
+ close(cmd)
+}
+{
+ if (match($0, regex)) {
+ before = substr($0,1,RSTART-1);
+ after = substr($0,RSTART+RLENGTH);
+ printf("%ssequenceNumber=\"%s\"%s\n", before, epoch, after);
+ } else {
+ print;
+ }
+}
+' > $i.tmp
+ mv $i.tmp $i
+}
+
###############################################################################
case "$action" in
esac
if [ -n "$version" ] && [ -d $version ]; then
- pushd $version > /dev/null
+ pushd $version >/dev/null || action="*"
+elif [ -n "$version" ]; then
+ # The directory does not exist yet so don't do anything
+ action="*"
fi
case "$action" in
+ add)
+ for (( i=0; i<${repositoryCount}; i++ )); do
+ localPath lp $i
+ msg $i "Stage changes in $lp"
+ pushd $lp > /dev/null
+ add $@
+ popd > /dev/null
+ done
+ ;;
branch)
for (( i=0; i<${repositoryCount}; i++ )); do
localPath lp $i
popd > /dev/null
done
;;
+ commit)
+ for (( i=0; i<${repositoryCount}; i++ )); do
+ localPath lp $i
+ msg $i "Checkout $branch branch in $lp"
+ pushd $lp > /dev/null
+ commit $@
+ popd > /dev/null
+ done
+ ;;
tag)
for (( i=0; i<${repositoryCount}; i++ )); do
localPath lp $i
localPath lp $i
msg $i "Status of $lp"
pushd $lp > /dev/null
- status
+ status $@
popd > /dev/null
done
;;
- *)
- echo "Usage: ${self} <version> <branch-name> <user-name> clone|branch|checkout|fetch|list-tags|pull|push|push-tags|remove-tag|status|tag"
- if [ -d $version ]; then
- echo "Version directory ('$version') does not exist yet. Please run the 'clone' action first."
- fi
+ diff)
+ for (( i=0; i<${repositoryCount}; i++ )); do
+ localPath lp $i
+ msg $i "Diff $branch branch in $lp"
+ pushd $lp > /dev/null
+ diff $@
+ popd > /dev/null
+ done
+ ;;
+ log)
+ for (( i=0; i<${repositoryCount}; i++ )); do
+ localPath lp $i
+ msg $i "Log of $lp"
+ pushd $lp > /dev/null
+ log $@
+ popd > /dev/null
+ done
+ ;;
+ reset)
+ for (( i=0; i<${repositoryCount}; i++ )); do
+ localPath lp $i
+ msg $i "'git reset $@' in $lp"
+ pushd $lp > /dev/null
+ git reset $@
+ popd > /dev/null
+ done
+ ;;
+
+ prepare-release-branch)
+ fromBranch=$1
+
+ # Fix branch name from P2 repository locations
+ for i in platform/releng/org.simantics.sdk.build.targetdefinition/*.{tpd,target} \
+ simupedia/fi.semantum.simupedia.build.targetdefinition/*.{tpd,target}
+ do
+ repl "/$fromBranch/" "/$branch/" $i
+ done
+
+ # Bump .target file sequenceNumbers
+ for i in platform/releng/org.simantics.sdk.build.targetdefinition/*.target \
+ simupedia/fi.semantum.simupedia.build.targetdefinition/*.{tpd,target}
+ do
+ bumpSequenceNumber $i
+ done
+
+ pushd platform
+ git commit -a -m "Configured $branch branch for SDK builds"
+ git commit --amend
+ popd
+ pushd simupedia
+ git commit -a -m "Configured $branch branch for SDK builds"
+ git commit --amend
+ popd
;;
+
+ bump-master-version)
+ fromVersion=$1
+ toVersion=$2
+
+ bash $selfpath $version master $user checkout
+
+ repl "$fromVersion" "$toVersion" platform/bundles/org.simantics.desktop.product/splash.svg
+ repl "$fromVersion" "$toVersion" platform/features/org.simantics.sdk.feature/feature.xml
+ repl "$fromVersion" "$toVersion" platform/releng/org.simantics.sdk.repository/pom.xml
+ repl "Simantics $fromVersion" "Simantics $toVersion" platform/releng/org.simantics.sdk.build.targetdefinition/simantics.{tpd,target}
+ repl "Simupedia $fromVersion" "Simupedia $toVersion" simupedia/fi.semantum.simupedia.build.targetdefinition/*.{tpd,target}
+ repl "Simupedia SDK $fromVersion" "Simupedia SDK $toVersion" simupedia/fi.semantum.simupedia.build.targetdefinition/*.{tpd,target}
+
+ pushd platform
+ git commit -a -m "Bumped master version to $toVersion"
+ git commit --amend
+ popd
+
+ pushd simupedia
+ git commit -a -m "Bumped master version to $toVersion"
+ git commit --amend
+ popd
+ ;;
+
+ branch-release)
+ fromBranch=$1
+ popd > /dev/null
+ bash $selfpath $version $fromBranch $user checkout
+ bash $selfpath $version $branch $user branch
+ bash $selfpath $version $branch $user checkout
+ bash $selfpath $version $branch $user prepare-release-branch $fromBranch
+ #$selfpath $version $branch $user push
+ ;;
+
+ *)
+ if [ "$version" ] && [ ! -d $versiondir ]; then
+ echo -e "Version directory ('$versiondir') does not exist yet. Run 'clone' action first.\n"
+ fi
+ echo "Usage: ${self} <version> <branch-name> <user-name> <command> [<command-arguments>]"
+ echo ""
+ echo "Commands:"
+ echo " clone The first thing that needs to be done before anything else"
+ echo " Clones all platform repositories under directory <version>"
+ echo ""
+ echo "Inspection commands:"
+ echo " diff [args] Run git diff [args] for each platform repository"
+ echo " log [args] Run git log [args] for each platform repository"
+ echo " status [args] Run git status [args] for each platform repository"
+ echo " list-tags Run git tag -l for each repository"
+ echo ""
+ echo "Action:"
+ echo " add "
+ echo " branch Run git branch <branch-name> for each platform repository"
+ echo " checkout Run git checkout <branch-name> for each repository"
+ echo " commit "
+ echo " fetch Run git fetch --all for each repository"
+ echo " pull Run git pull --all for each repository"
+ echo " push Run git push origin <branch> for each repository"
+ echo " push-tags Run git push --tags for each repository"
+ echo " remove-tag Run git tag -d v<branch> for each repository"
+ echo " reset [args] Run git reset [args] for each repository"
+ echo " tag Run git checkout <branch> and"
+ echo " git tag -a v<branch> -m \"Simantics <branch> simultaneous release\""
+ echo " for each repository"
+ echo ""
+ echo "Compound release commands:"
+ echo " prepare-release-branch <from-branch>"
+ echo " <from-branch> the name of the branch that the codebase is currently on"
+ echo ""
+ echo "Top-level release commands:"
+ echo " bump-master-version <from-version> <to-version>"
+ echo " <from-version> the version string to replace"
+ echo " <to-version> the replacing new version string"
+ echo ""
+ echo " branch-release <from-branch>"
+ echo " <from-branch> the branch to create the service branch from"
+ echo " e.g. master or release/x.y.z"
+ echo ""
+ echo "Processed repositories:"
+ for (( i=0; i<${repositoryCount}; i++ )); do
+ repo p $i
+ msg $i "$p"
+ done
+
+;;
esac