首页 > 解决方案 > 将包含 JSON 文件的 GitHub Actions 工件发布到 New Relic

问题描述

我的 GitHub Actions 构建创建了一个包含单个 JSON 文件的工件。

此 JSON 包含我的 Mochawesome 报告,用于完整的测试套件运行。

然后我想将此 JSON 发布到 New Relic 并最终为测试结果数据创建一个仪表板。

如何将此 JSON 从 GH 发布到 New Relic?

以 POSTMAN 为例:

curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/{owner}/{repo}/actions/artifacts/{id}

我得到了工件摘要,但没有得到 JSON 内容。

{
    "id": 85840686,
    "node_id": "MDg6QXJ0aWsomestuffg0MDY4Ng==",
    "name": "prod-json-report",
    "size_in_bytes": 5443,
    "url": "https://api.github.com/repos/{owner}/{repo}/actions/artifacts/85840686",
    "archive_download_url": "https://api.github.com/repos/{owner}/{repo}/actions/artifacts/85840686/zip",
    "expired": false,
    "created_at": "2021-08-23T18:04:56Z",
    "updated_at": "2021-08-23T18:04:56Z",
    "expires_at": "2021-09-22T18:04:52Z"
}

我假设我需要一个使用 Curl 的 GH 工作流步骤来发布 JSON,但这是我不明白如何配置的部分。

示例 JSON:

{
  "stats": {
    "suites": 66,
    "tests": 455,
    "passes": 448,
    "pending": 2,
    "failures": 2,
    "start": "2021-08-23T06:09:42.525Z",
    "end": "2021-08-23T07:08:45.761Z",
    "duration": 1497027,
    "testsRegistered": 455,
    "passPercent": 98.46153846153847,
    "pendingPercent": 0.43956043956043955,
    "other": 0,
    "hasOther": false,
    "skipped": 3,
    "hasSkipped": true
  },
  "results": [
    {
      "uuid": "44ce07ae-some-stuff-31327565d944",
      "title": "",
      "fullFile": "cypress/integration/accessibility/axe.spec.ts",
      "file": "cypress/integration/accessibility/axe.spec.ts",
      "beforeHooks": [],
      "afterHooks": [],
      "tests": [],
      "suites": [
        {
          "uuid": "65d39437-some-stuff-1e9a6564977b",
          "title": "Accessibility violations",
          "fullFile": "",
          "file": "",
          "beforeHooks": [],
          "afterHooks": [],
          "tests": [
            {
              "title": "Verify pages within URL path",
              "fullTitle": "Accessibility violations Verify pages within URL path",
              "timedOut": null,
              "duration": 24895,
              "state": "passed",
              "speed": "slow",
              "pass": true,
              "fail": false,
              "pending": false,
              "context": null,
              "code": "cy.get('@navItems').then((urls) => {\n    urls.dotCom.urlPathOurCompany.forEach((url) => {\n        cy.authVisit(url);\n        cy.injectAxe();\n        cy.checkAxeViolations();\n    });\n});",
              "err": {},
              "uuid": "02521245-some-stuff-3b89706e9a1b",
              "parentUUID": "65d39437-some-stuff-1e9a6564977b",
              "isHook": false,
              "skipped": false
            },
...

标签: jsonapigithubnewrelic

解决方案


推荐阅读