1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

feat: add FORGEJO_* for each GITHUB_* in the environment & contexts (#171)

Blocking for

- https://code.forgejo.org/actions/setup-forgejo/pulls/461
- forgejo/end-to-end#758

Tested locally with both of them.

```
$ ./end-to-end.sh actions_teardown
$ ( cd ../runner ; make --always-make forgejo-runner ; cp forgejo-runner /tmp/forgejo-end-to-end/forgejo-runner )
$ ./end-to-end.sh actions_setup 12.0
$ ./end-to-end.sh actions_verify_example conext
```

Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/171
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
Earl Warren 2025-07-07 06:00:53 +00:00 committed by earl-warren
parent 1a5cda1a93
commit aaf05691c0
2 changed files with 44 additions and 36 deletions

View file

@ -1183,46 +1183,48 @@ func nestedMapLookup(m map[string]interface{}, ks ...string) (rval interface{})
} }
func (rc *RunContext) withGithubEnv(ctx context.Context, github *model.GithubContext, env map[string]string) map[string]string { func (rc *RunContext) withGithubEnv(ctx context.Context, github *model.GithubContext, env map[string]string) map[string]string {
set := func(k, v string) {
for _, prefix := range []string{"FORGEJO", "GITHUB"} {
env[prefix+"_"+k] = v
}
}
env["CI"] = "true" env["CI"] = "true"
env["GITHUB_WORKFLOW"] = github.Workflow set("WORKFLOW", github.Workflow)
env["GITHUB_RUN_ID"] = github.RunID set("RUN_ID", github.RunID)
env["GITHUB_RUN_NUMBER"] = github.RunNumber set("RUN_NUMBER", github.RunNumber)
env["GITHUB_ACTION"] = github.Action set("ACTION", github.Action)
env["GITHUB_ACTION_PATH"] = github.ActionPath set("ACTION_PATH", github.ActionPath)
env["GITHUB_ACTION_REPOSITORY"] = github.ActionRepository set("ACTION_REPOSITORY", github.ActionRepository)
env["GITHUB_ACTION_REF"] = github.ActionRef set("ACTION_REF", github.ActionRef)
env["GITHUB_ACTIONS"] = "true" set("ACTIONS", "true")
env["GITHUB_ACTOR"] = github.Actor set("ACTOR", github.Actor)
env["GITHUB_REPOSITORY"] = github.Repository set("REPOSITORY", github.Repository)
env["GITHUB_EVENT_NAME"] = github.EventName set("EVENT_NAME", github.EventName)
env["GITHUB_EVENT_PATH"] = github.EventPath set("EVENT_PATH", github.EventPath)
env["GITHUB_WORKSPACE"] = github.Workspace set("WORKSPACE", github.Workspace)
env["GITHUB_SHA"] = github.Sha set("SHA", github.Sha)
env["GITHUB_REF"] = github.Ref set("REF", github.Ref)
env["GITHUB_REF_NAME"] = github.RefName set("REF_NAME", github.RefName)
env["GITHUB_REF_TYPE"] = github.RefType set("REF_TYPE", github.RefType)
env["GITHUB_TOKEN"] = github.Token set("TOKEN", github.Token)
env["FORGEJO_TOKEN"] = github.Token set("JOB", github.Job)
env["GITHUB_JOB"] = github.Job set("REPOSITORY_OWNER", github.RepositoryOwner)
env["GITHUB_REPOSITORY_OWNER"] = github.RepositoryOwner set("RETENTION_DAYS", github.RetentionDays)
env["GITHUB_RETENTION_DAYS"] = github.RetentionDays
env["RUNNER_PERFLOG"] = github.RunnerPerflog env["RUNNER_PERFLOG"] = github.RunnerPerflog
env["RUNNER_TRACKING_ID"] = github.RunnerTrackingID env["RUNNER_TRACKING_ID"] = github.RunnerTrackingID
env["GITHUB_BASE_REF"] = github.BaseRef set("BASE_REF", github.BaseRef)
env["GITHUB_HEAD_REF"] = github.HeadRef set("HEAD_REF", github.HeadRef)
env["GITHUB_SERVER_URL"] = github.ServerURL set("SERVER_URL", github.ServerURL)
env["GITHUB_API_URL"] = github.APIURL set("API_URL", github.APIURL)
env["GITHUB_GRAPHQL_URL"] = github.GraphQLURL
{ // Adapt to Gitea { // Adapt to Forgejo
instance := rc.Config.GitHubInstance instance := rc.Config.GitHubInstance
if !strings.HasPrefix(instance, "http://") && if !strings.HasPrefix(instance, "http://") &&
!strings.HasPrefix(instance, "https://") { !strings.HasPrefix(instance, "https://") {
instance = "https://" + instance instance = "https://" + instance
} }
env["GITHUB_SERVER_URL"] = instance set("SERVER_URL", instance)
env["GITHUB_API_URL"] = instance + "/api/v1" // the version of Gitea is v1 set("API_URL", instance+"/api/v1")
env["GITHUB_GRAPHQL_URL"] = "" // Gitea doesn't support graphql
} }
if rc.Config.ArtifactServerPath != "" { if rc.Config.ArtifactServerPath != "" {

View file

@ -107,20 +107,26 @@ func runStepExecutor(step step, stage stepStage, executor common.Executor) commo
// Prepare and clean Runner File Commands // Prepare and clean Runner File Commands
actPath := rc.JobContainer.GetActPath() actPath := rc.JobContainer.GetActPath()
set := func(k, v string) {
for _, prefix := range []string{"FORGEJO", "GITHUB"} {
(*step.getEnv())[prefix+"_"+k] = v
}
}
outputFileCommand := path.Join("workflow", "outputcmd.txt") outputFileCommand := path.Join("workflow", "outputcmd.txt")
(*step.getEnv())["GITHUB_OUTPUT"] = path.Join(actPath, outputFileCommand) set("OUTPUT", path.Join(actPath, outputFileCommand))
stateFileCommand := path.Join("workflow", "statecmd.txt") stateFileCommand := path.Join("workflow", "statecmd.txt")
(*step.getEnv())["GITHUB_STATE"] = path.Join(actPath, stateFileCommand) set("STATE", path.Join(actPath, stateFileCommand))
pathFileCommand := path.Join("workflow", "pathcmd.txt") pathFileCommand := path.Join("workflow", "pathcmd.txt")
(*step.getEnv())["GITHUB_PATH"] = path.Join(actPath, pathFileCommand) set("PATH", path.Join(actPath, pathFileCommand))
envFileCommand := path.Join("workflow", "envs.txt") envFileCommand := path.Join("workflow", "envs.txt")
(*step.getEnv())["GITHUB_ENV"] = path.Join(actPath, envFileCommand) set("ENV", path.Join(actPath, envFileCommand))
summaryFileCommand := path.Join("workflow", "SUMMARY.md") summaryFileCommand := path.Join("workflow", "SUMMARY.md")
(*step.getEnv())["GITHUB_STEP_SUMMARY"] = path.Join(actPath, summaryFileCommand) set("STEP_SUMMARY", path.Join(actPath, summaryFileCommand))
_ = rc.JobContainer.Copy(actPath, &container.FileEntry{ _ = rc.JobContainer.Copy(actPath, &container.FileEntry{
Name: outputFileCommand, Name: outputFileCommand,