cli, server: use prerelease tag as channel for console assets cdn (#3975)

Co-authored-by: Shahidh K Muhammed <muhammedshahid.k@gmail.com>
This commit is contained in:
Aravind Shankar 2020-03-04 20:10:47 +05:30 committed by GitHub
parent 2c13ba5a28
commit 45bcb6b536
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 21 deletions

View File

@ -2,7 +2,7 @@ package version
import (
"fmt"
"strings"
"regexp"
)
var (
@ -44,14 +44,13 @@ func (v *Version) GetConsoleAssetsVersion() (av string) {
// check for release channels
preRelease := v.ServerSemver.Prerelease()
channel := "stable"
if strings.HasPrefix(preRelease, "alpha") {
channel = "alpha"
}
if strings.HasPrefix(preRelease, "beta") {
channel = "beta"
}
if strings.HasPrefix(preRelease, "rc") {
channel = "rc"
if preRelease != "" {
// Get the correct channel from the prerelease tag
var re = regexp.MustCompile(`^[a-z]+`)
tag := re.FindString(preRelease)
if tag != "" {
channel = tag
}
}
return fmt.Sprintf("channel/%s/v%d.%d", channel, v.ServerSemver.Major(), v.ServerSemver.Minor())
}

View File

@ -39,6 +39,7 @@ func TestGetConsoleAssetsVersion(t *testing.T) {
{"tagged alpha release without .", "v1.0.0-alpha45", "channel/alpha/v1.0"},
{"tagged beta release with .", "v1.0.0-beta.01", "channel/beta/v1.0"},
{"tagged rc release with .", "v2.3.1-rc.11", "channel/rc/v2.3"},
{"tagged rj release with .", "v1.2.0-rj.1", "channel/rj/v1.2"},
}
for _, tc := range tt {

View File

@ -5,7 +5,8 @@ IFS=$'\n\t'
ROOT="${BASH_SOURCE[0]%/*}"
SEMVER_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$"
SEMVER_REGEX="v?([0-9]+)(\.[0-9]+)?(\.[0-9]+)?(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?"
CHANNEL_REGEX="^[a-z]+"
LATEST_TAG=$(git describe --tags --abbrev=0)
VERSION=""
@ -14,12 +15,11 @@ channel="stable"
if [[ "$LATEST_TAG" =~ $SEMVER_REGEX ]]; then
major=${BASH_REMATCH[1]}
minor=${BASH_REMATCH[2]}
release=${BASH_REMATCH[4]}
if [[ $release == -alpha* ]]; then channel="alpha"; fi
if [[ $release == -beta* ]]; then channel="beta"; fi
if [[ $release == -rc* ]]; then channel="rc"; fi
VERSION="channel/$channel/v$major.$minor"
release=${BASH_REMATCH[5]}
if [[ "$release" =~ $CHANNEL_REGEX ]]; then
channel="${BASH_REMATCH[0]}"
fi
VERSION="channel/$channel/v$major$minor"
fi
if [ -z "$VERSION" ]; then VERSION="versioned/$($ROOT/get-version.sh)"; fi

View File

@ -10,4 +10,4 @@ test -n "$VERSION" || VERSION="${GIT_BRANCH}-${GIT_SHA}${GIT_DIRTY}"
VERSION="$(echo $VERSION | tr -cd '[[:alnum:]]._-')"
echo "$VERSION"
echo "$VERSION"

View File

@ -17,6 +17,7 @@ import qualified Data.SemVer as V
import qualified Data.Text as T
import qualified Language.Haskell.TH.Syntax as TH
import Text.Regex.TDFA ((=~~))
import Control.Lens ((^.), (^?))
import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.Text.Conversions (FromText (..), ToText (..))
@ -86,10 +87,12 @@ consoleAssetsVersion = case currentVersion of
(mr:_) -> case getTextFromId mr of
Nothing -> Nothing
Just r -> if
| "alpha" `T.isPrefixOf` r -> Just "alpha"
| "beta" `T.isPrefixOf` r -> Just "beta"
| "rc" `T.isPrefixOf` r -> Just "rc"
| otherwise -> Nothing
| T.null r -> Nothing
| otherwise -> T.pack <$> (getChannelFromPreRelease $ T.unpack r)
getChannelFromPreRelease :: String -> Maybe String
getChannelFromPreRelease sv = sv =~~ ("^([a-z]+)"::String)
getTextFromId :: V.Identifier -> Maybe Text
getTextFromId i = Just i ^? (toTextualM . V._Textual)