openlibing流水线代码化:接口兼容性扫描action插件
Access rate limit exceeded. Please log in to continue.
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参数产出results.json(不再带--upload) - Node action 读取
results.json,经 OIDCcallApig(V11-HMAC-SHA256 签名 +X-Security-Token)免密上传到upload_url finally清理.api-parser-tool目录
使用方式
name: api-scan
on:
pull_request_target:
branches: [master]
permissions:
repository: read
id-token: write # 必须:OIDC 免密上传需要申请 ID Token
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 接口,生产网关) |
| tool_ref | 否 | master | api-parser 工具仓的分支/tag/commit |
| skip_install | 否 | true | 是否跳过工具自动安装(--skip-install) |
| exclude | 否 | .api-parser-tool | 排除目录,逗号分隔 |
| debug | 否 | false | 开启 OIDC SDK 调试日志(请求/响应详情,敏感字段脱敏) |
注:工具仓 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 用 |
鉴权
通过 @openlibing/huaweicloud-oidc-client(OIDC)免密上传,仓库内不存放任何 AK/SK:
- 调用方 workflow 必须声明
permissions: id-token: write(否则无法申请 OIDC ID Token); - action 运行时 Node 侧
callApig自动完成 OIDC 换证 + V11-HMAC-SHA256 签名 +X-Security-Token注入; - 前提:
upload_url对应的 APIG 接口安全认证方式需为 IAM 认证(建议新增接口,不改存量);IAM 信任委托gitcode-actions的oidc:sub需放行调用方仓库; debug: true可开启 SDK 调试日志(请求/响应详情,敏感字段自动脱敏)。
旧的
OPENLIBING_APIG_KEY/SECRET(app-key/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 直接执行。