@actions/core#notice TypeScript Examples

The following examples show how to use @actions/core#notice. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: eslint.ts    From action-eslint with MIT License 6 votes vote down vote up
runEslint = async (inputs: Inputs): Promise<void> => {
  if (!inputs.annotations) {
    disableAnnotations();
  }

  const changedFiles = await getChangedFiles(inputs.token);

  startGroup('Files changed.');
  changedFiles.forEach((file) => info(`- ${file}`));
  endGroup();

  const files = changedFiles.filter((filename) => {
    const isFileSupported = inputs.extensions.find((ext) => filename.endsWith(`.${ext}`));
    return isFileSupported;
  });

  if (files.length === 0) {
    notice('No files found. Skipping.');
    return;
  }

  startGroup('Files for linting.');
  files.forEach((file) => info(`- ${file}`));
  endGroup();

  const execOptions = [
    path.resolve(inputs.binPath, 'eslint'),
    ...files,
    ...inputs.eslintArgs,
  ].filter(Boolean);

  await exec('node', execOptions);
}
Example #2
Source File: main.ts    From setup-cpp with Apache License 2.0 4 votes vote down vote up
/** The main entry function */
export async function main(args: string[]): Promise<number> {
  if (!isGitHubCI()) {
    process.env.ACTIONS_ALLOW_UNSECURE_COMMANDS = "true"
  }

  // parse options using mri or github actions
  const opts = parseArgs(args)

  // print help
  if (opts.help) {
    printHelp()
  }

  // cpu architecture
  const arch = opts.architecture ?? process.arch

  // the installation dir for the tools that are downloaded directly
  const setupCppDir = process.env.SETUP_CPP_DIR ?? untildify("")

  // report messages
  const successMessages: string[] = []
  const errorMessages: string[] = []

  const timeFormatter = timeDelta.create({ autoloadLocales: true })
  timeDelta.addLocale(timeDeltaLocale as timeDelta.Locale)
  numerous.addLocale(numerousLocale)
  let time1: number
  let time2: number

  // installing the specified tools

  let osVersion: number[] | null = null
  try {
    // get the version if not already done
    osVersion = await ubuntuVersion()
  } catch (err) {
    warning((err as Error).toString())
  }

  // sync the version for the llvm tools
  if (!syncVersions(opts, ["llvm", "clangtidy", "clangformat"])) {
    error("The same version must be used for llvm, clangformat and clangtidy")
    return 1
  }

  // loop over the tools and run their setup function
  for (const tool of tools) {
    // get the version or "true" or undefined for this tool from the options
    const version = opts[tool]

    // skip if undefined
    if (version !== undefined) {
      // running the setup function for this tool
      time1 = Date.now()
      startGroup(`Installing ${tool} ${version}`)
      try {
        let installationInfo: InstallationInfo | undefined | void
        if (tool === "vcvarsall") {
          // eslint-disable-next-line no-await-in-loop
          await setupVCVarsall(
            getVersion(tool, version, osVersion),
            undefined,
            arch,
            undefined,
            undefined,
            false,
            false
          )
        } else {
          // get the setup function
          const setupFunction = setups[tool]

          // the tool installation directory (for the functions that ue it)
          const setupDir = join(setupCppDir, ["llvm", "clangformat", "clangtidy"].includes(tool) ? "llvm" : tool)

          // eslint-disable-next-line no-await-in-loop
          installationInfo = await setupFunction(getVersion(tool, version, osVersion), setupDir, arch)
        }
        // preparing a report string
        successMessages.push(getSuccessMessage(tool, installationInfo))
      } catch (e) {
        // push error message to the logger
        error(e as string | Error)
        errorMessages.push(`${tool} failed to install`)
      }
      endGroup()
      time2 = Date.now()
      info(`took ${timeFormatter.format(time1, time2) || "0 seconds"}`)
    }
  }

  // installing the specified compiler
  const maybeCompiler = opts.compiler
  time1 = Date.now()
  try {
    if (maybeCompiler !== undefined) {
      const { compiler, version } = getCompilerInfo(maybeCompiler)

      // install the compiler. We allow some aliases for the compiler name
      startGroup(`Installing ${compiler} ${version ?? ""}`)
      switch (compiler) {
        case "llvm":
        case "clang":
        case "clang++": {
          const installationInfo = await setupLLVM(
            getVersion("llvm", version, osVersion),
            join(setupCppDir, "llvm"),
            arch
          )
          successMessages.push(getSuccessMessage("llvm", installationInfo))
          break
        }
        case "gcc":
        case "mingw":
        case "cygwin":
        case "msys": {
          const installationInfo = await setupGcc(getVersion("gcc", version, osVersion), join(setupCppDir, "gcc"), arch)
          successMessages.push(getSuccessMessage("gcc", installationInfo))
          break
        }
        case "cl":
        case "msvc":
        case "msbuild":
        case "vs":
        case "visualstudio":
        case "visualcpp":
        case "visualc++": {
          const installationInfo = await setupMSVC(
            getVersion("msvc", version, osVersion),
            join(setupCppDir, "msvc"),
            arch
          )
          successMessages.push(getSuccessMessage("msvc", installationInfo))
          break
        }
        case "appleclang":
        case "applellvm": {
          notice("Assuming apple-clang is already installed")
          await Promise.all([addEnv("CC", "clang"), addEnv("CXX", "clang++")])
          successMessages.push(getSuccessMessage("apple-clang", undefined))
          break
        }
        default: {
          errorMessages.push(`Unsupported compiler ${compiler}`)
        }
      }
      endGroup()
      time2 = Date.now()
      info(`took ${timeFormatter.format(time1, time2) || "0 seconds"}`)
    }
  } catch (e) {
    error(e as string | Error)
    errorMessages.push(`Failed to install the ${maybeCompiler}`)
    endGroup()
    time2 = Date.now()
    info(`took ${timeFormatter.format(time1, time2) || "0 seconds"}`)
  }

  if (successMessages.length === 0 && errorMessages.length === 0) {
    warning("setup_cpp was called without any arguments. Nothing to do.")
    return 0
  }

  // report the messages in the end
  successMessages.forEach((tool) => success(tool))
  errorMessages.forEach((tool) => error(tool))

  info("setup_cpp finished")

  if (!isGitHubCI()) {
    switch (process.platform) {
      case "win32": {
        warning("Run `RefreshEnv.cmd` or restart your shell to update the environment.")
        break
      }
      case "linux":
      case "darwin": {
        warning("Run `source ~/.cpprc` or restart your shell to update the environment.")
        break
      }
      default: {
        // nothing
      }
    }
  }

  return errorMessages.length === 0 ? 0 : 1 // exit with non-zero if any error message
}