MCPcopy
hub / github.com/nektos/act / commandHandler

Method commandHandler

pkg/runner/command.go:36–93  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

34}
35
36func (rc *RunContext) commandHandler(ctx context.Context) common.LineHandler {
37 logger := common.Logger(ctx)
38 resumeCommand := ""
39 return func(line string) bool {
40 command, kvPairs, arg, ok := tryParseRawActionCommand(line)
41 if !ok {
42 return true
43 }
44
45 if resumeCommand != "" && command != resumeCommand {
46 logger.WithFields(logrus.Fields{"command": "ignored", "raw": line}).Infof(" \U00002699 %s", line)
47 return false
48 }
49 arg = unescapeCommandData(arg)
50 kvPairs = unescapeKvPairs(kvPairs)
51 defCommandLogger := logger.WithFields(logrus.Fields{"command": command, "kvPairs": kvPairs, "arg": arg, "raw": line})
52 switch command {
53 case "set-env":
54 if rc.Env["ACTIONS_ALLOW_UNSECURE_COMMANDS"] != "true" {
55 defCommandLogger.Errorf("The `set-env` command is disabled. Please upgrade to using Environment Files or opt into unsafe commands by setting the `ACTIONS_ALLOW_UNSECURE_COMMANDS` environment variable to `true`.")
56 break
57 }
58 rc.setEnv(ctx, kvPairs, arg)
59 case "set-output":
60 rc.setOutput(ctx, kvPairs, arg)
61 case "add-path":
62 if rc.Env["ACTIONS_ALLOW_UNSECURE_COMMANDS"] != "true" {
63 defCommandLogger.Errorf("The `add-path` command is disabled. Please upgrade to using Environment Files or opt into unsafe commands by setting the `ACTIONS_ALLOW_UNSECURE_COMMANDS` environment variable to `true`.")
64 break
65 }
66 rc.addPath(ctx, arg)
67 case "debug":
68 defCommandLogger.Debugf(" \U0001F4AC %s", line)
69 case "warning":
70 defCommandLogger.Warnf(" \U0001F6A7 %s", line)
71 case "error":
72 defCommandLogger.Errorf(" \U00002757 %s", line)
73 case "add-mask":
74 rc.AddMask(arg)
75 defCommandLogger.Infof(" \U00002699 %s", "***")
76 case "stop-commands":
77 resumeCommand = arg
78 defCommandLogger.Infof(" \U00002699 %s", line)
79 case resumeCommand:
80 resumeCommand = ""
81 defCommandLogger.Infof(" \U00002699 %s", line)
82 case "save-state":
83 defCommandLogger.Infof(" \U0001f4be %s", line)
84 rc.saveState(ctx, kvPairs, arg)
85 case "add-matcher":
86 defCommandLogger.Infof(" \U00002753 add-matcher %s", arg)
87 default:
88 defCommandLogger.Infof(" \U00002753 %s", line)
89 }
90
91 return false
92 }
93}

Callers 15

startHostEnvironmentMethod · 0.95
startJobContainerMethod · 0.95
TestSaveStateFunction · 0.95
newStepContainerMethod · 0.80
useStepLoggerFunction · 0.80
newStepContainerFunction · 0.80
TestSetEnvFunction · 0.80
TestSetEnvBlockedFunction · 0.80
TestSetOutputFunction · 0.80
TestAddpathFunction · 0.80
TestAddPathBlockedFunction · 0.80

Calls 9

setEnvMethod · 0.95
setOutputMethod · 0.95
addPathMethod · 0.95
AddMaskMethod · 0.95
saveStateMethod · 0.95
LoggerFunction · 0.92
tryParseRawActionCommandFunction · 0.85
unescapeCommandDataFunction · 0.85
unescapeKvPairsFunction · 0.85

Tested by 10

TestSaveStateFunction · 0.76
TestSetEnvFunction · 0.64
TestSetEnvBlockedFunction · 0.64
TestSetOutputFunction · 0.64
TestAddpathFunction · 0.64
TestAddPathBlockedFunction · 0.64
TestStopCommandsFunction · 0.64
TestAddpathADOFunction · 0.64
TestAddmaskFunction · 0.64
TestAddmaskUsemaskFunction · 0.64