Add script to compute container image tag

By putting this logic into its own script other tools like Jenkins
pipelines can use it to compute the expected container image tag.

Change-Id: Ie91a5310eca85fe7fce790e7a568b210c9e4d846
diff --git a/build b/build
index ddb58a8..aa8de36 100755
--- a/build
+++ b/build
@@ -85,17 +85,10 @@
     fi
 
     if test -z "$TAG"; then
-        export TAG="$(create_image_tag)"
+        export TAG="$(./get_version.sh)"
     fi
 }
 
-create_image_tag(){
-    GERRIT_VERSION=$(docker run --platform=linux/amd64 --entrypoint "/bin/sh" gerrit-base:$REV \
-        -c "java -jar /var/gerrit/bin/gerrit.war version")
-    GERRIT_VERSION=$(echo "${GERRIT_VERSION##*$'\n'}" | cut -d' ' -f3 | tr -d '[:space:]')
-    echo "$REV-$GERRIT_VERSION"
-}
-
 REPORT="Build results: \n"
 RETURN_CODE=0
 
diff --git a/get_version.sh b/get_version.sh
new file mode 100755
index 0000000..df2dc0f
--- /dev/null
+++ b/get_version.sh
@@ -0,0 +1,5 @@
+REV=$(git describe --always --dirty)
+GERRIT_VERSION=$(docker run --platform=linux/amd64 --entrypoint "/bin/sh" gerrit-base:$REV \
+    -c "java -jar /var/gerrit/bin/gerrit.war version")
+GERRIT_VERSION=$(echo "${GERRIT_VERSION##*$'\n'}" | cut -d' ' -f3 | tr -d '[:space:]')
+echo "$REV-$GERRIT_VERSION"
diff --git a/publish b/publish
index 957ef7b..ba8d368 100755
--- a/publish
+++ b/publish
@@ -2,7 +2,7 @@
 
 usage() {
     me=`basename "$0"`
-    echo >&2 "Usage: $me [--help] [--update-latest] [--registry REGISTRY] [--org ORGANIZATION] [--no-push] --tag TAG [IMAGE]"
+    echo >&2 "Usage: $me [--help] [--update-latest] [--registry REGISTRY] [--org ORGANIZATION] [--no-push] [--tag TAG] [IMAGE]"
     exit 1
 }
 
@@ -44,9 +44,7 @@
 done
 
 if test -z "$TAG"; then
-  echo "No tag was provided."
-  echo "Use either the --tag option or provide a TAG-environment variable."
-  usage
+  TAG=$(./get_version.sh)
 fi
 
 #Get list of images