change_after.js 815 B

12345678910111213141516171819202122232425
  1. const fs = require('fs');
  2. module.exports = function(){
  3. return
  4. console.log('开始执行脚本change_after');
  5. let changelog = fs.readFileSync(process.cwd() + '/changelog.md', 'utf-8').split("##")[1].split("\n").slice(1).join(' ');
  6. console.log(changelog);
  7. // 这里是修改完相关敏感配置后执行的脚本,你可以在这里自定义逻辑,
  8. // 比如执行git提交命令
  9. var shell = require("shelljs");
  10. var exec = shell.exec;
  11. if (exec('git add .').code !== 0) {
  12. shell.echo('Error: Git add failed');
  13. shell.exit(1);
  14. }
  15. if (exec(`git commit -a -m "${changelog}"`).code !== 0) {
  16. shell.echo('Error: Git commit failed');
  17. shell.exit(1);
  18. }
  19. if (exec('git push').code !== 0) {
  20. shell.echo('Error: Git commit failed');
  21. shell.exit(1);
  22. }
  23. shell.exec(`echo git success ${changelog}`);
  24. }