fix(build): internal env fetching of github actions

This commit is contained in:
Cal Bera 2025-06-25 00:42:51 -07:00
parent f92ae3095f
commit dc2ccd770e

View file

@ -98,6 +98,14 @@ func Env() Environment {
isPR := os.Getenv("GITHUB_HEAD_REF") != ""
tag := ""
branch := ""
if reftype == "" {
gref := os.Getenv("GITHUB_REF")
if strings.HasPrefix(gref, "refs/heads/") {
reftype = "branch"
} else if strings.HasPrefix(gref, "refs/tags/") {
reftype = "tag"
}
}
switch {
case isPR:
branch = os.Getenv("GITHUB_BASE_REF")
@ -106,6 +114,18 @@ func Env() Environment {
case reftype == "tag":
tag = os.Getenv("GITHUB_REF_NAME")
}
// Fallback: If tag or branch is still empty, derive from GITHUB_REF.
if tag == "" && branch == "" {
if gref := os.Getenv("GITHUB_REF"); gref != "" {
if strings.HasPrefix(gref, "refs/tags/") {
tag = strings.TrimPrefix(gref, "refs/tags/")
} else if strings.HasPrefix(gref, "refs/heads/") {
branch = strings.TrimPrefix(gref, "refs/heads/")
}
}
}
return Environment{
CI: true,
Name: "github-actions",
@ -126,7 +146,7 @@ func Env() Environment {
// LocalEnv returns build environment metadata gathered from git.
func LocalEnv() Environment {
env := applyEnvFlags(Environment{Name: "local", Repo: "ethereum/go-ethereum"})
env := applyEnvFlags(Environment{Name: "local", Repo: "berachain/bera-geth"})
head := readGitFile("HEAD")
if fields := strings.Fields(head); len(fields) == 2 {