internal/build: add support for Github Actions CI environment (#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.
This commit is contained in:
Felix Lange 2025-05-23 17:48:15 +02:00 committed by GitHub
parent b97198379b
commit f14813fea9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -92,6 +92,33 @@ func Env() Environment {
IsPullRequest: os.Getenv("APPVEYOR_PULL_REQUEST_NUMBER") != "",
IsCronJob: os.Getenv("APPVEYOR_SCHEDULED_BUILD") == "True",
}
case os.Getenv("CI") == "true" && os.Getenv("GITHUB_ACTIONS") == "true":
commit := os.Getenv("GITHUB_SHA")
reftype := os.Getenv("GITHUB_REF_TYPE")
isPR := os.Getenv("GITHUB_HEAD_REF") != ""
tag := ""
branch := ""
switch {
case isPR:
branch = os.Getenv("GITHUB_BASE_REF")
case reftype == "branch":
branch = os.Getenv("GITHUB_REF_NAME")
case reftype == "tag":
tag = os.Getenv("GITHUB_REF_NAME")
}
return Environment{
CI: true,
Name: "github-actions",
Repo: os.Getenv("GITHUB_REPOSITORY"),
Commit: commit,
Date: getDate(commit),
Branch: branch,
Tag: tag,
IsPullRequest: isPR,
Buildnum: os.Getenv("GITHUB_RUN_ID"),
IsCronJob: os.Getenv("GITHUB_EVENT_NAME") == "schedule",
}
default:
return LocalEnv()
}