如何(以及为什么)升级 GitHub 工作流程以使用“环境文件”

How (and why) upgrade a GitHub workflow to use “Environment files”

我有一个 GitHub 动作工作流文件 运行 很好,但最近我注意到了关于“set-env”和“add-path”弃用的警告。 GitHub 建议的修复是使用“环境文件”; IE。将值通过管道传输到由 GITHUB_ENV 文件描述符管理的文件中。

我的问题是:GitHub 是否要求我将工作流程中的“env”块替换为包含“echo “{name}={value}”形式的命令的步骤>> $GITHUB_ENV'?

我还要问为什么这是必要的,因为我认为它很蹩脚,但那真的不是重点。

根据我使用 python 和 GitHub 操作的经验,这是 actions/setup-python 版本 1.1.1 和更早版本的问题。您的工作流程中可能有一行内容为:

uses: actions/setup-python@v1.1.1

如果升级到 setup-python 的版本 2,将不会出现警告。只需将上面的行更改为以下内容:

uses: actions/setup-python@v2

为了演示,我的日志v1.1.1 workflow shows the warnings you mentioned, but the warnings are resolved by using version 2

I have to also ask why this is necessary

这是announced in early Oct. 2020 this month, and pointed to a moderate security vulnerability

The @actions/core npm module addPath and exportVariable functions communicate with the Actions Runner over stdout by generating a string in a specific format.
Workflows that log untrusted data to stdout may invoke these commands, resulting in the path or environment variables being modified without the intention of the workflow or action author.

For now, users should upgrade to @actions/core v1.2.6 or later, and replace any instance of the set-env or add-path commands in their workflows with the new Environment File Syntax.
Workflows and actions using the old commands or older versions of the toolkit will start to warn, then error out during workflow execution.

所以:

echo "FOO=BAR" >> $GITHUB_ENV
echo "/Users/test/.nvm/versions/node/v12.18.3/bin" >> $GITHUB_PATH

这就是为什么要像 actions/setup-python has a recent PR 138 in order to uses Environment files 这样的 GitHub 动作来与跑步者交流。

但是如果您正在使用基于 actions/core 的任何其他工作流程,您需要尽快升级上述 actions/core 版本。