api-scan-action:基于 GitCode Actions 的接口兼容性扫描项目

openlibing流水线代码化:接口兼容性扫描action插件

Branch8Tags3
FilesLast commitLast update
17 hours ago
13 days ago
13 days ago
13 days ago
2 months ago
2 months ago
29 days ago
29 days ago
2 months ago
2 months ago
2 months ago

api-scan-action

API-Scan 接口兼容性扫描插件,克隆 openlibing-api-parser 工具仓并执行接口扫描,结果上传到 openLiBing 平台,用于 PR 门禁阶段的接口兼容性检测。

工作流程

  1. git clone 接口解析与扫描引擎仓 openlibing/openlibing-api-parser(分支由 tool_ref 指定)到 ${WORKSPACE}/.api-parser-tool
  2. chmod 三个可执行:scripts/openlibing_scan.sh、cli.py、tools/api_analysis/linux-x86_64-ubuntu22-llvm15/api_analysis
  3. pip3 install -r requirements.txt(清华源加速)
  4. 执行 bash openlibing_scan.sh,带 --source/--exclude/--output 参数产出 results.json(不再带 --upload)
  5. Node action 读取 results.json,经 OIDC callApig(V11-HMAC-SHA256 签名 + X-Security-Token)免密上传到 upload_url
  6. 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 直接执行。

Introduction

openlibing流水线代码化:接口兼容性扫描action插件

Customize your domain