github.com/jfrog/frogbot@v1.1.1-0.20231221090046-821a26f50338/action/node_modules/@actions/core/lib/file-command.js (about)

     1  "use strict";
     2  // For internal use, subject to change.
     3  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
     4      if (k2 === undefined) k2 = k;
     5      Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
     6  }) : (function(o, m, k, k2) {
     7      if (k2 === undefined) k2 = k;
     8      o[k2] = m[k];
     9  }));
    10  var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    11      Object.defineProperty(o, "default", { enumerable: true, value: v });
    12  }) : function(o, v) {
    13      o["default"] = v;
    14  });
    15  var __importStar = (this && this.__importStar) || function (mod) {
    16      if (mod && mod.__esModule) return mod;
    17      var result = {};
    18      if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    19      __setModuleDefault(result, mod);
    20      return result;
    21  };
    22  Object.defineProperty(exports, "__esModule", { value: true });
    23  exports.prepareKeyValueMessage = exports.issueFileCommand = void 0;
    24  // We use any as a valid input type
    25  /* eslint-disable @typescript-eslint/no-explicit-any */
    26  const fs = __importStar(require("fs"));
    27  const os = __importStar(require("os"));
    28  const uuid_1 = require("uuid");
    29  const utils_1 = require("./utils");
    30  function issueFileCommand(command, message) {
    31      const filePath = process.env[`GITHUB_${command}`];
    32      if (!filePath) {
    33          throw new Error(`Unable to find environment variable for file command ${command}`);
    34      }
    35      if (!fs.existsSync(filePath)) {
    36          throw new Error(`Missing file at path: ${filePath}`);
    37      }
    38      fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os.EOL}`, {
    39          encoding: 'utf8'
    40      });
    41  }
    42  exports.issueFileCommand = issueFileCommand;
    43  function prepareKeyValueMessage(key, value) {
    44      const delimiter = `ghadelimiter_${uuid_1.v4()}`;
    45      const convertedValue = utils_1.toCommandValue(value);
    46      // These should realistically never happen, but just in case someone finds a
    47      // way to exploit uuid generation let's not allow keys or values that contain
    48      // the delimiter.
    49      if (key.includes(delimiter)) {
    50          throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`);
    51      }
    52      if (convertedValue.includes(delimiter)) {
    53          throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`);
    54      }
    55      return `${key}<<${delimiter}${os.EOL}${convertedValue}${os.EOL}${delimiter}`;
    56  }
    57  exports.prepareKeyValueMessage = prepareKeyValueMessage;
    58  //# sourceMappingURL=file-command.js.map