这个 action-validator 是一个独立工具,旨在“lint” YAML 文件
用于定义 GitHub 动作和工作流程。 它确保它们的结构良好,
通过检查它们与公布的JSON计划, 它确保任何
用于 paths 编号 : paths-ignore 匹配 repo 中至少一个文件.
用于 action-validator 在基特前承诺钩和
类似情况.
安装
我们有很多方法可以安装 action-validator。 。 。 .
预建二进制
这个 GitHub 发布 有一些预设的二进制-- 下载后放入你的路径。 如果有的话 你的平台没有二进制,让我知道 我会看看我能做什么 想想办法.
使用货物
如果你安装了Rust工具链,就运行 cargo install action-validator 应该给你最新消息.
使用灰尘
如果你是一个支持 缓冲工具,那么你就可以这样
用于安装和管理 action-validator数字 :
asdf plugin add action-validator
# or
asdf plugin add action-validator https://github.com/mpalmer/action-validator.git
安装/配置动作验证器 :
# 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应用程序内直接使用.
npm install -g @action-validator/core @action-validator/cli --save-dev
从收回的大楼
如果你想在当地建设,就需要:
-
在某个地方检查 Git 仓库;
-
拿着
SchemaStore子模块,通过运行git submodule init && git submodule update· ; -
安装 a 锈 工具链;然后
-
运行
cargo build。 。 。 .
使用量
再简单不过了: 把文件传给程序:
action-validator .github/workflows/build.yml
使用 action-validator -h 以查看其他选项.
责
作为预期用途
action-validator在承诺前的钩, 它假设它是从仓库的根部运行的。 光环 检查会爆炸的可怕 如果你运行它 从子目录 repo——或者,天堂要塞,完全在仓库之外.
在 GitHub 动作中
动作验证器可以在Github动作本身中运行,作为牵引请求工作. 见 actions 任务在 QA 工作流程,在这个寄存器中,作为在 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 并粘贴以下示例代码:
#!/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(+)
国家预防机制
如果你跟随 国家预防机制安装指令您可以运行动作 验证器 CLI 如下
npx action-validator <path_to_action_yaml>
或者,如果你已经在全球安装了软件包:
action-validator <path_to_action_yaml>
节点 API
节点API可用于验证来自Node.js的动作和工作流程文件如下:
QQ 节点 API 目前不支持 glob 验证 .
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;
捐款
请看 捐款额。 。 。 .
许可证
除非另有说明,否则本押金中的所有款项均由下列款项支付: 版权通知:
Copyright (C) 2021 Matt Palmer <[email protected]>
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/>.