1.1.1 • Published 5 months ago
cjlint-sarif v1.1.1
cjlint-sarif
一个将 cjlint 输出转换为 SARIF 格式的工具。
功能特点
- 将 cjlint 的检查结果转换为标准的 SARIF 格式
- 支持命令行使用
- 支持 CommonJS 和 ES Module 两种导入方式
- 支持 GitHub Actions
- 完整的测试覆盖
安装
# 使用 npm
npm install cjlint-sarif
# 使用 pnpm
pnpm add cjlint-sarif
# 使用 yarn
yarn add cjlint-sarif
使用方法
命令行使用
npx cjlint-sarif <input-file> -o <output-file>
作为模块使用
// ES Module
import { convert } from "cjlint-sarif";
// CommonJS
const { convert } = require("cjlint-sarif");
GitHub Actions
您可以在 GitHub Actions 工作流中使用此工具来转换 cjlint 的输出:
- name: Convert CJLint to SARIF
uses: Zxilly/cjlint-sarif@v1
with:
input-file: "path/to/cjlint-output.json"
output-file: "output.sarif"
输入参数
input-file
:(必需)cjlint JSON 输出文件的路径output-file
:(可选)SARIF 输出文件的路径,默认为 'cjlint-output.sarif'
版本标签
本项目使用语义化版本标签。当发布新版本时(如 v1.2.3
),会自动更新以下标签:
v1
:指向最新的 1.x.x 版本v1.2
:指向最新的 1.2.x 版本
您可以在工作流中使用这些标签来获取不同级别的更新:
@v1
:始终使用最新的主版本@v1.2
:使用特定的次版本系列@v1.2.3
:锁定到特定版本
示例工作流
name: Code Quality
on: [push, pull_request]
jobs:
analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Zxilly/setup-cangjie@v1
with:
channel: "canary" # 当前仅有 Canary 渠道提供 cjlint
token: ${{ secrets.GITCODE_TOKEN }}
# 运行 cjlint 并生成 JSON 输出
- name: Run CJLint
run: cjlint src/ -r json -o cjlint-output.json
# 转换为 SARIF 格式
- name: Convert to SARIF
uses: Zxilly/cjlint-sarif@v1
with:
input-file: "cjlint-output.json"
output-file: "cjlint.sarif"
# 上传 SARIF 结果到 GitHub
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: cjlint.sarif
开发
# 安装依赖
pnpm install
# 运行测试
pnpm test
# 运行测试覆盖率报告
pnpm test:coverage
# 构建项目
pnpm build
# 本地开发
pnpm dev
构建 GitHub Action
如果您要修改 GitHub Action 的代码,需要注意:
- Action 的构建输出(
dist/action.js
)需要被提交到版本控制中 每次修改 Action 相关代码后,请执行以下步骤:
# 构建 Action pnpm build # 提交更改,包括 dist/action.js git add dist/action.js git commit -m "chore: update action distribution"
发布新版本
- 更新
package.json
中的版本号 - 提交更改并创建对应的版本标签:
git add package.json git commit -m "chore: bump version to X.Y.Z" git tag vX.Y.Z git push origin vX.Y.Z
- GitHub Actions 会自动:
- 验证版本号匹配
- 运行测试
- 发布到 npm
- 创建 GitHub Release
- 更新主版本和次版本标签
技术栈
- TypeScript
- Rollup
- Vitest
- GitHub Actions
许可证
本项目使用 MIT 许可证 - 查看 LICENSE 文件了解更多详情。