-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
391 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package context | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/aweris/gale/internal/fs" | ||
) | ||
|
||
// GetMetadataPath returns the path of the metadata path. If the path does not exist, it creates it. This path assumes | ||
// zenith module set a cache for metadata, otherwise it will be empty every time it runs. | ||
func (c *Context) GetMetadataPath() (string, error) { | ||
return EnsureDir(c.GhxConfig.HomeDir, "metadata") | ||
} | ||
|
||
// GetActionsPath returns the path of the custom action repositories clones and stores. If the path does not exist, it | ||
// creates it. | ||
func (c *Context) GetActionsPath() (string, error) { | ||
return EnsureDir(c.GhxConfig.HomeDir, "actions") | ||
} | ||
|
||
// GetSecretsPath returns the path of the secrets.json file containing the secrets. If the path does not exist, it | ||
// creates it. | ||
func (c *Context) GetSecretsPath() (string, error) { | ||
file := filepath.Join(c.GhxConfig.HomeDir, "secrets", "secrets.json") | ||
|
||
// ensure file and directory exists | ||
if err := fs.EnsureFile(file); err != nil { | ||
return "", err | ||
} | ||
|
||
// if file content is empty, write empty json object to avoid json unmarshal error | ||
stat, err := os.Stat(file) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if stat.Size() == 0 { | ||
fs.WriteJSONFile(file, map[string]string{}) | ||
} | ||
|
||
return file, nil | ||
} | ||
|
||
// GetWorkflowRunPath returns the path of the current workflow run path. If the path does not exist, it creates it. If | ||
// the workflow run is not set, it returns an error. | ||
func (c *Context) GetWorkflowRunPath() (string, error) { | ||
if c.Execution.WorkflowRun == nil { | ||
return "", errors.New("no workflow run is set") | ||
} | ||
|
||
return EnsureDir(c.GhxConfig.HomeDir, "runs", c.Execution.WorkflowRun.RunID) | ||
} | ||
|
||
// GetJobRunPath returns the path of the current job run path. If the path does not exist, it creates it. If the job run | ||
// is not set, it returns an error. | ||
func (c *Context) GetJobRunPath() (string, error) { | ||
if c.Execution.JobRun == nil { | ||
return "", errors.New("no job is set") | ||
} | ||
|
||
return EnsureDir(c.GhxConfig.HomeDir, "runs", c.Execution.WorkflowRun.RunID, "jobs", c.Execution.JobRun.RunID) | ||
} | ||
|
||
// GetStepRunPath returns the path of the current step run path. If the path does not exist, it creates it. If the step | ||
// run is not set, it returns an error. | ||
func (c *Context) GetStepRunPath() (string, error) { | ||
if c.Execution.StepRun == nil { | ||
return "", errors.New("no step is set") | ||
} | ||
|
||
return EnsureDir(c.GhxConfig.HomeDir, "runs", c.Execution.WorkflowRun.RunID, "jobs", c.Execution.JobRun.RunID, "steps", c.Execution.StepRun.Step.ID) | ||
} | ||
|
||
// EnsureDir return the joined path and ensures that the directory exists. and returns the joined path. | ||
func EnsureDir(path ...string) (string, error) { | ||
joined := filepath.Join(path...) | ||
|
||
if err := fs.EnsureDir(joined); err != nil { | ||
return "", err | ||
} | ||
|
||
return joined, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package context | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/aweris/gale/ghx/core" | ||
) | ||
|
||
// RunResult is the result of the task execution | ||
type RunResult struct { | ||
Ran bool `json:"ran"` // Ran indicates if the execution ran | ||
Conclusion core.Conclusion `json:"conclusion"` // Conclusion of the execution | ||
Duration time.Duration `json:"duration"` // Duration of the execution | ||
} | ||
|
||
type WorkflowRunReport struct { | ||
Ran bool `json:"ran"` // Ran indicates if the execution ran | ||
Duration string `json:"duration"` // Duration of the execution | ||
Name string `json:"name"` // Name is the name of the workflow | ||
Path string `json:"path"` // Path is the path of the workflow | ||
RunID string `json:"run_id"` // RunID is the ID of the run | ||
RunNumber string `json:"run_number"` // RunNumber is the number of the run | ||
RunAttempt string `json:"run_attempt"` // RunAttempt is the attempt number of the run | ||
RetentionDays string `json:"retention_days"` // RetentionDays is the number of days to keep the run logs | ||
Conclusion core.Conclusion `json:"conclusion"` // Conclusion is the result of a completed workflow run after continue-on-error is applied | ||
Jobs map[string]core.Conclusion `json:"jobs"` // Jobs is map of the job run id to its result | ||
} | ||
|
||
// NewWorkflowRunReport creates a new workflow run report from the given workflow run. | ||
func NewWorkflowRunReport(result *RunResult, wr *core.WorkflowRun) *WorkflowRunReport { | ||
report := &WorkflowRunReport{ | ||
Ran: result.Ran, | ||
Duration: result.Duration.String(), | ||
Conclusion: result.Conclusion, | ||
Name: wr.Workflow.Name, | ||
Path: wr.Workflow.Path, | ||
RunID: wr.RunID, | ||
RunNumber: wr.RunNumber, | ||
RunAttempt: wr.RunAttempt, | ||
RetentionDays: wr.RetentionDays, | ||
Jobs: make(map[string]core.Conclusion), | ||
} | ||
|
||
for id, job := range wr.Jobs { | ||
report.Jobs[id] = job.Conclusion | ||
} | ||
|
||
return report | ||
} | ||
|
||
type JobRunReport struct { | ||
Ran bool `json:"ran"` // Ran indicates if the execution ran | ||
Duration string `json:"duration"` // Duration of the execution | ||
Name string `json:"name"` // Name is the name of the job | ||
RunID string `json:"run_id"` // RunID is the ID of the run | ||
Conclusion core.Conclusion `json:"conclusion"` // Conclusion is the result of a completed job after continue-on-error is applied | ||
Outcome core.Conclusion `json:"outcome"` // Outcome is the result of a completed job before continue-on-error is applied | ||
Outputs map[string]string `json:"outputs,omitempty"` // Outputs is the outputs generated by the job | ||
Matrix core.MatrixCombination `json:"matrix,omitempty"` // Matrix is the matrix parameters used to run the job | ||
Steps []StepRunSummary `json:"steps"` // Steps is the list of steps in the job | ||
} | ||
|
||
type StepRunSummary struct { | ||
ID string `json:"id"` // ID is the unique identifier of the step. | ||
Name string `json:"name,omitempty"` // Name is the name of the step | ||
Stage core.StepStage `json:"stage"` // Stage is the stage of the step during the execution of the job. Possible values are: setup, pre, main, post, complete. | ||
Conclusion core.Conclusion `json:"conclusion"` // Conclusion is the result of a completed job after continue-on-error is applied | ||
} | ||
|
||
// NewJobRunReport creates a new job run report from the given job run. | ||
func NewJobRunReport(result *RunResult, jr *core.JobRun) *JobRunReport { | ||
report := &JobRunReport{ | ||
Ran: result.Ran, | ||
Duration: result.Duration.String(), | ||
Conclusion: result.Conclusion, | ||
Name: jr.Job.Name, | ||
RunID: jr.RunID, | ||
Outcome: jr.Outcome, | ||
Outputs: jr.Outputs, | ||
Matrix: jr.Matrix, | ||
} | ||
|
||
for _, step := range jr.Steps { | ||
summary := StepRunSummary{ | ||
ID: step.Step.ID, | ||
Name: step.Step.Name, | ||
Stage: step.Stage, | ||
Conclusion: step.Conclusion, | ||
} | ||
|
||
report.Steps = append(report.Steps, summary) | ||
} | ||
|
||
return report | ||
} | ||
|
||
type StepRunReport struct { | ||
Ran bool `json:"ran"` // Ran indicates if the execution ran | ||
Duration string `json:"duration"` // Duration of the execution | ||
ID string `json:"id"` // ID is the unique identifier of the step. | ||
Name string `json:"name,omitempty"` // Name is the name of the step | ||
Conclusion core.Conclusion `json:"conclusion"` // Conclusion is the result of a completed job after continue-on-error is applied | ||
Outcome core.Conclusion `json:"outcome"` // Outcome is the result of a completed job before continue-on-error is applied | ||
Outputs map[string]string `json:"outputs,omitempty"` // Outputs is the outputs generated by the job | ||
State map[string]string `json:"state,omitempty"` // State is a map of step state variables. | ||
Env map[string]string `json:"env,omitempty"` // Env is the extra environment variables set by the step. | ||
Path []string `json:"path,omitempty"` // Path is extra PATH items set by the step. | ||
} | ||
|
||
// NewStepRunReport creates a new step run report from the given step run. | ||
func NewStepRunReport(result *RunResult, sr *core.StepRun) *StepRunReport { | ||
return &StepRunReport{ | ||
Ran: result.Ran, | ||
Duration: result.Duration.String(), | ||
ID: sr.Step.ID, | ||
Name: sr.Step.Name, | ||
Conclusion: result.Conclusion, | ||
Outcome: sr.Outcome, | ||
Outputs: sr.Outputs, | ||
State: sr.State, | ||
Env: sr.Environment, | ||
Path: sr.Path, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.