# @action-validator/cli 中文文档

规范地址：https://npmcn.com/package/%40action-validator/cli/

版本：0\.6\.0
npm 元数据更新时间：2024-02-23T05:52:05.849Z
中文译文更新时间：2026-11-05T17:42:37.734Z
软件包许可：GPL-3\.0-only

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40action-validator/cli
原文对照：https://npmcn.com/package/%40action-validator/cli/?lang=original
项目主页：https://github.com/mpalmer/action-validator
源码仓库：https://github.com/mpalmer/action-validator

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：44.5 kB，4 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：1 个
- peer 依赖：@action-validator/core 0\.6\.0
- 首次发布：2023-03-03T05:36:51.268Z
- 最新版本发布：2024-02-23T05:52:05.425Z
- 近 30 天下载量：170344（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：7（近 12 个月 0 个）

## 中文简介

GitHub 动作和工作流程 YAML 文件验证器

## 安装

```sh
npm install @action-validator/cli
```

也可以使用：`pnpm add @action-validator/cli`、`yarn add @action-validator/cli`、`bun add @action-validator/cli`

## README

这个 `action-validator` 是一个独立工具,旨在“lint” YAML 文件 用于定义 GitHub 动作和工作流程。 它确保它们的结构良好, 通过检查它们与公布的JSON计划, 它确保任何 用于 `paths` 编号 : `paths-ignore` 匹配 repo 中至少一个文件.

用于 `action-validator` 在基特前承诺钩和 类似情况.

# 安装

我们有很多方法可以安装 `action-validator`。 。 。 .

## 预建二进制

这个 [GitHub 发布](https://github.com/mpalmer/action-validator/releases) 有一些预设的二进制-- 下载后放入你的路径。 如果有的话 你的平台没有二进制,让我知道 我会看看我能做什么 想想办法.

## 使用货物

如果你安装了Rust工具链,就运行 `cargo install action-validator` 应该给你最新消息.

## 使用灰尘

如果你是一个支持 [缓冲工具](https://asdf-vm.com/),那么你就可以这样 用于安装和管理 `action-validator`数字 :

```shell
asdf plugin add action-validator
# or
asdf plugin add action-validator https://github.com/mpalmer/action-validator.git
```

安装/配置动作验证器 :

```shell
# Show all installable versions
asdf list-all action-validator

# Install specific version
asdf install action-validator latest

# Set a version globally (on your ~/.tool-versions file)
asdf global action-validator latest

# Now action-validator commands are available
action-validator --help
```

## 利用国家预防机制

节点用户可以利用国家预防机制安装最新版本:

> 我... 这.. `@action-validator/core` 软件包可以在Node.js应用程序内直接使用.

```sh
npm install -g @action-validator/core @action-validator/cli --save-dev
```

## 从收回的大楼

如果你想在当地建设,就需要:

1.  在某个地方检查 Git 仓库;
    
2.  拿着 `SchemaStore` 子模块,通过运行 `git submodule init && git submodule update`· ;
    
3.  安装 a [锈](https://rust-lang.org/) 工具链;然后
    
4.  运行 `cargo build`。 。 。 .
    

# 使用量

再简单不过了: 把文件传给程序:

```shell
action-validator .github/workflows/build.yml
```

使用 `action-validator -h` 以查看其他选项.

> ### 责
> 
> 作为预期用途 `action-validator` 在承诺前的钩, 它假设它是从仓库的根部运行的。 光环 检查会爆炸的可怕 如果你运行它 从子目录 repo——或者,天堂要塞,完全在仓库之外.

## 在 GitHub 动作中

动作验证器可以在Github动作本身中运行,作为牵引请求工作. 见 `actions` 任务在 [QA 工作流程](https://github.com/mpalmer/action-validator/tree/main/.github/workflows/qa.yml),在这个寄存器中,作为在 GitHub 工作流程中如何使用动作验证器+asdf 的例子. 这可能看起来有点多余(毕竟,一个动作必须有效才能让GitHub运行),但是这个工作会确保您所有的操作 _其他项目_ 动作也是有效的.

## 使用预承诺

更新您的 . pre-config. yaml :

```
repos:
- repo: https://github.com/mpalmer/action-validator
  rev: v0.5.1
  hooks:
    - id: action-validator
```

## 承诺前钩子示例

在目标仓库的.git/hoks目录中创建可执行文件 : `touch .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit` 并粘贴以下示例代码:

```bash
#!/bin/bash
if ! command -v action-validator >/dev/null; then
  echo "action-validator is not installed."
  echo "Installation instructions: https://github.com/mpalmer/action-validator"
  exit 1
fi
echo "Running pre-commit hook for GitHub Actions: https://github.com/mpalmer/action-validator"
scan_count=0
for action in $(git diff --cached --name-only --diff-filter=ACM | grep -E '^\.github/(workflows|actions)/.*\.ya?ml$'); do
  if action-validator "$action"; then
    echo "✅ $action"
  else
    echo "❌ $action"
    exit 1
  fi
  scan_count=$((scan_count+1))
done
echo "action-validator scanned $scan_count GitHub Actions and found no errors!"
```

此脚本将运行在目标寄存器的每个承诺上, 无论 github 动作 yaml 文件是否被执行, 并且如果有 Linting 错误, 则防止任何执行 .

```
# All action-validator linting errors must be resolved before any commit will succeed.
$ echo "" >> README.md && git add README.md && git commit -m "Update read-me"
Running pre-commit hook for GitHub Actions: https://github.com/mpalmer/action-validator
Validation failed: ValidationState {
    errors: [
        Properties {
            path: "",
            detail: "Additional property 'aname' is not allowed",
        },
    ],
    missing: [],
    replacement: None,
}
❌ .github/workflows/ci.yaml
Fatal error validating .github/workflows/ci.yaml: validation failed


# Fix error and try again
$ echo "" >> README.md && git add README.md && git commit -m "Update read-me"
Running pre-commit hook for GitHub Actions: https://github.com/mpalmer/action-validator
✅ .github/workflows/ci.yaml
✅ .github/workflows/release.yml
action-validator scanned 2 GitHub Actions found no errors!
[main c34fda3] Update read-me
 1 file changed, 2 insertions(+)
```

## 国家预防机制

如果你跟随 [国家预防机制安装指令](https://npmcn.com/package/%40action-validator/cli/#readme-using-npm)您可以运行动作 验证器 CLI 如下

```sh
npx action-validator <path_to_action_yaml>
```

或者,如果你已经在全球安装了软件包:

```sh
action-validator <path_to_action_yaml>
```

## 节点 API

节点API可用于验证来自Node.js的动作和工作流程文件如下:

> QQ 节点 API 目前不支持 glob 验证 .

```ts
import { readFileSync } from "fs";
import { validateAction, validateWorkflow } from "@action-validator/core";

// Validate Action
const actionSource = readFileSync("action.yml", "utf8");
const state = validator.validateAction(actionSource);
const isValid = state.errors.length === 0;

// Validate Workflow
const workflowSource = readFileSync("workflow.yml", "utf8");
const state = validator.validateWorkflow(workflowSource);
const isValid = state.errors.length === 0;
```

# 捐款

请看 [捐款额](https://npmcn.com/package/%40action-validator/cli/CONTRIBUTING.md)。 。 。 .

# 许可证

除非另有说明,否则本押金中的所有款项均由下列款项支付: 版权通知:

```
Copyright (C) 2021  Matt Palmer <matt@hezmatt.org>

This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License version 3, as
published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
```

## 常见问题

### @action-validator/cli 是什么？

GitHub 动作和工作流程 YAML 文件验证器

### 如何安装 @action-validator/cli？

在项目目录运行 npm install @action-validator/cli，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@action-validator/core（0\.6\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。它还提供命令行工具 action-validator，可以用 npx action-validator 直接运行。

### @action-validator/cli 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/action-validator\_\_cli 是否存在。

### @action-validator/cli 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @action-validator/cli 可以商用吗？

@action-validator/cli 使用 GPL-3\.0-only 许可。强 Copyleft：分发包含该代码的软件时，整个作品需以 GPL-3\.0 兼容许可开源，并附带专利与反锁定条款。仅内部使用不触发此义务。以上为概括，不构成法律意见，请以许可原文为准。

### @action-validator/cli 的下载量有多少？

根据 npm 官方下载统计，@action-validator/cli 在 2026/10/05 – 2026/11/03 这 30 天内被下载 170,344 次，日均约 5,678 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @action-validator/cli 还在维护吗？

最新版本 0\.6\.0 发布于 2024/02/23（2 年前）；至今共发布 7 个版本，其中过去 12 个月发布了 0 个；首次发布于 2023/03/03。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

