api-scan-action
API-Scan 接口兼容性扫描插件,克隆 openlibing-api-parser 工具仓并执行接口扫描,结果上传到 openLiBing 平台,用于 PR 门禁阶段的接口兼容性检测。
工作流程
git clone接口解析与扫描引擎仓openlibing/openlibing-api-parser(分支由tool_ref指定)到${WORKSPACE}/.api-parser-toolchmod三个可执行:scripts/openlibing_scan.sh、cli.py、tools/api_analysis/linux-x86_64-ubuntu22-llvm15/api_analysispip3 install -r requirements.txt(清华源加速)- 执行
bash openlibing_scan.sh,带--source/--exclude/--output/--upload/--upload-header参数,结果上传到upload_url finally清理.api-parser-tool目录
使用方式
name: api-scan
on:
pull_request_target:
branches: [master]
jobs:
api-scan:
name: api-scan task
runs-on: ["codearts-hosted", "ubuntu-latest", "x64", "large"]
steps:
- name: checkout repository
uses: checkout
with:
token: ${{ secrets.ROBOT_TOKEN }}
ref: ${{ atomgit.event.pull_request.merge_commit_sha || '' }}
- name: setup-python
uses: setup-python
with:
version: 3.12
- name: api-scan
uses: api-scan-action
输入参数
| 参数 | 必填 | 默认值 | 说明 |
|---|---|---|---|
| upload_url | 否 | https://apig.openlibing.com:443/openlibing-design-api-management/interface/pr-control/report | 扫描结果上传地址(openLiBing 接口),临时使用华为云 apic 地址 |
| skip_install | 否 | true | 是否跳过工具自动安装(--skip-install) |
| exclude | 否 | .api-parser-tool | 排除目录,逗号分隔 |
注:工具仓 URL 写死为 https://gitcode.com/openlibing/openlibing-api-parser.git,不参数化。
上下文派生
action 从 GitCode Actions runner 注入的 ATOMGIT_* 环境变量自动派生以下值(调用方无需配置):
| 派生项 | 来源 | 说明 |
|---|---|---|
| workspace | ATOMGIT_WORKSPACE (GITHUB_WORKSPACE) |
checkout 检出的源代码目录 |
| repo_url | ATOMGIT_REPOSITORY (owner/repo) + 固定 https://gitcode.com |
拼成 https://gitcode.com/owner/repo.git |
| merge_id | event payload pull_request.number;回退正则解析 ATOMGIT_REF (refs/pull|pull-requests|merge-requests/<n>/merge|head) |
PR 编号(非 PR 事件为空) |
| commit_id | event payload pull_request.merge_commit_sha(PR 事件)或 ATOMGIT_SHA(非 PR) |
上传 header 用 |
凭据
凭据通过以下输入参数传入(通过 APIG 网关调用 openLiBing 接口):apig-app-key / apig-app-secret。请在 workflow 的 with 中传入,凭证值使用 ${{ secrets.OPENLIBING_APIG_KEY }} / ${{ secrets.OPENLIBING_APIG_SECRET }} 引用。
依赖
- openlibing-api-parser — 接口解析与扫描引擎工具仓(Python + 预编译二进制)
scripts/openlibing_scan.sh— 扫描入口脚本cli.py— CLI 入口tools/api_analysis/linux-x86_64-ubuntu22-llvm15/api_analysis— 语言分析二进制requirements.txt— Python 依赖
构建
npm install
npm run package # ncc build src/index.js -o dist
dist/index.js 为 ncc 打包产物(已 inline 所有依赖),提交到仓供 GitCode Actions runner 直接执行。