VOL-1996 Use v-prefixed versions with golang projects
Change-Id: I0de8742fa41b957fe3c6f13ace5b63836ead7993
diff --git a/jjb/pipeline/docker-publish.groovy b/jjb/pipeline/docker-publish.groovy
index 9b2e74b..2b55663 100644
--- a/jjb/pipeline/docker-publish.groovy
+++ b/jjb/pipeline/docker-publish.groovy
@@ -64,8 +64,10 @@
then
for tag in $git_tags
do
- echo "Building image with tag: \$tag (should reuse cached layers)"
- make DOCKER_TAG="\$tag" docker-build
+ # remove leading 'v' on funky golang tags
+ clean_tag=$(echo \$tag | sed 's/^v//g')
+ echo "Building image with tag: \$clean_tag (should reuse cached layers)"
+ make DOCKER_TAG="\$clean_tag" docker-build
done
fi
""")
@@ -98,8 +100,10 @@
then
for tag in $git_tags
do
- echo "Pushing image with tag: \$tag (should reuse cached layers)"
- make DOCKER_TAG="\$tag" docker-push
+ # remove leading 'v' on funky golang tags
+ clean_tag=$(echo \$tag | sed 's/^v//g')
+ echo "Pushing image with tag: \$clean_tag (should reuse cached layers)"
+ make DOCKER_TAG="\$clean_tag" docker-push
done
fi
""")
diff --git a/jjb/shell/github-release.sh b/jjb/shell/github-release.sh
index 2ab2c94..2ded191 100644
--- a/jjb/shell/github-release.sh
+++ b/jjb/shell/github-release.sh
@@ -44,7 +44,8 @@
pushd "$GERRIT_PROJECT"
GIT_VERSION=$(git tag -l --points-at HEAD)
- if [[ "$GIT_VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]
+ # match bare versions or v-prefixed golang style version
+ if [[ "$GIT_VERSION" =~ ^v?([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]
then
echo "git has a SemVer released version tag: '$GIT_VERSION'"
echo "Building artifacts for GitHub release."
diff --git a/jjb/shell/pypi-publish.sh b/jjb/shell/pypi-publish.sh
index b7f3526..3118df7 100755
--- a/jjb/shell/pypi-publish.sh
+++ b/jjb/shell/pypi-publish.sh
@@ -26,7 +26,8 @@
# check that we're on a semver released version
GIT_VERSION=$(git tag -l --points-at HEAD)
-if [[ "$GIT_VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]
+# match bare versions or v-prefixed golang style version
+if [[ "$GIT_VERSION" =~ ^v?([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]
then
echo "git has a SemVer released version tag: '$GIT_VERSION', publishing to PyPI"
else
diff --git a/jjb/shell/tagcollisionreject.sh b/jjb/shell/tagcollisionreject.sh
index 49d6e21..309e35c 100755
--- a/jjb/shell/tagcollisionreject.sh
+++ b/jjb/shell/tagcollisionreject.sh
@@ -21,6 +21,7 @@
VERSIONFILE="" # file path to file containing version number
NEW_VERSION="" # version number found in $VERSIONFILE
+TAG_VERSION="" # version file that might have a leading v to work around go mod funkyness
SEMVER_STRICT=${SEMVER_STRICT:-0} # require semver versions
@@ -37,13 +38,25 @@
then
NEW_VERSION=$(head -n1 "VERSION")
VERSIONFILE="VERSION"
+
+ # If this is a golang project, use funky v-prefixed versions
+ if [ -f "Gopkg.toml" ] || [ -f "go.mod" ]
+ then
+ echo "go-based project found, using v-prefixed version for git tags: v${NEW_VERSION}"
+ TAG_VERSION=v${NEW_VERSION}
+ else
+ TAG_VERSION=${NEW_VERSION}
+ fi
+
elif [ -f "package.json" ]
then
NEW_VERSION=$(python -c 'import json,sys;obj=json.load(sys.stdin); print obj["version"]' < package.json)
+ TAG_VERSION=$NEW_VERSION
VERSIONFILE="package.json"
elif [ -f "pom.xml" ]
then
NEW_VERSION=$(xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' pom.xml)
+ TAG_VERSION=$NEW_VERSION
VERSIONFILE="pom.xml"
else
echo "ERROR: No versioning file found!"
@@ -51,18 +64,6 @@
fi
}
-# check if the version is already a tag in git
-function is_git_tag_duplicated {
- for existing_tag in $(git tag)
- do
- if [ "$NEW_VERSION" = "$existing_tag" ]
- then
- echo "ERROR: Duplicate tag: $existing_tag"
- exit 2
- fi
- done
-}
-
# check if the version is a released version
function check_if_releaseversion {
if [[ "$NEW_VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]
@@ -80,6 +81,18 @@
fi
}
+# check if the version is already a tag in git
+function is_git_tag_duplicated {
+ for existing_tag in $(git tag)
+ do
+ if [ "$TAG_VERSION" = "$existing_tag" ]
+ then
+ echo "ERROR: Duplicate tag: $existing_tag"
+ exit 2
+ fi
+ done
+}
+
# check if Dockerfiles have a released version as their parent
function dockerfile_parentcheck {
while IFS= read -r -d '' dockerfile
diff --git a/jjb/shell/versiontag.sh b/jjb/shell/versiontag.sh
index a75087b..cc01f97 100755
--- a/jjb/shell/versiontag.sh
+++ b/jjb/shell/versiontag.sh
@@ -22,6 +22,7 @@
VERSIONFILE="" # file path to file containing version number
NEW_VERSION="" # version number found in $VERSIONFILE
+TAG_VERSION="" # version file that might have a leading v to work around go mod funkyness
SEMVER_STRICT=${SEMVER_STRICT:-0} # require semver versions
@@ -38,13 +39,25 @@
then
NEW_VERSION=$(head -n1 "VERSION")
VERSIONFILE="VERSION"
+
+ # If this is a golang project, use funky v-prefixed versions
+ if [ -f "Gopkg.toml" ] || [ -f "go.mod" ]
+ then
+ echo "go-based project found, using v-prefixed version for git tags: v${NEW_VERSION}"
+ TAG_VERSION=v${NEW_VERSION}
+ else
+ TAG_VERSION=${NEW_VERSION}
+ fi
+
elif [ -f "package.json" ]
then
NEW_VERSION=$(python -c 'import json,sys;obj=json.load(sys.stdin); print obj["version"]' < package.json)
+ TAG_VERSION=$NEW_VERSION
VERSIONFILE="package.json"
elif [ -f "pom.xml" ]
then
NEW_VERSION=$(xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' pom.xml)
+ TAG_VERSION=$NEW_VERSION
VERSIONFILE="pom.xml"
else
echo "ERROR: No versioning file found!"
@@ -73,7 +86,7 @@
function is_git_tag_duplicated {
for existing_tag in $(git tag)
do
- if [ "$NEW_VERSION" = "$existing_tag" ]
+ if [ "$TAG_VERSION" = "$existing_tag" ]
then
echo "ERROR: Duplicate tag: $existing_tag"
exit 2
@@ -134,18 +147,18 @@
# create a git tag
function create_git_tag {
- echo "Creating git tag: $NEW_VERSION"
+ echo "Creating git tag: $TAG_VERSION"
git checkout "$GERRIT_PATCHSET_REVISION"
git config --global user.email "do-not-reply@opencord.org"
git config --global user.name "Jenkins"
- git tag -a "$NEW_VERSION" -m "Tagged by CORD Jenkins version-tag job: $BUILD_NUMBER, for Gerrit patchset: $GERRIT_CHANGE_NUMBER"
+ git tag -a "$TAG_VERSION" -m "Tagged by CORD Jenkins version-tag job: $BUILD_NUMBER, for Gerrit patchset: $GERRIT_CHANGE_NUMBER"
echo "Tags including new tag:"
git tag -n
- git push origin "$NEW_VERSION"
+ git push origin "$TAG_VERSION"
}
echo "Checking git repo with remotes:"