Skip to content

Commit f14813f

Browse files
authored
internal/build: add support for Github Actions CI environment (ethereum#31891)
This adds support for the Github actions environment in the build tool. Information from environment variables, like the build number and branch/tag name, is used to make decisions about uploads and package filenames.
1 parent b971983 commit f14813f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

internal/build/env.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,33 @@ func Env() Environment {
9292
IsPullRequest: os.Getenv("APPVEYOR_PULL_REQUEST_NUMBER") != "",
9393
IsCronJob: os.Getenv("APPVEYOR_SCHEDULED_BUILD") == "True",
9494
}
95+
case os.Getenv("CI") == "true" && os.Getenv("GITHUB_ACTIONS") == "true":
96+
commit := os.Getenv("GITHUB_SHA")
97+
reftype := os.Getenv("GITHUB_REF_TYPE")
98+
isPR := os.Getenv("GITHUB_HEAD_REF") != ""
99+
tag := ""
100+
branch := ""
101+
switch {
102+
case isPR:
103+
branch = os.Getenv("GITHUB_BASE_REF")
104+
case reftype == "branch":
105+
branch = os.Getenv("GITHUB_REF_NAME")
106+
case reftype == "tag":
107+
tag = os.Getenv("GITHUB_REF_NAME")
108+
}
109+
return Environment{
110+
CI: true,
111+
Name: "github-actions",
112+
Repo: os.Getenv("GITHUB_REPOSITORY"),
113+
Commit: commit,
114+
Date: getDate(commit),
115+
Branch: branch,
116+
Tag: tag,
117+
IsPullRequest: isPR,
118+
Buildnum: os.Getenv("GITHUB_RUN_ID"),
119+
IsCronJob: os.Getenv("GITHUB_EVENT_NAME") == "schedule",
120+
}
121+
95122
default:
96123
return LocalEnv()
97124
}

0 commit comments

Comments
 (0)