Skip to content

Commit

Permalink
chore: repo overall update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtao25 committed Nov 19, 2024
1 parent c267c50 commit 4d838d9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
9 changes: 8 additions & 1 deletion plugins/babel-plugin-canyon/src/helpers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,12 @@ export function walkProviders(inputs: UploaderInputs): IServiceParams {
return provider.getServiceParams(inputs)
}
}
throw new Error(`Unable to detect provider.`)
// 返回默认值
return {
projectID: '-',
sha: '-',
instrumentCwd: '-',
branch: '-',
}
// throw new Error(`Unable to detect provider.`)
}
4 changes: 3 additions & 1 deletion plugins/babel-plugin-canyon/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export default declare((api, config) => {
exit: (path) => {
// 侦测流水线
// 优先级:手动设置 > CI/CD提供商
// hit需要打到__coverage__中,因为ui自动化测试工具部署地方不确定
// map就不需要,写到本地时,可以侦测本地流水线变量,直接上报上来
const serviceParams = detectProvider({
envs: process.env,
args: {
Expand All @@ -23,7 +25,7 @@ export default declare((api, config) => {
}
})
console.log(serviceParams,'serviceParams')
visitorProgramExit(api,path)
visitorProgramExit(api,path,serviceParams)
}
},
},
Expand Down
9 changes: 5 additions & 4 deletions plugins/babel-plugin-canyon/src/visitor-program-exit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {generateInitialCoverage} from "./helpers/generate-initial-coverage";
import generate from "@babel/generator";

export const visitorProgramExit = (api,path) => {
// 关键参数 serviceParams ,它由 detectProvider 函数返回,手动设置的参数优先级高于 CI/CD 提供商
export const visitorProgramExit = (api,path,serviceParams) => {
// 生成初始覆盖率数据
generateInitialCoverage(generate(path.node).code)
if (generate(path.node).code.includes('coverageData')) {
Expand Down Expand Up @@ -41,19 +42,19 @@ export const visitorProgramExit = (api,path) => {
// 增加 sha 字段
const shaField = t.objectProperty(
t.identifier("sha"), // 键名
t.stringLiteral('__canyon__.COMMIT_SHA') // 键值
t.stringLiteral(serviceParams.sha) // 键值
);
properties.push(shaField); // 添加新字段
// 增加 sha 字段
const projectIDField = t.objectProperty(
t.identifier("projectID"), // 键名
t.stringLiteral('__canyon__.PROJECT_ID') // 键值
t.stringLiteral(serviceParams.projectID) // 键值
);
properties.push(projectIDField); // 添加新字段
// 增加 sha 字段
const instrumentCwdField = t.objectProperty(
t.identifier("instrumentCwd"), // 键名
t.stringLiteral('__canyon__.INSTRUMENT_CWD') // 键值
t.stringLiteral(serviceParams.instrumentCwd) // 键值
);
properties.push(instrumentCwdField); // 添加新字段
}
Expand Down

0 comments on commit 4d838d9

Please sign in to comment.