当前位置:网站首页>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();
边栏推荐
- swiper组件中使用video导致全屏错位
- LeetCode:1175. Prime permutation
- Install Firefox browser on raspberry pie /arm device
- Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform
- C # method of calculating lunar calendar date 2022
- Installation of gazebo & connection with ROS
- 对C语言数组的再认识
- docker 方法安装mysql
- Js逆向——捅了【马蜂窝】的ob混淆与加速乐
- 【信号与系统】
猜你喜欢
2022 Google CTF SEGFAULT LABYRINTH wp
LeetCode:1175. 质数排列
go-zero微服务实战系列(九、极致优化秒杀性能)
Wood extraction in Halcon
子网划分、构造超网 典型题
LeetCode. 剑指offer 62. 圆圈中最后剩下的数
405 method not allowed appears when the third party jumps to the website
JTAG principle of arm bare board debugging
How to manage distributed teams?
[advanced C language] 8 written questions of pointer
随机推荐
golang 基础 —— 数据类型
ClickHouse字段分组聚合、按照任意时间段粒度查询SQL
Taro中添加小程序 “lazyCodeLoading“: “requiredComponents“,
Wood extraction in Halcon
子网划分、构造超网 典型题
云呐-工单管理制度及流程,工单管理规范
C语言实例_4
The difference between Tansig and logsig. Why does BP like to use Tansig
C语言实例_3
Can the system hibernation file be deleted? How to delete the system hibernation file
从零开始匹配vim(0)——vimscript 简介
AcWing 346. 走廊泼水节 题解(推公式、最小生成树)
2022 Google CTF SEGFAULT LABYRINTH wp
前置机是什么意思?主要作用是什么?与堡垒机有什么区别?
Match VIM from zero (0) -- Introduction to vimscript
Taro 小程序开启wxml代码压缩
Today's question -2022/7/4 modify string reference type variables in lambda body
json学习初体验–第三者jar包实现bean、List、map创json格式
curl 命令
table表格设置圆角