github.com/jfrerich/mattermost-server@v5.8.0-rc2+incompatible/model/version.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package model
     5  
     6  import (
     7  	"fmt"
     8  	"strconv"
     9  	"strings"
    10  )
    11  
    12  // This is a list of all the current versions including any patches.
    13  // It should be maintained in chronological order with most current
    14  // release at the front of the list.
    15  var versions = []string{
    16  	"5.8.0",
    17  	"5.7.0",
    18  	"5.6.0",
    19  	"5.5.0",
    20  	"5.4.0",
    21  	"5.3.0",
    22  	"5.2.0",
    23  	"5.1.0",
    24  	"5.0.0",
    25  	"4.10.0",
    26  	"4.9.0",
    27  	"4.8.1",
    28  	"4.8.0",
    29  	"4.7.2",
    30  	"4.7.1",
    31  	"4.7.0",
    32  	"4.6.0",
    33  	"4.5.0",
    34  	"4.4.0",
    35  	"4.3.0",
    36  	"4.2.0",
    37  	"4.1.0",
    38  	"4.0.0",
    39  	"3.10.0",
    40  	"3.9.0",
    41  	"3.8.0",
    42  	"3.7.0",
    43  	"3.6.0",
    44  	"3.5.0",
    45  	"3.4.0",
    46  	"3.3.0",
    47  	"3.2.0",
    48  	"3.1.0",
    49  	"3.0.0",
    50  	"2.2.0",
    51  	"2.1.0",
    52  	"2.0.0",
    53  	"1.4.0",
    54  	"1.3.0",
    55  	"1.2.1",
    56  	"1.2.0",
    57  	"1.1.0",
    58  	"1.0.0",
    59  	"0.7.1",
    60  	"0.7.0",
    61  	"0.6.0",
    62  	"0.5.0",
    63  }
    64  
    65  var CurrentVersion string = versions[0]
    66  var BuildNumber string
    67  var BuildDate string
    68  var BuildHash string
    69  var BuildHashEnterprise string
    70  var BuildEnterpriseReady string
    71  var versionsWithoutHotFixes []string
    72  
    73  func init() {
    74  	versionsWithoutHotFixes = make([]string, 0, len(versions))
    75  	seen := make(map[string]string)
    76  
    77  	for _, version := range versions {
    78  		maj, min, _ := SplitVersion(version)
    79  		verStr := fmt.Sprintf("%v.%v.0", maj, min)
    80  
    81  		if seen[verStr] == "" {
    82  			versionsWithoutHotFixes = append(versionsWithoutHotFixes, verStr)
    83  			seen[verStr] = verStr
    84  		}
    85  	}
    86  }
    87  
    88  func SplitVersion(version string) (int64, int64, int64) {
    89  	parts := strings.Split(version, ".")
    90  
    91  	major := int64(0)
    92  	minor := int64(0)
    93  	patch := int64(0)
    94  
    95  	if len(parts) > 0 {
    96  		major, _ = strconv.ParseInt(parts[0], 10, 64)
    97  	}
    98  
    99  	if len(parts) > 1 {
   100  		minor, _ = strconv.ParseInt(parts[1], 10, 64)
   101  	}
   102  
   103  	if len(parts) > 2 {
   104  		patch, _ = strconv.ParseInt(parts[2], 10, 64)
   105  	}
   106  
   107  	return major, minor, patch
   108  }
   109  
   110  func GetPreviousVersion(version string) string {
   111  	verMajor, verMinor, _ := SplitVersion(version)
   112  	verStr := fmt.Sprintf("%v.%v.0", verMajor, verMinor)
   113  
   114  	for index, v := range versionsWithoutHotFixes {
   115  		if v == verStr && len(versionsWithoutHotFixes) > index+1 {
   116  			return versionsWithoutHotFixes[index+1]
   117  		}
   118  	}
   119  
   120  	return ""
   121  }
   122  
   123  func IsCurrentVersion(versionToCheck string) bool {
   124  	currentMajor, currentMinor, _ := SplitVersion(CurrentVersion)
   125  	toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck)
   126  
   127  	if toCheckMajor == currentMajor && toCheckMinor == currentMinor {
   128  		return true
   129  	} else {
   130  		return false
   131  	}
   132  }
   133  
   134  func IsPreviousVersionsSupported(versionToCheck string) bool {
   135  	toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck)
   136  	versionToCheckStr := fmt.Sprintf("%v.%v.0", toCheckMajor, toCheckMinor)
   137  
   138  	// Current Supported
   139  	if versionsWithoutHotFixes[0] == versionToCheckStr {
   140  		return true
   141  	}
   142  
   143  	// Current - 1 Supported
   144  	if versionsWithoutHotFixes[1] == versionToCheckStr {
   145  		return true
   146  	}
   147  
   148  	// Current - 2 Supported
   149  	if versionsWithoutHotFixes[2] == versionToCheckStr {
   150  		return true
   151  	}
   152  
   153  	// Current - 3 Supported
   154  	if versionsWithoutHotFixes[3] == versionToCheckStr {
   155  		return true
   156  	}
   157  
   158  	return false
   159  }