| 34 | } |
| 35 | |
| 36 | func (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 | } |