文件最后提交记录最后更新时间
24 天前
1 个月前
1 个月前
1 个月前
1 个月前
1 个月前
1 个月前
1 个月前
README

metadata-collect

核心特性(Features)

  • 自动环境管理:在随机临时目录中创建 Python 虚拟环境,执行结束后自动清理,不污染工作区。
  • 依赖自动安装:从 GitCode release 下载 pytest-testcase-collector wheel 并安装,无需手工准备。
  • 一键收集:执行 pytest --collect-only --metadata-output <file>,产出 XML 格式的用例全集元数据报告。
  • 灵活输入:支持按用例目录(testcase-path)、pytest 配置文件(pytest-config-file)、rootdir 覆盖三种方式指定收集范围。
  • 安全路径校验:所有路径限制在工作区内,禁止路径遍历(..)与符号链接逃逸。

快速上手(Quick Start)

在仓库根目录创建 .gitcode/workflows/collect-metadata.yml,内容如下:

name: collect-metadata

on: push

jobs:
  collect:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Collect metadata
        id: collect
        uses: openlibing/test-action/metadata-collect@v1.0.2
        with:
          testcase-path: tests

收集 metadata 信息的完整示例 workflow。

  • 运行时:node16(GitCode 平台限制)
  • uses 路径:openlibing/test-action/metadata-collect@<tag>(下文示例统一使用 @v1.0.2,请按最新标签替换)

输入参数(Inputs)

参数 必填 默认值 说明
testcase-path 否 '' 测试用例目录路径。指定 pytest-config-file 且由其 testpaths 决定收集范围时可省略
metadata-output-path 否 metadata_test.xml XML 输出文件路径,文件名必须以 metadata 开头;并发场景请指定不同路径以避免覆盖
pytest-config-file 否 - pytest 配置文件路径(如 pytest.ini),指定后由配置中的 testpaths 自动收集
rootdir 否 '' pytest rootdir 覆盖路径,作为 testpaths 与相对路径的解析基准

输出参数(Outputs)

参数 类型 说明
metadata-output-path string 生成的 XML 文件绝对路径

如何使用输出参数

通过 steps.<id>.outputs.<参数名> 引用输出。典型场景:将收集到的元数据 XML 传给下游 upload-reports 插件上传归档。

- name: Collect metadata
  id: collect
  uses: openlibing/test-action/metadata-collect@v1.0.2
  with:
    testcase-path: tests

- name: Show output
  run: echo "metadata file at ${{ steps.collect.outputs.metadata-output-path }}"

使用约束

  • testcase-path 与 pytest-config-file 至少指定其一,否则执行失败。
  • 输出文件名必须以 metadata 开头(由 validateOutputPath 校验)。
  • 所有路径须位于工作区内,禁止路径遍历(..)与符号链接逃逸。
  • 镜像源可通过环境变量 PYPI_INDEX_URL 覆盖:必须 HTTPS,且主机须在白名单内:pypi.org、files.pythonhosted.org、mirrors.huaweicloud.com、mirrors.aliyun.com、pypi.tuna.tsinghua.edu.cn、mirrors.cloud.tencent.com。

环境变量依赖

本插件不依赖额外的 ATOMGIT_* 环境变量;如使用自定义 PyPI 镜像源,可通过环境变量 PYPI_INDEX_URL 覆盖(约束见"使用约束")。

上下游串联

下游 upload-reports 插件可将收集到的元数据 XML 上传至 OpenLibing OBS 归档。

jobs:
  collect-and-upload:
    runs-on: ubuntu-latest
    permissions:
      id-token: write # upload-reports 需要 OIDC 联邦认证
    steps:
      - uses: actions/checkout@v4

      - name: Collect metadata
        id: collect
        uses: openlibing/test-action/metadata-collect@v1.0.2
        with:
          testcase-path: tests

      - name: Upload metadata
        uses: openlibing/test-action/upload-reports@v2.0.0
        with:
          files: ${{ steps.collect.outputs.metadata-output-path }}
          label: smoke

贡献与本地调试

  1. Fork 本仓库并 clone 到本地。
  2. 进入插件目录:cd metadata-collect。
  3. 安装依赖:npm install。
  4. 构建产物:npm run build(或 npm run package,视 package.json 而定)。
  5. 本地调试:通过单元测试或 mock 输入验证逻辑;提交前确保 dist/index.js 已重新构建。
  6. 提交 Pull Request。

开源协议(License)

本项目基于 MIT License 开源。