我是 github 操作的新手,我看到用于配置步骤的两件事(如果我错了,请纠正我)with和env.
这两者有什么区别以及它们是如何使用的。
uses: someAction
with:
x: 10
y: 20
env:
x1: 30
y2: 40
Run Code Online (Sandbox Code Playgroud)
with - 专门用于向动作传递参数
env - 专门用于引入可以根据资源范围访问的环境变量
workflow envs - can be accessed by all resources in the workflow except services
job envs - can be accessed by all resources under job except services
step envs - can be accessed by any resource within the step
Run Code Online (Sandbox Code Playgroud)
这是一个关于如何处理参数的示例
假设使用以下参数创建了一个动作 action.yaml
name: 'Npm Audit Action'
inputs:
dirPath:
description: 'Directory path of the project to audit'
required: true
default: './'
Run Code Online (Sandbox Code Playgroud)
然后我们会with在我们的工作流中通过标签提供这个参数
- name: Use the action
uses: meroware/npm-audit-action@v1.0.2
with:
dirPath: vulnerable-project
Run Code Online (Sandbox Code Playgroud)
然后在动作代码中,如果构建一个 Node.js 动作,我们将这样处理它
const core = require("@actions/core");
const dirPath = core.getInput("dirPath");
Run Code Online (Sandbox Code Playgroud)
动作中的 Envs 的访问方式不同,假设我们正在构建一个 Node.js 动作,然后我们将通过process.env. 回到我们的示例操作
name: 'Npm Audit Action'
env:
SOME_ENV: 'hey I am an env'
Run Code Online (Sandbox Code Playgroud)
然后这可以访问为
const { someEnv: SOME_ENV } = process.env
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
493 次 |
| 最近记录: |