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