version.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2019 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Package version records versioning information about this module.
  5. package version
  6. import (
  7. "fmt"
  8. "strings"
  9. )
  10. // These constants determine the current version of this module.
  11. //
  12. //
  13. // For our release process, we enforce the following rules:
  14. // * Tagged releases use a tag that is identical to String.
  15. // * Tagged releases never reference a commit where the String
  16. // contains "devel".
  17. // * The set of all commits in this repository where String
  18. // does not contain "devel" must have a unique String.
  19. //
  20. //
  21. // Steps for tagging a new release:
  22. // 1. Create a new CL.
  23. //
  24. // 2. Update Minor, Patch, and/or PreRelease as necessary.
  25. // PreRelease must not contain the string "devel".
  26. //
  27. // 3. Since the last released minor version, have there been any changes to
  28. // generator that relies on new functionality in the runtime?
  29. // If yes, then increment RequiredGenerated.
  30. //
  31. // 4. Since the last released minor version, have there been any changes to
  32. // the runtime that removes support for old .pb.go source code?
  33. // If yes, then increment SupportMinimum.
  34. //
  35. // 5. Send out the CL for review and submit it.
  36. // Note that the next CL in step 8 must be submitted after this CL
  37. // without any other CLs in-between.
  38. //
  39. // 6. Tag a new version, where the tag is is the current String.
  40. //
  41. // 7. Write release notes for all notable changes
  42. // between this release and the last release.
  43. //
  44. // 8. Create a new CL.
  45. //
  46. // 9. Update PreRelease to include the string "devel".
  47. // For example: "" -> "devel" or "rc.1" -> "rc.1.devel"
  48. //
  49. // 10. Send out the CL for review and submit it.
  50. const (
  51. Major = 1
  52. Minor = 26
  53. Patch = 0
  54. PreRelease = "rc.1"
  55. )
  56. // String formats the version string for this module in semver format.
  57. //
  58. // Examples:
  59. // v1.20.1
  60. // v1.21.0-rc.1
  61. func String() string {
  62. v := fmt.Sprintf("v%d.%d.%d", Major, Minor, Patch)
  63. if PreRelease != "" {
  64. v += "-" + PreRelease
  65. // TODO: Add metadata about the commit or build hash.
  66. // See https://golang.org/issue/29814
  67. // See https://golang.org/issue/33533
  68. var metadata string
  69. if strings.Contains(PreRelease, "devel") && metadata != "" {
  70. v += "+" + metadata
  71. }
  72. }
  73. return v
  74. }