diff --git a/biome.json b/biome.json index 0a344d06..7e539965 100644 --- a/biome.json +++ b/biome.json @@ -1,8 +1,6 @@ { "$schema": "./node_modules/@biomejs/biome/configuration_schema.json", "files": { - "include": [ - "packages/canyon-report/src" - ] + "include": ["tools/canyon-uploader/src"] } } diff --git a/tools/canyon-uploader/package.json b/tools/canyon-uploader/package.json index fa3b240c..19af74b7 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.19", + "version": "0.0.1-beta.20", "files": [ "bin", "dist" diff --git a/tools/canyon-uploader/src/commands/hit.ts b/tools/canyon-uploader/src/commands/hit.ts index 8e6899f3..be8007bf 100644 --- a/tools/canyon-uploader/src/commands/hit.ts +++ b/tools/canyon-uploader/src/commands/hit.ts @@ -3,56 +3,57 @@ import path from "node:path"; import axios from "axios"; export async function hitCommand(params, options) { - const { dsn } = params; - // console.log(dsn, projectID, sha); - - // 判断是否存在.canyon_output文件夹 - - if (!fs.existsSync(path.resolve(process.cwd(), ".canyon_output"))) { - console.error("No coverage data found in .canyon_output"); - return; - } - - const files = fs.readdirSync(path.resolve(process.cwd(), ".canyon_output")).filter((file) => file.includes("hit")); - if (files.length === 0) { - console.error("No coverage data found in .canyon_output"); - return; - } - - - -// files中的覆盖率数据是整体的,而且可能来自不同项目,所以需要分别上传 -// - - const map = {} - - for (let i = 0; i < files.length; i++) { - const fileCoverageString = fs.readFileSync( - path.resolve(process.cwd(), ".canyon_output", files[i]), - "utf-8", - ); - const data = JSON.parse(fileCoverageString); - - if (Object.values(data).length>0){ - const { sha, projectID, reportID,instrumentCwd } = data[Object.keys(data)[0]]; - if (!map[JSON.stringify({sha, projectID, reportID,instrumentCwd})]) { - map[JSON.stringify({sha, projectID, reportID,instrumentCwd})] = []; - } - map[JSON.stringify({sha, projectID, reportID,instrumentCwd})].push(data); - } - - } - // console.log(map); - return Promise.all(Object.entries(map).map( ([key, value]) => { - const {sha,projectID,instrumentCwd,reportID} = JSON.parse(key); - console.log(sha,projectID,instrumentCwd,reportID); - return axios.post(dsn, { - sha: '93c7779af32f4dd37162d59bdf4ba8b72dc9df5e', - projectID: projectID, - coverage: value[0], - instrumentCwd: instrumentCwd, - branch: "-", - reportID: reportID, - }) - })) + const { dsn } = params; + // 判断是否存在.canyon_output文件夹 + if (!fs.existsSync(path.resolve(process.cwd(), ".canyon_output"))) { + console.error("No coverage data found in .canyon_output"); + return; + } + + const files = fs + .readdirSync(path.resolve(process.cwd(), ".canyon_output")) + .filter((file) => file.includes("hit")); + if (files.length === 0) { + console.error("No coverage data found in .canyon_output"); + return; + } + + // files中的覆盖率数据是整体的,而且可能来自不同项目,所以需要分别上传 + // + + const map = {}; + + for (let i = 0; i < files.length; i++) { + const fileCoverageString = fs.readFileSync( + path.resolve(process.cwd(), ".canyon_output", files[i]), + "utf-8", + ); + const data = JSON.parse(fileCoverageString); + + if (Object.values(data).length > 0) { + const { sha, projectID, reportID, instrumentCwd } = + data[Object.keys(data)[0]]; + if (!map[JSON.stringify({ sha, projectID, reportID, instrumentCwd })]) { + map[JSON.stringify({ sha, projectID, reportID, instrumentCwd })] = []; + } + map[JSON.stringify({ sha, projectID, reportID, instrumentCwd })].push( + data, + ); + } + } + // console.log(map); + return Promise.all( + Object.entries(map).map(([key, value]) => { + const { sha, projectID, instrumentCwd, reportID } = JSON.parse(key); + console.log(sha, projectID, instrumentCwd, reportID); + return axios.post(dsn, { + sha: sha, + projectID: projectID, + instrumentCwd: instrumentCwd, + // branch: "-", + coverage: value[0], + reportID: reportID, + }); + }), + ); } diff --git a/tools/canyon-uploader/src/commands/map.ts b/tools/canyon-uploader/src/commands/map.ts index 183c325b..de82b094 100644 --- a/tools/canyon-uploader/src/commands/map.ts +++ b/tools/canyon-uploader/src/commands/map.ts @@ -3,47 +3,50 @@ import path from "node:path"; import axios from "axios"; export async function mapCommand(params, options) { - const { dsn, project_id:projectID, sha:sha,instrument_cwd:instrumentCwd } = params; - // console.log(dsn, projectID, sha); + const { + dsn, + project_id: projectID, + sha, + instrument_cwd: instrumentCwd, + } = params; + // 判断是否存在.canyon_output文件夹 + if (!fs.existsSync(path.resolve(process.cwd(), ".canyon_output"))) { + console.error("No coverage data found in .canyon_output"); + return; + } - // 判断是否存在.canyon_output文件夹 - - if (!fs.existsSync(path.resolve(process.cwd(), ".canyon_output"))) { - console.error("No coverage data found in .canyon_output"); - return; - } - - const files = fs.readdirSync(path.resolve(process.cwd(), ".canyon_output")); - if (files.length === 0) { - console.error("No coverage data found in .canyon_output"); - return; - } - 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), - }; - } - const reqData = { - projectID: projectID||process.env.CI_PROJECT_ID||process.env.GITHUB_REPOSITORY, - sha: sha||process.env.CI_COMMIT_SHA || process.env.GITHUB_SHA, - instrumentCwd: instrumentCwd || process.cwd(), - // coverage: JSON.stringify(data), - } - console.log(reqData); - await axios.post(dsn, { - projectID: projectID||process.env.CI_PROJECT_ID||process.env.GITHUB_REPOSITORY, - sha: sha||process.env.CI_COMMIT_SHA || process.env.GITHUB_SHA, - instrumentCwd: instrumentCwd || process.cwd(), - coverage: JSON.stringify(data), - }).catch((e) => { - // 打印错误 - console.log(e.message,e.name,e.errors,e.response); - return e; - }); + const files = fs.readdirSync(path.resolve(process.cwd(), ".canyon_output")); + if (files.length === 0) { + console.error("No coverage data found in .canyon_output"); + return; + } + 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), + }; + } + const reqData = { + projectID: + projectID || process.env.CI_PROJECT_ID || process.env.GITHUB_REPOSITORY, + sha: sha || process.env.CI_COMMIT_SHA || process.env.GITHUB_SHA, + instrumentCwd: instrumentCwd || process.cwd(), + coverage: Object.keys(data), + }; + console.log(reqData); + await axios + .post(dsn, { + ...reqData, + coverage: data, + }) + .catch((e) => { + // 打印错误 + console.log(e.message, e.name, e.errors, e.response); + return e; + }); } diff --git a/tools/canyon-uploader/src/main.ts b/tools/canyon-uploader/src/main.ts index 4ee1b2f5..9c5f0390 100644 --- a/tools/canyon-uploader/src/main.ts +++ b/tools/canyon-uploader/src/main.ts @@ -62,10 +62,10 @@ program */ program .command("map") - .option("--dsn ", "dsn of the canyon server") - .option("--project_id ", "id of the project") - .option("--sha ", "commit sha of the project") - .option("--instrument_cwd ", "instrument_cwd") + .option("--dsn ", "dsn of the canyon server") + .option("--project_id ", "id of the project") + .option("--sha ", "commit sha of the project") + .option("--instrument_cwd ", "instrument_cwd") .allowExcessArguments(false) .allowUnknownOption(false) .description("modify react native project code to adapt to canyon")