libexec/dna in alpha_omega-0.0.142 vs libexec/dna in alpha_omega-0.0.150
- old
+ new
@@ -1,7 +1,119 @@
#!/bin/bash -e
+function bump_version {
+ ensure_clean_git_status
+
+ local_file=
+ if [[ -f VERSION || -L VERSION ]]; then
+ local_file=1
+ if [[ ! -e VERSION ]]; then
+ echo "ERROR: cannot write to VERSION file" 1>&2
+ exit 1
+ fi
+ fi
+
+ tmp_version=$(mktemp -t XXXXXXXXX)
+ if [[ -n $local_file ]]; then
+ cp VERSION $tmp_version
+ else
+ git tag | perl -ne 'm{^v(\d+)\.(\d+)\.(\d+)$} && printf("v%03d.%03d.%03d v%d.%d.%d\n",$1,$2,$3,$1,$2,$3)' | sort -r | head -1 | awk '{print $2}' > $tmp_version
+ fi
+
+ case "$1" in
+ patch|minor|major)
+ bump=$1; shift
+ set $(cat $tmp_version | sed 's#\.# #g')
+ case "$bump" in
+ patch)
+ echo "$1.$2.$(($3 + 1))"
+ ;;
+ minor)
+ echo "$1.$(($2 + 1)).0"
+ ;;
+ major)
+ echo "$(($1 + 1)).0.0"
+ ;;
+ esac > $tmp_version
+ ;;
+ *)
+ ver_new=$1; shift
+ set $(echo "$ver_new" | sed 's#\.# #g') 0
+ M=$1; shift
+ m=$1; shift
+ p=$1; shift
+
+ (echo "$(($M+0)).$(($m+0)).$(($p+0))" > $tmp_version) 2>&-
+ ver_new_same=$(cat $tmp_version)
+
+ if [[ $ver_new != $ver_new_same ]]; then
+ echo "ERROR: invalid version: $ver_new" 1>&2
+ exit 1
+ fi
+ ;;
+ esac
+
+ ver_bumped=$(cat $tmp_version)
+ rm -f $tmp_version
+ ensure_git_tag_available "v$ver_bumped"
+
+ if [[ -n $local_file ]]; then
+ echo $ver_bumped > VERSION
+ git add VERSION
+ if [[ -f Gemfile ]]; then
+ bundle check 2>&1 >/dev/null || { bundle --quiet install --local --path vendor/bundle || bundle check > /dev/null; }
+ git add Gemfile.lock
+ fi
+
+ git commit -m "bump: $ver_bumped"
+ git push
+ fi
+
+ git_tag "v$ver_bumped"
+ echo $ver_bumped
+}
+
+function ensure_git_tag_available {
+ version=$1; shift
+ git fetch --tags
+ remote_sha=$(git ls-remote origin $version | awk '{print $1}')
+ if [[ -n $remote_sha ]]; then
+ echo "ERROR: already a remote tag $version, bump again" 1>&2
+ exit 1
+ fi
+
+ local_sha=$(git show-ref $version | awk '{print $1}')
+ if [[ -n $local_sha ]]; then
+ echo "ERROR: already a local tag $version" 1>&2
+ exit 1
+ fi
+}
+
+function git_tag {
+ local version=$1; shift
+
+ ensure_git_tag_available "$version"
+
+ git tag $version
+ git push origin tag $version
+ remote_sha=$(git ls-remote origin $version | awk '{print $1}')
+ local_sha=$(git show-ref $version | awk '{print $1}')
+ if [[ $remote_sha != $local_sha ]]; then
+ echo "ERROR: remote tag $version does not match local SHA" 1>&2
+ exit 1
+ fi
+}
+
+function ensure_clean_git_status {
+ local lines=$(git status -s -uno | wc -l | awk '{print $1}')
+ if [[ $lines != "0" ]]; then
+ echo "ERROR: git status is not clean, cannot tag" 1>&2
+ git status -s -uno
+ exit 1
+ fi
+}
+
case "$(basename $0)" in
bump)
true
;;
*)
@@ -71,58 +183,11 @@
fi
} 2>&1 | grep eea914aaa8dde6fdae29242b1084a2b0415eefaf | sed 's#eea914aaa8dde6fdae29242b1084a2b0415eefaf ##'
;;
bump)
- case "$1" in
- patch|minor|major)
- bump=$1; shift
- set $(cat VERSION | sed 's#\.# #g')
- case "$bump" in
- patch)
- echo "$1.$2.$(($3 + 1))"
- ;;
- minor)
- echo "$1.$(($2 + 1)).0"
- ;;
- major)
- echo "$(($1 + 1)).0.0"
- ;;
- esac > VERSION
- ;;
- *)
- ver_new=$1; shift
- set $(echo "$ver_new" | sed 's#\.# #g') 0
- M=$1; shift
- m=$1; shift
- p=$1; shift
-
- tmp_version=$(mktemp -t XXXXXXXXX)
- (echo "$(($M+0)).$(($m+0)).$(($p+0))" > $tmp_version) 2>&-
- ver_new_same=$(cat $tmp_version)
- rm -f $tmp_version
-
- if [[ $ver_new = $ver_new_same ]]; then
- echo "$ver_new" > VERSION
- else
- echo "ERROR: invalid version: $ver_new" 1>&2
- exit 1
- fi
- ;;
- esac
-
- if [[ -f Gemfile ]]; then
- bundle check 2>&1 >/dev/null || { bundle --quiet install --local --path vendor/bundle || bundle check > /dev/null; }
- git add Gemfile.lock
- fi
-
- git add VERSION
-
- ver_bumped=$(cat VERSION)
- git commit -m "bump: $ver_bumped"
- git tag "v$ver_bumped"
- echo $ver_bumped
+ bump_version "$@"
;;
*)
LOCAL_ONLY=
if [[ -n $1 ]]; then
@@ -188,10 +253,46 @@
compare)
bundle exec cap "$@" deploy:compare
;;
migrate)
- bundle exec cap "$@" deploy:migrate
+ want_list=
+ if [[ $1 = "list" ]]; then
+ want_list=1; shift
+ fi
+
+ change_group=
+ migration=
+ case $1 in
+ data)
+ change_group=$1; shift
+ ;;
+ pre)
+ change_group=$1; shift
+ ;;
+ during)
+ change_group=$1; shift
+ ;;
+ post)
+ change_group=$1; shift
+ ;;
+ [0123456789][0123456789][0123456789][0123456789][0123456789][0123456789][0123456789][0123456789][0123456789][0123456789][0123456789][0123456789][0123456789][0123456789])
+ migration=$1; shift
+ ;;
+ esac
+
+ if [[ -n $change_group ]]; then
+ if [[ -n $want_list ]]; then
+ echo "listing change group $change_group"
+ else
+ echo "running change group $change_group"
+ fi
+ elif [[ -n $migration ]]; then
+ echo "running migration $migratio"
+ elif [[ -n $want_list ]]; then
+ echo "listing migrations"
+ fi
+ #bundle exec cap "$@" deploy:migrate
;;
*)
bundle exec cap "$@"
;;