├── .gitignore ├── README.md ├── package.json └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # open-source4 laylo laydsadsa 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webhook", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index.js" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "body-parser": "^2.2.0", 14 | "child_process": "^1.0.2", 15 | "express": "^5.1.0" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // webhook.js 2 | const express = require('express'); 3 | const bodyParser = require('body-parser'); 4 | const { exec } = require('child_process'); 5 | const app = express(); 6 | const PORT = 3088; 7 | 8 | app.use(bodyParser.json()); 9 | 10 | app.post('/github-webhook', (req, res) => { 11 | const payload = req.body; 12 | 13 | if (payload.ref === 'refs/heads/main') { 14 | res.status(200).send('Webhook received. Deploying...'); 15 | 16 | // Loyihangiz joylashgan katalog 17 | const projectDir = '/home/root/kurslar-algoritmedu'; 18 | 19 | // Ketma-ket buyruqlar 20 | const commands = ` 21 | cd ${projectDir} && 22 | git pull && 23 | npm install && 24 | npm run build && 25 | rm -rf /var/www/kurslar-algoritmedu/* && 26 | cp -r dist/* /var/www/kurslar-algoritmedu/ 27 | `; 28 | 29 | exec(commands, (err, stdout, stderr) => { 30 | if (err) { 31 | console.error(`Xatolik yuz berdi:\n${stderr}`); 32 | return; 33 | } 34 | console.log(`Muvaffaqiyatli:\n${stdout}`); 35 | }); 36 | } else { 37 | res.status(200).send('Boshqa branch — hech narsa qilinmadi.'); 38 | } 39 | }); 40 | 41 | app.listen(PORT, () => { 42 | console.log(`Webhook server ${PORT}-portda ishlayapti`); 43 | }); 44 | --------------------------------------------------------------------------------