Skip to content

Commit

Permalink
feat: 优化mp-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
novlan1 committed Oct 18, 2022
1 parent ed89c09 commit cf629db
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,6 @@ repo/

ignore-tmp-data/
.npmrc

/mp_ci_preview_destination.png

30 changes: 24 additions & 6 deletions src/mp-ci/mp-ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class MpCI {
cosInfo: any;
commitInfo: any;
buildDesc: string;
buildTime: string;
buildTime?: string;
version: string;

/**
Expand All @@ -48,7 +48,7 @@ export class MpCI {

this.options = options;
this.projectCI = null;
this.savePreviewPath = path.resolve(process.cwd(), 'preview_destination.png');
this.savePreviewPath = path.resolve(process.cwd(), 'mp_ci_preview_destination.png');
const {
appId,
appName,
Expand Down Expand Up @@ -108,9 +108,10 @@ export class MpCI {
}

this.init();
this.getBuildTime();

this.commitInfo = getGitCommitInfo(this.root);
this.buildDesc = this.getBuildDesc() || '';
this.buildTime = timeStampFormat(Date.now(), 'yyyy-MM-dd hh:mm:ss');
this.version = this.getVersion();
}

Expand All @@ -126,6 +127,10 @@ export class MpCI {
});
}

getBuildTime() {
return timeStampFormat(Date.now(), 'yyyy-MM-dd hh:mm:ss');
}

getPkgInfo() {
return require(this.pkgFile) || {};
}
Expand All @@ -136,7 +141,7 @@ export class MpCI {

getBuildDesc() {
const { env, commitInfo } = this;
const buildDesc = `环境:${env || ''},分支:${commitInfo.branch}Last Commit${commitInfo.author} - ${commitInfo.message}`;
const buildDesc = `环境:${env || ''},分支:${commitInfo.branch}提交${commitInfo.author} - ${commitInfo.message}`;
return buildDesc;
}

Expand All @@ -153,6 +158,7 @@ export class MpCI {
robot: robotNumber,
setting: this.buildSetting,
});
this.getBuildTime();
console.log('UploadResult:\n', uploadResult);
}

Expand Down Expand Up @@ -185,7 +191,7 @@ export class MpCI {
`版本: ${version}, 提交者: CI机器人${robotNumber}, 环境: ${env}`,
`分支: ${commitInfo.branch}`,
`提交时间: ${buildTime}`,
`Commit: ${commitInfo.author} - ${commitInfo.message}`,
`提交信息: ${commitInfo.author} - ${commitInfo.message}`,
].map((item) => {
if (item.length > 35) return `${item.slice(0, 35)}...`;
return item;
Expand All @@ -204,12 +210,23 @@ export class MpCI {
});
this.uploadFiles([
{
key: `${this.cosInfo.dir}/${commitInfo.branch.replace(/\//g, '-')}_${env}.png`,
key: this.getCosKey(),
path: this.savePreviewPath,
},
]);
}

getCosKey() {
const { cosInfo, env, commitInfo } = this;
return `${cosInfo.dir}/${commitInfo.branch.replace(/\//g, '-')}_${env}.png`;
}

getCOSFilePath() {
const { bucket, region } = this.cosInfo;
const cosKey = this.getCosKey();
return `https://${bucket}.cos.${region}.myqcloud.com/${cosKey}`;
}

/**
* 发送机器人消息
*/
Expand All @@ -228,6 +245,7 @@ export class MpCI {
`提交者:CI机器人${robotNumber}`,
buildDesc,
`提交时间:${buildTime || ''}`,
`[COS链接](${this.getCOSFilePath()})`,
];

const template = `>【构建成功】${descList.join(',')}`;
Expand Down

0 comments on commit cf629db

Please sign in to comment.