2687ace
package runner
import (
"context"
"encoding/json"
"os"
"path"
"strings"
"github.com/nektos/act/pkg/common"
"github.com/nektos/act/pkg/container"
"github.com/nektos/act/pkg/exprparser"
"github.com/nektos/act/pkg/model"
)
type GitDataEvent struct {
Type string `json:"type"`
StepID string `json:"step_id,omitempty"`
Stage string `json:"stage,omitempty"`
Name string `json:"name,omitempty"`
Outcome string `json:"outcome,omitempty"`
Conclusion string `json:"conclusion,omitempty"`
Outputs map[string]string `json:"outputs,omitempty"`
Text string `json:"text,omitempty"`
Properties map[string]string `json:"properties,omitempty"`
}
func (rc *RunContext) gitDataEmit(event GitDataEvent) {
if rc.Config.GitDataObserver == nil {
return
}
for parent := rc.Parent; parent != nil; parent = parent.Parent {
event.StepID = parent.CurrentStep + "/" + event.StepID
}
rc.Config.GitDataObserver(event)
}
func (rc *RunContext) GitDataEvaluate(ctx context.Context, expression string, check exprparser.DefaultStatusCheck) (interface{}, error) {
return rc.NewExpressionEvaluator(ctx).evaluate(ctx, expression, check)
}
func (rc *RunContext) gitDataContext(ghc *model.GithubContext) bool {
if rc.Config.GitDataGithub == nil {
return false
}
data, err := json.Marshal(rc.Config.GitDataGithub)
if err != nil || json.Unmarshal(data, ghc) != nil {
return false
}
ghc.Job = rc.Run.JobID
ghc.Action = rc.CurrentStep
ghc.ActionPath = rc.ActionPath
ghc.Token = rc.Config.Token
if rc.EventJSON != "" {
_ = json.Unmarshal([]byte(rc.EventJSON), &ghc.Event)
}
if rc.JobContainer != nil {
ghc.Workspace = rc.JobContainer.ToContainerPath(rc.Config.Workdir)
ghc.EventPath = rc.JobContainer.GetActPath() + "/workflow/event.json"
}
ghc.SetRefTypeAndName()
return true
}
func (rc *RunContext) GetNodeToolForAction(ctx context.Context, using string) string {
if node := rc.Config.GitDataNodeRuntimes[strings.ToLower(using)]; node != "" {
if rc.IsHostEnv(ctx) {
return node
}
destination := path.Join(rc.JobContainer.GetActPath(), "node", strings.ToLower(using), "bin/node")
if rc.gitDataNodes == nil {
rc.gitDataNodes = map[string]string{}
}
if cached := rc.gitDataNodes[using]; cached != "" {
return cached
}
data, err := os.ReadFile(node)
if err != nil {
common.Logger(ctx).Errorf("Node runtime %s: %v", using, err)
return destination
}
if err := rc.JobContainer.Copy(rc.JobContainer.GetActPath(), &container.FileEntry{Name: path.Join("node", strings.ToLower(using), "bin/node"), Mode: 0755, Body: string(data)})(ctx); err != nil {
common.Logger(ctx).Errorf("copying Node runtime %s: %v", using, err)
return destination
}
rc.gitDataNodes[using] = destination
return destination
}
return rc.GetNodeToolFullPath(ctx)
}
func (rc *RunContext) gitDataArtifactEnvironment(step *model.Step, env map[string]string) {
if rc.Config.GitDataRuntimeURL == "" {
return
}
if strings.HasPrefix(step.Uses, "actions/upload-artifact@") || strings.HasPrefix(step.Uses, "actions/download-artifact@") {
env["GITHUB_SERVER_URL"] = "https://github.com"
}
}