Skip to content

Commit 10a7ff1

Browse files
authored
Merge pull request #149 from Tenderly/dgp/invocation-type-support
[PIPE-670] - Parallel Execution Support
2 parents 806ef39 + 6e7d1ab commit 10a7ff1

File tree

4 files changed

+227
-97
lines changed

4 files changed

+227
-97
lines changed

commands/actions/init.go

Lines changed: 72 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,24 @@ module.exports = { blockHelloWorldFn };
5757
var initDescription = "This is just an example, but you can publish this action."
5858

5959
var initAction = &actionsModel.ActionSpec{
60-
Description: &initDescription,
61-
Function: "example:blockHelloWorldFn",
62-
Trigger: actionsModel.TriggerUnparsed{Type: "block"},
60+
Description: &initDescription,
61+
Function: "example:blockHelloWorldFn",
62+
Trigger: actionsModel.TriggerUnparsed{Type: "block"},
63+
ExecutionType: "sequential",
6364
}
6465

6566
func init() {
66-
initCmd.PersistentFlags().StringVar(&actionsSourcesDir, "sources", "", "The path where the actions will be created.")
67-
initCmd.PersistentFlags().StringVar(&actionsLanguage, "language", "typescript", "Initialize actions for this language. Supported {javascript, typescript}")
68-
initCmd.PersistentFlags().StringVar(&actionsTemplateName, "template", "", "Initialize actions from this template, see Tenderly/tenderly-actions.")
67+
initCmd.PersistentFlags().StringVar(
68+
&actionsSourcesDir, "sources", "", "The path where the actions will be created.",
69+
)
70+
initCmd.PersistentFlags().StringVar(
71+
&actionsLanguage, "language", "typescript",
72+
"Initialize actions for this language. Supported {javascript, typescript}",
73+
)
74+
initCmd.PersistentFlags().StringVar(
75+
&actionsTemplateName, "template", "",
76+
"Initialize actions from this template, see Tenderly/tenderly-actions.",
77+
)
6978

7079
actionsCmd.AddCommand(initCmd)
7180
}
@@ -88,11 +97,13 @@ var initCmd = &cobra.Command{
8897
"Actions for project are already initialized",
8998
userError.NewUserError(
9099
fmt.Errorf("actions initialized"),
91-
commands.Colorizer.Sprintf("Actions for project %s are already initialized, see %s",
100+
commands.Colorizer.Sprintf(
101+
"Actions for project %s are already initialized, see %s",
92102
commands.Colorizer.Bold(commands.Colorizer.Green(projectSlug)),
93103
commands.Colorizer.Bold(commands.Colorizer.Green("tenderly.yaml")),
94104
),
95-
))
105+
),
106+
)
96107
os.Exit(0)
97108
}
98109

@@ -106,7 +117,10 @@ var initCmd = &cobra.Command{
106117
if err != nil {
107118
userError.LogErrorf(
108119
"failed to load template",
109-
userError.NewUserError(err, fmt.Sprintf("Failed to load template %s", actionsTemplateName)))
120+
userError.NewUserError(
121+
err, fmt.Sprintf("Failed to load template %s", actionsTemplateName),
122+
),
123+
)
110124
os.Exit(1)
111125
}
112126

@@ -127,28 +141,36 @@ var initCmd = &cobra.Command{
127141
if err != nil {
128142
userError.LogErrorf(
129143
"failed to load template specs",
130-
userError.NewUserError(err, fmt.Sprintf("Failed to load specs for template %s", actionsTemplateName)))
144+
userError.NewUserError(
145+
err, fmt.Sprintf("Failed to load specs for template %s", actionsTemplateName),
146+
),
147+
)
131148
os.Exit(1)
132149
}
133150
}
134151

135-
config.MustWriteActionsInit(projectSlug, &actionsModel.ProjectActions{
136-
Runtime: actionsModel.RuntimeV2,
137-
Sources: sources,
138-
Dependencies: nil,
139-
Specs: specs,
140-
})
152+
config.MustWriteActionsInit(
153+
projectSlug, &actionsModel.ProjectActions{
154+
Runtime: actionsModel.RuntimeV2,
155+
Sources: sources,
156+
Dependencies: nil,
157+
Specs: specs,
158+
},
159+
)
141160

142161
if actionsLanguage == LanguageJavaScript {
143162
filePath := filepath.Join(sources, "example.js")
144163
content := initActionJavascript
145164

146165
util.CreateFileWithContent(filePath, content)
147166

148-
logrus.Info(commands.Colorizer.Sprintf("\nInitialized actions project. Sources directory created at %s. Configuration created in %s.",
149-
commands.Colorizer.Bold(commands.Colorizer.Green(sources)),
150-
commands.Colorizer.Bold(commands.Colorizer.Green("tenderly.yaml")),
151-
))
167+
logrus.Info(
168+
commands.Colorizer.Sprintf(
169+
"\nInitialized actions project. Sources directory created at %s. Configuration created in %s.",
170+
commands.Colorizer.Bold(commands.Colorizer.Green(sources)),
171+
commands.Colorizer.Bold(commands.Colorizer.Green("tenderly.yaml")),
172+
),
173+
)
152174

153175
os.Exit(0)
154176
}
@@ -183,18 +205,24 @@ var initCmd = &cobra.Command{
183205
if err != nil {
184206
userError.LogErrorf(
185207
"failed to create from template",
186-
userError.NewUserError(err, fmt.Sprintf("Failed to create from template %s", actionsTemplateName)))
208+
userError.NewUserError(
209+
err, fmt.Sprintf("Failed to create from template %s", actionsTemplateName),
210+
),
211+
)
187212
os.Exit(1)
188213
}
189214
}
190215

191216
// Install dependencies
192217
mustInstallDependencies(sources)
193218

194-
logrus.Info(commands.Colorizer.Sprintf("\nInitialized actions project. Sources directory created at %s. Configuration created in %s.",
195-
commands.Colorizer.Bold(commands.Colorizer.Green(sources)),
196-
commands.Colorizer.Bold(commands.Colorizer.Green("tenderly.yaml")),
197-
))
219+
logrus.Info(
220+
commands.Colorizer.Sprintf(
221+
"\nInitialized actions project. Sources directory created at %s. Configuration created in %s.",
222+
commands.Colorizer.Bold(commands.Colorizer.Green(sources)),
223+
commands.Colorizer.Bold(commands.Colorizer.Green("tenderly.yaml")),
224+
),
225+
)
198226

199227
os.Exit(0)
200228
},
@@ -229,8 +257,10 @@ func promptTemplateArg(arg actionsModel.TemplateArg) string {
229257
if result == "" {
230258
userError.LogErrorf(
231259
"value for template arg not entered",
232-
userError.NewUserError(errors.New("enter template arg"),
233-
"Value for template arg not entered correctly"),
260+
userError.NewUserError(
261+
errors.New("enter template arg"),
262+
"Value for template arg not entered correctly",
263+
),
234264
)
235265
os.Exit(1)
236266
}
@@ -241,7 +271,11 @@ func mustValidateFlags() {
241271
if actionsLanguage != LanguageTypeScript && actionsLanguage != LanguageJavaScript {
242272
userError.LogErrorf(
243273
"language not supported",
244-
userError.NewUserError(errors.New("language not supported"), fmt.Sprintf("Language %s not supported", actionsLanguage)))
274+
userError.NewUserError(
275+
errors.New("language not supported"),
276+
fmt.Sprintf("Language %s not supported", actionsLanguage),
277+
),
278+
)
245279
os.Exit(1)
246280
}
247281
}
@@ -251,17 +285,21 @@ func chooseSources() string {
251285
if util.ExistFile(actionsSourcesDir) {
252286
userError.LogErrorf(
253287
"sources dir is file: %s",
254-
userError.NewUserError(errors.New("sources dir is file"),
255-
"Selected sources directory is a file."),
288+
userError.NewUserError(
289+
errors.New("sources dir is file"),
290+
"Selected sources directory is a file.",
291+
),
256292
)
257293
os.Exit(1)
258294
}
259295

260296
if util.ExistDir(actionsSourcesDir) {
261297
userError.LogErrorf(
262298
"sources dir exists: %s",
263-
userError.NewUserError(errors.New("sources dir exists"),
264-
"Selected sources directory already exists."),
299+
userError.NewUserError(
300+
errors.New("sources dir exists"),
301+
"Selected sources directory already exists.",
302+
),
265303
)
266304
os.Exit(1)
267305
}
@@ -324,7 +362,8 @@ func excludeFromTsconfigParent(sourcesPath string, parentPath string) {
324362
if err != nil {
325363
userError.LogErrorf(
326364
"failed to get path relative to parentPath",
327-
userError.NewUserError(err, fmt.Sprintf("Can't find relative path for %s", sourcesPath)))
365+
userError.NewUserError(err, fmt.Sprintf("Can't find relative path for %s", sourcesPath)),
366+
)
328367
os.Exit(1)
329368
}
330369
rel = relTmp

0 commit comments

Comments
 (0)