我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们

GitHub 操作的开发工具

You can create JavaScript actions more quickly using the GitHub 操作 Node.js toolkit and interact with the log files using log commands.

GitHub 操作 目前在有限公测阶段,可能会有变动。强烈建议在公测期间不要将此功能用于高价值工作流程和内容。

更多信息请参阅“关于 GitHub 操作”。

本文内容

GitHub 操作 的 Node.js 工具包

如果开发 Node.js 项目,操作工具包提供可用在项目中加速开发的软件包。 更多信息请参阅 actions/toolkit 仓库。

要快速开始,可以使用 JavaScript 或 Docker 容器操作模板仓库创建仓库。 更多信息请参阅“JavaScript 操作模板”、“Docker 容器操作模板”和“从模板创建仓库”。

Logging commands

Actions can communicate with the GitHub-hosted virtual machine to set environment variables, output values used by other actions, add debug messages to the output logs, and other tasks.

Logging commands use the echo command in a specific format.

echo ::log-command parameter1={data},parameter2={data}::{command value}

Note: Log command and parameter names are not case-sensitive.

GitHub 操作 includes a variety of commands.

Set an environment variable: set-env

::set-env name={name}::{value}

Creates or updates an environment variable for any actions running next in a job. The action that creates or updates the environment variable does not have access to the new value, but all subsequent actions in a job will have access. Environment variables are case-sensitive and you can include punctuation.

示例
echo ::set-env name=action_state::yellow

Set an output parameter: set-output

::set-output name={name}::{value}

Sets an action's output parameter. Output parameters are defined in an action's metadata file. For more information, see "[Metadata syntax for GitHub 操作

](/articles/metadata-syntax-for-github-actions)."

You will receive an error if you attempt to set an output value that was not declared in the action's metadata file.

示例
echo ::set-output name=action_fruit::strawberry

Add a system path: add-path

::add-path::{path}

Prepends a directory to the system PATH variable for all subsequent actions in the current job. The currently running action cannot access the new path variable.

示例
echo ::add-path::/path/to/dir

Set a debug message: debug

::debug::{message}

Prints a debug message to the log. You must create a secret named ACTIONS_STEP_DEBUG with the value true to see the debug messages set by this command in the log. To learn more about creating secrets and using them in a step, see "Virtual environments for GitHub 操作."

示例
echo ::debug file=app.js,line=1::Entered octocatAddition method

Set a warning message: warning

::warning file={name},line={line},col={col}::{message}

Creates a warning message and prints the message to the log. You can optionally provide a filename (file), line number (line), and column (col) number where the warning occurred.

示例
echo ::warning file=app.js,line=1,col=5::Missing semicolon

Set an error message: error

::error file={name},line={line},col={col}::{message}

Creates an error message and prints the message to the log. You can optionally provide a filename (file), line number (line), and column (col) number where the warning occurred.

示例
echo ::error file=app.js,line=10,col=15::Something went wrong

Mask a value in log: add-mask

::add-mask::{value}

Masking a value prevents a string or variable from being printed in the log. Each masked word separated by whitespace is replaced with the * character. You can use an environment variable or string for the mask's value.

Example masking a string

When you print "Mona The Octocat" in the log, you'll see "***".

echo ::add-mask::Mona The Octocat
Example masking an environment variable

When you print the variable MY_NAME or the value "Mona The Octocat" in the log, you'll see "***" instead of "Mona The Octocat".

MY_NAME="Mona The Octocat"
echo ::add-mask::$MY_NAME

Stop and start log commands: stop-commands

::stop-commands::{endtoken}

Stops processing any logging commands. This special command allows you to log anything without accidentally running a log command. For example, you could stop logging to output an entire script that has comments.

Example stopping log commands
echo ::stop-commands::pause-logging

To start log commands, pass the token that you used to stop logging.

::{endtoken}::

Example starting log commands
echo ::pause-logging::

问问别人

找不到要找的内容?

联系我们