当前位置:网站首页>Use nodejs to determine which projects are packaged + released
Use nodejs to determine which projects are packaged + released
2022-07-07 01:35:00 【Ah Liu】
Because the codes of many of my systems are in one folder , You can only modify the code of one of the systems , But four of them are published
So the use of nodejs Complete this requirement
git fetch Remote access to the code base ci Merge requested ⽬ Standard score ⽀ name .
git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
git diff Judge the difference
git diff --name-only $CI_COMMIT_BEFORE_SHA origin/master | awk -F/ '{print $1}' | sort -u
Subprocess running shell Script
https://blog.csdn.net/cindy647/article/details/108830841
child_process:node A subprocess of api, You can create a sub process to execute commands
// call util.promisify Method , Return to one promise, Such as const { stdout, stderr } = await exec(‘rm -rf build’)
const runShell = async (command, exitShellByMsg = false) => {
const exec = util.promisify(child_process.exec); //
let shell = await exec(command);
let data = '';
return new Promise((resolve, reject) => {
data = shell.stdout;
if ((exitShellByMsg && shell.stdout.indexOf('shell exit') > 0) || !exitShellByMsg) {
resolve(data);
}
});
};
Get command line parameters
process.argv[2]
The complete code is as follows
const util = require('util');
const child_process = require('child_process'); // Used to run the shell command
const projects = ['ishmael','isaac','hagar','sarai'];
const env = process.env;
const runShell = async (command, exitShellByMsg = false) => {
const exec = util.promisify(child_process.exec);
let shell = await exec(command);
let data = '';
return new Promise((resolve, reject) => {
data = shell.stdout;
if ((exitShellByMsg && shell.stdout.indexOf('shell exit') > 0) || !exitShellByMsg) {
resolve(data);
}
});
};
const diffChange = async () => {
await runShell("git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME"); // git fetch Remote access to the code base ci Merge requested ⽬ Standard score ⽀ name .
const data = await runShell("git diff --name-only $CI_COMMIT_BEFORE_SHA origin/master | awk -F/ '{print $1}' | sort -u");
const diffs = data.trim().replace(/\n/g, ',').split(',');
const isNeedBuildAll = diffs.some(name => name && projects.indexOf(name) < 0); // If the folder name is not projects in , Prove to be a shared folder , It needs to be all build
console.info('change files', diffs);
return isNeedBuildAll ? projects : projects.filter(name => {
return name && diffs.indexOf(name) > -1;
});
};
const buildChanges = async (names) => {
if (!names.length) {
console.info('no changes to build');
return;
}
let index = 0;
const build = async () => {
const name = names[index];
console.log("project--------name-------building",name)
// runShell I got a Promise object
await runShell(`./build.sh ${
name} ${
env.CI_COMMIT_SHORT_SHA}`, true)
console.log("project--------name-------buildEnd",name)
index++;
if (index <= names.length - 1) {
await build();
}
};
return build();
};
const deployChanges = async (names) => {
if (!names.length) {
console.info('no changes to deploy');
return;
}
let index = 0;
const deploy = async () => {
const name = names[index];
const envName = process.argv[2] || 'TEST'; // Project name
const prefix = `${
envName}_${
name.toUpperCase()}_SERVER`; // TEST_ Project name _SERVER_xx || PRODUCT_ Project name _SERVER_xxx
const server = env[`${
prefix}_NAME`]; // Server name
const serverPWD = env[`${
prefix}_PWD`]; // Server password
const serverPath = env[`${
prefix}_PATH`]; // Server path
if (server) {
await runShell(`./script/ci-deploy.sh ${
name} ${
server} ${
serverPWD} ${
serverPath}`, true);
}
index++;
if (index <= names.length - 1) {
await deploy();
}
};
return deploy();
};
const main = async () => {
const buildProjectNames = process.argv[2] === 'TEST' ? await diffChange() : projects;
const projectNames = buildProjectNames.join('、');
console.info(`${
projectNames} prepare build`);
await buildChanges(buildProjectNames);
console.info(`${
projectNames} build done`);
await deployChanges(buildProjectNames);
console.info(`${
projectNames} deploy done`);
};
main();
边栏推荐
猜你喜欢

2022 Google CTF SEGFAULT LABYRINTH wp

Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which

鼠标右键 自定义

The MySQL database in Alibaba cloud was attacked, and finally the data was found

AcWing 1148. 秘密的牛奶运输 题解(最小生成树)

设置Wordpress伪静态连接(无宝塔)

Dark horse notes - exception handling
![[signal and system]](/img/aa/a65d6da1d1d9410254ca7b775e24a6.png)
[signal and system]

云呐|工单管理软件,工单管理软件APP

Go zero micro service practical series (IX. ultimate optimization of seckill performance)
随机推荐
Neon Optimization: an optimization case of log10 function
今日问题-2022/7/4 lambda体中修改String引用类型变量
增加 pdf 标题浮窗
Send template message via wechat official account
Neon Optimization: performance optimization FAQ QA
json学习初体验–第三者jar包实现bean、List、map创json格式
系统休眠文件可以删除吗 系统休眠文件怎么删除
Installation and testing of pyflink
Installation of gazebo & connection with ROS
C语言实例_4
Start from the bottom structure to learn the customization and testing of fpga---- FIFO IP
C language instance_ three
Yunna | work order management measures, how to carry out work order management
C language instance_ four
THREE. AxesHelper is not a constructor
Taro applet enables wxml code compression
C language instance_ five
Set up [redis in centos7.x]
安全保护能力是什么意思?等保不同级别保护能力分别是怎样?
Add the applet "lazycodeloading": "requiredcomponents" in taro,