#!/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 ############################################################################### declare -a repositories=( "simantics/third-party.git" "third-party" "simantics/platform.git" "platform" "simantics/fmil.git" "fmil" "simantics/interop.git" "interop" "simantics/district.git" "district" "simantics/matlab.git" "matlab" "simantics/python.git" "python" "simantics/r.git" "r" "simantics/sysdyn.git" "sysdyn" "simantics/3d.git" "3d" "members/fmi.git" "fmi" "members/simupedia.git" "simupedia" "gold-members/proteus.git" "proteus" ) repositoryCount=$((${#repositories[@]} / 2)) function repo { eval $1=\${repositories[$(($2 * 2))]} } function localPath { eval $1=\${repositories[$(($2 * 2 + 1))]} } function version_xyz { echo $version } ############################################################################### function msg { echo "[$(($1+1))/${repositoryCount}] $2" } function clone { echo "git clone ssh://${user}@www.simantics.org:29418/$1" 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 pull { echo "git pull --all" git pull --all } function pushBranch { echo "git push origin $1" git push origin $1 } function checkout { echo "git checkout $1" git checkout $1 } function tag { echo "git tag $1 -m \"Simantics $1 simultaneous release\"" git tag $1 -m "Simantics $1 simultaneous release" } function removeTag { echo "git tag -d $1" git tag -d $1 } function pushTags { echo "git push origin --tags" git push origin --tags } function status { git status $@ } function diff { git diff --stat --patch $@ } function log { git log --pretty --oneline --graph --decorate=full $@ } function listTags { git tag -l } function listBranches { 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 clone) mkdir -p $version pushd $version > /dev/null for (( i=0; i<${repositoryCount}; i++ )); do repo p $i msg $i "Clone $p" clone $p done popd > /dev/null exit 0 ;; esac if [ -n "$version" ] && [ -d $version ]; then 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 msg $i "Create $branch branch in $lp" pushd $lp > /dev/null branch $branch popd > /dev/null done ;; checkout) for (( i=0; i<${repositoryCount}; i++ )); do localPath lp $i msg $i "Checkout $branch branch in $lp" pushd $lp > /dev/null checkout $branch 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 msg $i "Tag ${version} for $lp" pushd $lp > /dev/null checkout $branch tag ${tagForVersion} popd > /dev/null done ;; list-branches) for (( i=0; i<${repositoryCount}; i++ )); do localPath lp $i msg $i "List branches in $lp" pushd $lp > /dev/null listBranches popd > /dev/null done ;; list-tags) for (( i=0; i<${repositoryCount}; i++ )); do localPath lp $i msg $i "List tags in $lp" pushd $lp > /dev/null listTags popd > /dev/null done ;; remove-tag) for (( i=0; i<${repositoryCount}; i++ )); do localPath lp $i msg $i "Remove tag $tagForVersion from $lp" pushd $lp > /dev/null removeTag ${tagForVersion} popd > /dev/null done ;; fetch) for (( i=0; i<${repositoryCount}; i++ )); do localPath lp $i msg $i "Fetch from remote origin in $lp" pushd $lp > /dev/null fetch popd > /dev/null done ;; pull) for (( i=0; i<${repositoryCount}; i++ )); do localPath lp $i msg $i "Pull from remote origin in $lp" pushd $lp > /dev/null pull popd > /dev/null done ;; push) for (( i=0; i<${repositoryCount}; i++ )); do localPath lp $i msg $i "Push branch $branch to remote origin in $lp" pushd $lp > /dev/null pushBranch $branch popd > /dev/null done ;; push-tags) for (( i=0; i<${repositoryCount}; i++ )); do localPath lp $i msg $i "Push tags to remote origin in $lp" pushd $lp > /dev/null pushTags popd > /dev/null done ;; status) for (( i=0; i<${repositoryCount}; i++ )); do localPath lp $i msg $i "Status of $lp" pushd $lp > /dev/null status $@ popd > /dev/null done ;; 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 if [ -ne $fromBranch ]; then bash $selfpath $version $fromBranch $user checkout fi 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} []" echo "" echo "Commands:" echo " clone The first thing that needs to be done before anything else" echo " Clones all platform repositories under directory " 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 for each platform repository" echo " checkout Run git checkout 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 for each repository" echo " push-tags Run git push --tags for each repository" echo " remove-tag Run git tag -d v for each repository" echo " reset [args] Run git reset [args] for each repository" echo " tag Run git checkout and" echo " git tag -a v -m \"Simantics simultaneous release\"" echo " for each repository" echo "" echo "Compound release commands:" echo " prepare-release-branch " echo " the name of the branch that the codebase is currently on" echo "" echo "Top-level release commands:" echo " bump-master-version " echo " the version string to replace" echo " the replacing new version string" echo "" echo " branch-release " echo " 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