From 3e6530c81318defa78574328c7cbe37ce36358ab Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 5 Mar 2018 19:34:23 +0000 Subject: [PATCH 1/7] Propose semver version script for #45 --- contrib/semver/version.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 contrib/semver/version.sh diff --git a/contrib/semver/version.sh b/contrib/semver/version.sh new file mode 100644 index 00000000..a2c9f82a --- /dev/null +++ b/contrib/semver/version.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +# Get the last tag +TAG=$(git describe --abbrev=0 --tags 2>/dev/null) + +# Get the number of commits from the last tag, or if not, from +# the first commit +COUNT=$( \ + git rev-list v$TAG..HEAD --count 2>/dev/null || \ + git rev-list HEAD --count 2>/dev/null \ +) + +# Check if it matches the vX.Y.Z format +grep "v[0-9]*\.[0-9]*\.[0-9]*" <<< $TAG &>/dev/null + +# If it doesn't, abort +if [ $? -ne 0 ]; then + printf 'v0.0.0-%d' "$COUNT" + exit -1 +fi + +# Trim the "v" off the front +TAG=$(echo $TAG | cut -c 2-) + +# Split out into major, minor and patch numbers +MAJOR=$(echo $TAG | cut -d "." -f 1) +MINOR=$(echo $TAG | cut -d "." -f 2) +PATCH=$(echo $TAG | cut -d "." -f 3) + +# Output in the desired format +printf 'v%d.%d.%d-%d' "$MAJOR" "$MINOR" "$PATCH" "$COUNT" From f4aa4f184803e760cef0da6bb237c5cf9179c697 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 5 Mar 2018 19:54:18 +0000 Subject: [PATCH 2/7] Match v* tags only --- contrib/semver/version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/semver/version.sh b/contrib/semver/version.sh index a2c9f82a..8dd3dd09 100644 --- a/contrib/semver/version.sh +++ b/contrib/semver/version.sh @@ -1,7 +1,7 @@ #!/bin/sh # Get the last tag -TAG=$(git describe --abbrev=0 --tags 2>/dev/null) +TAG=$(git describe --abbrev=0 --tags --match=v* 2>/dev/null) # Get the number of commits from the last tag, or if not, from # the first commit From a75ddff9f3d0cd1cb32c2bbe62d0b8841f549460 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 5 Mar 2018 20:06:38 +0000 Subject: [PATCH 3/7] Ignore non-version tags --- contrib/semver/version.sh | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/contrib/semver/version.sh b/contrib/semver/version.sh index 8dd3dd09..62acd62c 100644 --- a/contrib/semver/version.sh +++ b/contrib/semver/version.sh @@ -1,20 +1,15 @@ #!/bin/sh # Get the last tag -TAG=$(git describe --abbrev=0 --tags --match=v* 2>/dev/null) +TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" 2>/dev/null) -# Get the number of commits from the last tag, or if not, from -# the first commit -COUNT=$( \ - git rev-list v$TAG..HEAD --count 2>/dev/null || \ - git rev-list HEAD --count 2>/dev/null \ -) +# Get the number of commits from the last tag +COUNT=$(git rev-list $TAG..HEAD --count 2>/dev/null) -# Check if it matches the vX.Y.Z format -grep "v[0-9]*\.[0-9]*\.[0-9]*" <<< $TAG &>/dev/null +# If it fails then there's no last tag - go from the first commit +if [ $? != 0 ]; then + COUNT=$(git rev-list HEAD --count 2>/dev/null) -# If it doesn't, abort -if [ $? -ne 0 ]; then printf 'v0.0.0-%d' "$COUNT" exit -1 fi From 636655825847d6e35ea795f1954729a8f1036fea Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 5 Mar 2018 20:20:17 +0000 Subject: [PATCH 4/7] Use new semver versioning for CircleCI builds --- .circleci/config.yml | 33 ++++++++++++++++----------------- contrib/deb/generate.sh | 5 ++--- contrib/semver/name.sh | 19 +++++++++++++++++++ 3 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 contrib/semver/name.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 16fb4e4d..be772aed 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,48 +15,47 @@ jobs: name: Create artifact upload directory and set variables command: | mkdir /tmp/upload - echo 'export CIBUILD=$(cat VERSION).$(git rev-list HEAD --count | xargs printf "%04d")' >> $BASH_ENV - echo 'export CIBRANCH=$(git name-rev --name-only HEAD)' >> $BASH_ENV - echo '[ "$CIBRANCH" != "master" ] && export CIVERSION=$CIBRANCH-$CIBUILD || export CIVERSION=$CIBUILD' >> $BASH_ENV + echo 'export CINAME=$(sh contrib/semver/name.sh)' >> $BASH_ENV + echo 'export CIVERSION=$(sh contrib/semver/version.sh)' >> $BASH_ENV - run: name: Build for Linux (including Debian packages) command: | - PKGARCH=amd64 sh contrib/deb/generate.sh && mv yggdrasil /tmp/upload/yggdrasil-$CIVERSION-linux-amd64; - PKGARCH=i386 sh contrib/deb/generate.sh && mv yggdrasil /tmp/upload/yggdrasil-$CIVERSION-linux-i386; - PKGARCH=mipsel sh contrib/deb/generate.sh && mv yggdrasil /tmp/upload/yggdrasil-$CIVERSION-linux-mipsel; - PKGARCH=mips sh contrib/deb/generate.sh && mv yggdrasil /tmp/upload/yggdrasil-$CIVERSION-linux-mips; + PKGARCH=amd64 sh contrib/deb/generate.sh && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-linux-amd64; + PKGARCH=i386 sh contrib/deb/generate.sh && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-linux-i386; + PKGARCH=mipsel sh contrib/deb/generate.sh && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-linux-mipsel; + PKGARCH=mips sh contrib/deb/generate.sh && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-linux-mips; mv *.deb /tmp/upload/ - run: name: Build for macOS command: | - GOOS=darwin GOARCH=amd64 ./build && mv yggdrasil /tmp/upload/yggdrasil-$CIVERSION-darwin-amd64; - GOOS=darwin GOARCH=386 ./build && mv yggdrasil /tmp/upload/yggdrasil-$CIVERSION-darwin-i386; + GOOS=darwin GOARCH=amd64 ./build && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-darwin-amd64; + GOOS=darwin GOARCH=386 ./build && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-darwin-i386; - run: name: Build for OpenBSD command: | - GOOS=openbsd GOARCH=amd64 ./build && mv yggdrasil /tmp/upload/yggdrasil-$CIVERSION-openbsd-amd64; - GOOS=openbsd GOARCH=386 ./build && mv yggdrasil /tmp/upload/yggdrasil-$CIVERSION-openbsd-i386; + GOOS=openbsd GOARCH=amd64 ./build && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-openbsd-amd64; + GOOS=openbsd GOARCH=386 ./build && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-openbsd-i386; - run: name: Build for FreeBSD command: | - GOOS=freebsd GOARCH=amd64 ./build && mv yggdrasil /tmp/upload/yggdrasil-$CIVERSION-freebsd-amd64; - GOOS=freebsd GOARCH=386 ./build && mv yggdrasil /tmp/upload/yggdrasil-$CIVERSION-freebsd-i386; + GOOS=freebsd GOARCH=amd64 ./build && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-freebsd-amd64; + GOOS=freebsd GOARCH=386 ./build && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-freebsd-i386; - run: name: Build for NetBSD command: | - GOOS=netbsd GOARCH=amd64 ./build && mv yggdrasil /tmp/upload/yggdrasil-$CIVERSION-netbsd-amd64; - GOOS=netbsd GOARCH=386 ./build && mv yggdrasil /tmp/upload/yggdrasil-$CIVERSION-netbsd-i386; + GOOS=netbsd GOARCH=amd64 ./build && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-netbsd-amd64; + GOOS=netbsd GOARCH=386 ./build && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-netbsd-i386; - run: name: Build for Windows command: | - GOOS=windows GOARCH=amd64 ./build && mv yggdrasil.exe /tmp/upload/yggdrasil-$CIVERSION-windows-amd64.exe; - GOOS=windows GOARCH=386 ./build && mv yggdrasil.exe /tmp/upload/yggdrasil-$CIVERSION-windows-i386.exe; + GOOS=windows GOARCH=amd64 ./build && mv yggdrasil.exe /tmp/upload/$CINAME-$CIVERSION-windows-amd64.exe; + GOOS=windows GOARCH=386 ./build && mv yggdrasil.exe /tmp/upload/$CINAME-$CIVERSION-windows-i386.exe; - run: name: Build for EdgeRouter diff --git a/contrib/deb/generate.sh b/contrib/deb/generate.sh index 6e58e875..8f604d31 100644 --- a/contrib/deb/generate.sh +++ b/contrib/deb/generate.sh @@ -11,10 +11,9 @@ then fi PKGBRANCH=$(basename `git name-rev --name-only HEAD`) -if [ "$PKGBRANCH" = "master" ]; then PKGNAME=yggdrasil -else PKGNAME=yggdrasil-${PKGBRANCH}; fi +PKGNAME=$(sh contrib/semver/name.sh) +PKGVERSION=$(sh contrib/semver/version.sh | cut -c 2-) PKGARCH=${PKGARCH-amd64} -PKGVERSION=$(cat VERSION).$(git rev-list HEAD --count 2>/dev/null | xargs printf "%04d") PKGFILE=$PKGNAME-$PKGVERSION-$PKGARCH.deb if [ $PKGARCH = "amd64" ]; then GOARCH=amd64 GOOS=linux ./build diff --git a/contrib/semver/name.sh b/contrib/semver/name.sh new file mode 100644 index 00000000..ee2f8cd8 --- /dev/null +++ b/contrib/semver/name.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +# Get the branch name +BRANCH=$(git name-rev --name-only HEAD 2>/dev/null) + +# Check if the branch name check fails +if [ $? != 0 ]; then + printf "yggdrasil" + exit 0 +fi + +# Check if the branch name is not master +if [ "$BRANCH" = "master" ]; then + printf "yggdrasil" + exit 0 +fi + +# If it is something other than master, append it +printf "yggdrasil-%s" "$BRANCH" From d58c97155987020324037d50befa8994c99917d5 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 5 Mar 2018 20:26:55 +0000 Subject: [PATCH 5/7] Fix bugs in CircleCI naming --- .circleci/config.yml | 2 +- contrib/semver/name.sh | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index be772aed..0ec36733 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,7 +16,7 @@ jobs: command: | mkdir /tmp/upload echo 'export CINAME=$(sh contrib/semver/name.sh)' >> $BASH_ENV - echo 'export CIVERSION=$(sh contrib/semver/version.sh)' >> $BASH_ENV + echo 'export CIVERSION=$(sh contrib/semver/version.sh | cut -c 2-)' >> $BASH_ENV - run: name: Build for Linux (including Debian packages) diff --git a/contrib/semver/name.sh b/contrib/semver/name.sh index ee2f8cd8..82527596 100644 --- a/contrib/semver/name.sh +++ b/contrib/semver/name.sh @@ -3,12 +3,6 @@ # Get the branch name BRANCH=$(git name-rev --name-only HEAD 2>/dev/null) -# Check if the branch name check fails -if [ $? != 0 ]; then - printf "yggdrasil" - exit 0 -fi - # Check if the branch name is not master if [ "$BRANCH" = "master" ]; then printf "yggdrasil" From c57cf73219389ad135bfc9433611be6afaf042b4 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 5 Mar 2018 21:54:30 +0000 Subject: [PATCH 6/7] Try symbolic-ref to get branch name --- contrib/semver/name.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/semver/name.sh b/contrib/semver/name.sh index 82527596..eea8ee4b 100644 --- a/contrib/semver/name.sh +++ b/contrib/semver/name.sh @@ -1,7 +1,7 @@ #!/bin/sh # Get the branch name -BRANCH=$(git name-rev --name-only HEAD 2>/dev/null) +BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null) # Check if the branch name is not master if [ "$BRANCH" = "master" ]; then From b1380baa9f8b3bebe5e21905b75c1c2fd04c7476 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 5 Mar 2018 22:14:36 +0000 Subject: [PATCH 7/7] Update versioning to v1.2.3 where derived from the tag and 3 is commits since last tag --- contrib/semver/version.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/contrib/semver/version.sh b/contrib/semver/version.sh index 62acd62c..1839a67b 100644 --- a/contrib/semver/version.sh +++ b/contrib/semver/version.sh @@ -1,7 +1,7 @@ #!/bin/sh # Get the last tag -TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" 2>/dev/null) +TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*" 2>/dev/null) # Get the number of commits from the last tag COUNT=$(git rev-list $TAG..HEAD --count 2>/dev/null) @@ -10,17 +10,17 @@ COUNT=$(git rev-list $TAG..HEAD --count 2>/dev/null) if [ $? != 0 ]; then COUNT=$(git rev-list HEAD --count 2>/dev/null) - printf 'v0.0.0-%d' "$COUNT" + printf 'v0.0.%d' "$COUNT" exit -1 fi -# Trim the "v" off the front -TAG=$(echo $TAG | cut -c 2-) - # Split out into major, minor and patch numbers -MAJOR=$(echo $TAG | cut -d "." -f 1) -MINOR=$(echo $TAG | cut -d "." -f 2) -PATCH=$(echo $TAG | cut -d "." -f 3) +MAJOR=$(echo $TAG | cut -c 2- | cut -d "." -f 1) +MINOR=$(echo $TAG | cut -c 2- | cut -d "." -f 2) # Output in the desired format -printf 'v%d.%d.%d-%d' "$MAJOR" "$MINOR" "$PATCH" "$COUNT" +if [ $COUNT = 0 ]; then + printf 'v%d.%d' "$MAJOR" "$MINOR" +else + printf 'v%d.%d.%d' "$MAJOR" "$MINOR" "$COUNT" +fi