From 31f326917e11cd8b79adb1489602d9a01504db2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Allen=20Zhang=20=28=E5=BC=A0=E6=B6=9B=29?= Date: Mon, 11 Nov 2024 19:52:31 +0800 Subject: [PATCH] feat(canyon-uploader): update --- tools/canyon-uploader/package.json | 2 +- tools/canyon-uploader/src/commands/hit.ts | 4 ++-- tools/canyon-uploader/src/commands/map.ts | 25 ++++++++++++++++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/tools/canyon-uploader/package.json b/tools/canyon-uploader/package.json index d81c56e2..677006cf 100644 --- a/tools/canyon-uploader/package.json +++ b/tools/canyon-uploader/package.json @@ -1,6 +1,6 @@ { "name": "canyon-uploader", - "version": "0.0.1-beta.5", + "version": "0.0.1-beta.6", "files": [ "bin", "dist" diff --git a/tools/canyon-uploader/src/commands/hit.ts b/tools/canyon-uploader/src/commands/hit.ts index e199daee..1e2364a2 100644 --- a/tools/canyon-uploader/src/commands/hit.ts +++ b/tools/canyon-uploader/src/commands/hit.ts @@ -3,7 +3,7 @@ import path from "node:path"; import * as process from "node:process"; import axios from "axios"; export async function hitCommand(params, options) { - const { dsn, project_id:projectID, commit_sha:sha } = options; + const { dsn, project_id:projectID, commit_sha:sha } = params; const files = fs.readdirSync(path.resolve(process.cwd(), ".canyon_output")); let data = {}; for (let i = 0; i < files.length; i++) { @@ -22,5 +22,5 @@ export async function hitCommand(params, options) { sha, instrumentCwd: process.cwd(), coverage: JSON.stringify(data), - }, {}); + }); } diff --git a/tools/canyon-uploader/src/commands/map.ts b/tools/canyon-uploader/src/commands/map.ts index c14f78f0..d781a536 100644 --- a/tools/canyon-uploader/src/commands/map.ts +++ b/tools/canyon-uploader/src/commands/map.ts @@ -1,3 +1,26 @@ +import fs from "node:fs"; +import path from "node:path"; +import * as process from "node:process"; +import axios from "axios"; export async function mapCommand(params, options) { - console.log("mapCommand", "mapCommand"); + const { dsn, project_id:projectID, commit_sha:sha } = params; + console.log(dsn, projectID, sha); + const files = fs.readdirSync(path.resolve(process.cwd(), ".canyon_output")); + let data = {}; + for (let i = 0; i < files.length; i++) { + const fileCoverageString = fs.readFileSync( + path.resolve(process.cwd(), ".canyon_output", files[i]), + "utf-8", + ); + data = { + ...data, + ...JSON.parse(fileCoverageString), + }; + } + await axios.post(dsn, { + projectID: projectID||process.env.CI_COMMIT_SHA, + sha: sha||process.env.CI_PROJECT_ID, + instrumentCwd: process.cwd(), + coverage: JSON.stringify(data), + }); }