Skip to content

Commit 81c1662

Browse files
committed
fix(actions): fix nil errors and double list size
1 parent a9a9a16 commit 81c1662

File tree

5 files changed

+106
-279
lines changed

5 files changed

+106
-279
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ require (
102102
github.com/prometheus/client_golang v1.20.5
103103
github.com/quasoft/websspi v1.1.2
104104
github.com/redis/go-redis/v9 v9.7.0
105+
github.com/rhysd/actionlint v1.7.3
105106
github.com/robfig/cron/v3 v3.0.1
106107
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
107108
github.com/sassoftware/go-rpmutils v0.4.0
@@ -271,7 +272,6 @@ require (
271272
github.com/prometheus/client_model v0.6.1 // indirect
272273
github.com/prometheus/common v0.60.1 // indirect
273274
github.com/prometheus/procfs v0.15.1 // indirect
274-
github.com/rhysd/actionlint v1.7.3 // indirect
275275
github.com/rivo/uniseg v0.4.7 // indirect
276276
github.com/rogpeppe/go-internal v1.13.1 // indirect
277277
github.com/rs/xid v1.6.0 // indirect

modules/actions/jobparser/interpeter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99
"gopkg.in/yaml.v3"
1010
)
1111

12-
// NewInterpeter returns an interpeter used in the server,
12+
// NewInterpreter returns an interpreter used in the server,
1313
// need github, needs, strategy, matrix, inputs context only,
1414
// see https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
15-
func NewInterpeter(
15+
func NewInterpreter(
1616
jobID string,
1717
job *model.Job,
1818
matrix map[string]any,
@@ -78,7 +78,7 @@ func NewInterpeter(
7878
return exprparser.NewInterpeter(ee, config)
7979
}
8080

81-
// JobResult is the minimum requirement of job results for Interpeter
81+
// JobResult is the minimum requirement of job results for Interpreter
8282
type JobResult struct {
8383
Needs []string
8484
Result string

modules/actions/jobparser/jobparser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func Parse(content []byte, options ...ParseOption) ([]*SingleWorkflow, error) {
5454
job.Name = id
5555
}
5656
job.Strategy.RawMatrix = encodeMatrix(matrix)
57-
evaluator := NewExpressionEvaluator(NewInterpeter(id, origin.GetJob(id), matrix, pc.gitContext, results, pc.vars))
57+
evaluator := NewExpressionEvaluator(NewInterpreter(id, origin.GetJob(id), matrix, pc.gitContext, results, pc.vars))
5858
job.Name = nameWithMatrix(job.Name, matrix, evaluator)
5959
runsOn := origin.GetJob(id).RunsOn()
6060
for i, v := range runsOn {

modules/actions/jobparser/model.go

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,19 @@ func (evt *Event) Acts() map[string][]string {
204204
// Helper to convert actionlint errors
205205
func acErrToError(acErrs []*actionlint.Error) []error {
206206
errs := make([]error, len(acErrs))
207-
for _, err := range acErrs {
208-
errs = append(errs, err)
207+
for i, err := range acErrs {
208+
errs[i] = err
209209
}
210210
return errs
211211
}
212212

213213
func acStringToString(strs []*actionlint.String) []string {
214+
if len(strs) == 0 {
215+
return nil
216+
}
214217
strings := make([]string, len(strs))
215-
for _, v := range strs {
216-
strings = append(strings, v.Value)
218+
for i, v := range strs {
219+
strings[i] = v.Value
217220
}
218221
return strings
219222
}
@@ -246,29 +249,39 @@ func GetEventsFromContent(content []byte) ([]*Event, error) {
246249
for _, acEvent := range wf.On {
247250
event := &Event{
248251
Name: acEvent.EventName(),
249-
acts: map[string][]string{},
250252
}
251253
switch e := acEvent.(type) {
252254
case *actionlint.ScheduledEvent:
253255
schedules := make([]map[string]string, len(e.Cron))
254-
for _, c := range e.Cron {
255-
schedules = append(schedules, map[string]string{"cron": c.Value})
256+
for i, c := range e.Cron {
257+
schedules[i] = map[string]string{"cron": c.Value}
256258
}
257259
event.schedules = schedules
258260
case *actionlint.WorkflowDispatchEvent:
259261
inputs := make([]WorkflowDispatchInput, len(e.Inputs))
262+
i := 0
260263
for keyword, v := range e.Inputs {
261-
inputs = append(inputs, WorkflowDispatchInput{
262-
Name: keyword,
263-
Required: v.Required.Value,
264-
Description: v.Description.Value,
265-
Default: v.Default.Value,
266-
Options: acStringToString(v.Options),
267-
Type: typeToString(v.Type),
268-
})
264+
wdi := WorkflowDispatchInput{
265+
Name: keyword,
266+
267+
Options: acStringToString(v.Options),
268+
Type: typeToString(v.Type),
269+
}
270+
if v.Required != nil {
271+
wdi.Required = v.Required.Value
272+
}
273+
if v.Description != nil {
274+
wdi.Description = v.Description.Value
275+
}
276+
if v.Default != nil {
277+
wdi.Default = v.Default.Value
278+
}
279+
inputs[i] = wdi
280+
i++
269281
}
270282
event.inputs = inputs
271283
case *actionlint.WebhookEvent:
284+
event.acts = map[string][]string{}
272285
if e.Branches != nil {
273286
event.acts[e.Branches.Name.Value] = acStringToString(e.Branches.Values)
274287
}
@@ -290,7 +303,6 @@ func GetEventsFromContent(content []byte) ([]*Event, error) {
290303
if e.Types != nil {
291304
event.acts["types"] = acStringToString(e.Types)
292305
}
293-
// if e.
294306
}
295307
events = append(events, event)
296308
}

0 commit comments

Comments
 (0)