go-ethereum/params/version.libevm.go
Arran Schlosberg 08490a9b76
test: branch properties of main and release/* (#145)
## Why this should be merged

Safer release process by enforcing invariants of `release/*` branches as
automated in #137 to fulfil #25.

## How this works

New test for `go_tooling` CI job.

If the PR target branch is `main` then only the `params.ReleaseType` is
checked. If the target is neither `main` nor a release branch then the
test is skipped. The checks performed on `release/*` branches are
described in the test.

## How this was tested

Locally against a dummy release branch with deliberate problems created
by (a) including this PR's changes in the final commit and (b) not
updating the libevm version.

```
$ go test -v ./... --target_branch="release/v1.13.14-0.1.0.rc.3"
=== RUN   TestCherryPicksFormat
--- PASS: TestCherryPicksFormat (0.39s)
=== RUN   TestBranchProperties
=== RUN   TestBranchProperties/branch_name
    release_test.go:172: 
                Error Trace:    .../ava-labs/libevm/libevm/tooling/release/release_test.go:172
                Error:          Not equal: 
                                expected: "release/v1.13.14-0.1.0.beta"
                                actual  : "release/v1.13.14-0.1.0.rc.3"
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1 +1 @@
                                -release/v1.13.14-0.1.0.beta
                                +release/v1.13.14-0.1.0.rc.3
                Test:           TestBranchProperties/branch_name
    release_test.go:175: On release branch; params.LibEVMReleaseType = "beta", which is unsuitable for release branches
=== RUN   TestBranchProperties/commit_history
    release_test.go:192: Forked from "main" at commit 4c6e50e7d1 (chore: module-renaming workflow inverts between `libevm` and `geth` (#152))
    release_test.go:314: ### History since fork from default branch (8 commits):
    release_test.go:316: internal/build, rpc: add missing HTTP response body Close() calls (#29223) by Shiming Zhang <wzshiming@hotmail.com>
    release_test.go:316: core/state: fix bug in statedb.Copy and remove unnecessary preallocation (#29563) by Aaron Chen <aaronchen.lisp@gmail.com>
    release_test.go:316: params: print time value instead of pointer in ConfigCompatError (#29514) by Nathan <Nathan.l@nodereal.io>
    release_test.go:316: eth/gasprice: add query limit for FeeHistory to defend DDOS attack (#29644) by Nathan <Nathan.l@nodereal.io>
    release_test.go:316: core/state/snapshot: add a missing lock (#30001) by maskpp <maskpp266@gmail.com>
    release_test.go:316: crypto: add IsOnCurve check (#31100) by Felix Lange <fjl@twurst.com>
    release_test.go:316: internal/ethapi: fix panic in debug methods (#31157) by Sina M <1591639+s1na@users.noreply.github.com>
    release_test.go:316: x by Arran Schlosberg <me@arranschlosberg.com>
=== RUN   TestBranchProperties/commit_history/cherry_picked_commits
    release_test.go:314: ### Expected cherry-picks (7 commits):
    release_test.go:316: internal/build, rpc: add missing HTTP response body Close() calls (#29223) by Shiming Zhang <wzshiming@hotmail.com>
    release_test.go:316: core/state: fix bug in statedb.Copy and remove unnecessary preallocation (#29563) by Aaron Chen <aaronchen.lisp@gmail.com>
    release_test.go:316: params: print time value instead of pointer in ConfigCompatError (#29514) by Nathan <Nathan.l@nodereal.io>
    release_test.go:316: eth/gasprice: add query limit for FeeHistory to defend DDOS attack (#29644) by Nathan <Nathan.l@nodereal.io>
    release_test.go:316: core/state/snapshot: add a missing lock (#30001) by maskpp <maskpp266@gmail.com>
    release_test.go:316: crypto: add IsOnCurve check (#31100) by Felix Lange <fjl@twurst.com>
    release_test.go:316: internal/ethapi: fix panic in debug methods (#31157) by Sina M <1591639+s1na@users.noreply.github.com>
=== RUN   TestBranchProperties/commit_history/final_commit
    release_test.go:365: Modified disallowed file "go.yml"
    release_test.go:365: Modified disallowed file "go.mod"
    release_test.go:365: Modified disallowed file "go.sum"
    release_test.go:365: Modified disallowed file "release_test.go"
--- FAIL: TestBranchProperties (2.07s)
    --- FAIL: TestBranchProperties/branch_name (0.00s)
    --- FAIL: TestBranchProperties/commit_history (2.07s)
        --- PASS: TestBranchProperties/commit_history/cherry_picked_commits (1.81s)
        --- FAIL: TestBranchProperties/commit_history/final_commit (0.01s)
FAIL
FAIL    github.com/ava-labs/libevm/libevm/tooling/release       2.712s
FAIL
```
2025-03-17 16:55:39 +00:00

102 lines
3.5 KiB
Go

// Copyright 2024 the libevm authors.
//
// The libevm additions to go-ethereum are free software: you can redistribute
// them and/or modify them under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// The libevm additions are distributed in the hope that they will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
// General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see
// <http://www.gnu.org/licenses/>.
package params
import "fmt"
const (
LibEVMVersionMajor = 0
LibEVMVersionMinor = 1
LibEVMVersionPatch = 0
LibEVMReleaseType ReleaseType = BetaRelease
libEVMReleaseCandidate uint = 3 // ignored unless [LibEVMReleaseType] == [ReleaseCandidate]
)
// LibEVMVersion holds the textual version string of `libevm` modifications.
//
// Although compliant with [semver v2], it follows additional rules:
//
// 1. Major, minor, and patch MUST be the respective `geth` values;
// 2. The first three pre-release identifiers MUST be a semver-compliant
// triplet denoting the `libevm` "version";
// 3. On the `main` (development) branch, the final identifier MUST be "alpha"
// or "beta";
// 3. If a production version, the final identifier MUST be "release"; and
// 4. If a release candidate, the final two identifiers MUST be "rc" and an
// incrementing numeric value.
//
// The benefits of this pattern are that (a) it captures all relevant
// information; and (b) it follows an intuitive ordering under semver rules.
// Precedence is determined first by the `geth` version then the `libevm`
// version, with release candidates being lower than actual releases.
//
// The primary drawbacks is that it requires an explicit "release" identifier
// because of the use of pre-release identifiers to capture the `libevm`
// triplet.
//
// [semver v2]: https://semver.org/
var LibEVMVersion = func() string {
v := libEVMSemver{
geth: semverTriplet{VersionMajor, VersionMinor, VersionPatch},
libEVM: semverTriplet{LibEVMVersionMajor, LibEVMVersionMinor, LibEVMVersionPatch},
typ: LibEVMReleaseType,
rc: libEVMReleaseCandidate,
}
return v.String()
}()
type semverTriplet struct {
major, minor, patch uint
}
func (t semverTriplet) String() string {
return fmt.Sprintf("%d.%d.%d", t.major, t.minor, t.patch)
}
// A ReleaseType is a suffix for [LibEVMVersion].
type ReleaseType string
const (
// BetaRelease MUST be used on `main` branch.
BetaRelease = ReleaseType("beta")
// Reserved for `release/*` branches.
ReleaseCandidate = ReleaseType("rc")
ProductionRelease = ReleaseType("release")
)
// ForReleaseBranch returns true i.f.f. `t` is suitable for use on a release
// branch. The sets of [ReleaseType] values suitable for release vs default
// branches is disjoint so the negation of the return value is equivalent to
// "ForDefaultBranch".
func (t ReleaseType) ForReleaseBranch() bool {
return t == ReleaseCandidate || t == ProductionRelease
}
type libEVMSemver struct {
geth, libEVM semverTriplet
typ ReleaseType
rc uint
}
func (v libEVMSemver) String() string {
suffix := v.typ
if suffix == ReleaseCandidate {
suffix = ReleaseType(fmt.Sprintf("%s.%d", suffix, v.rc))
}
return fmt.Sprintf("%s-%s.%s", v.geth, v.libEVM, suffix)
}