내 node
(Express
) 응용 프로그램에서 실행되는 원격 베어 자식의 repo를 설정 괜찮은 runthrough입니다 forever
, 그래서 기본적으로않는 다음과 같은 처리기를 사용하여그리고 스스로를 죽이기 때문에 (따라서 재 스폰됨). 이제
function handleGitHub(req, res, next) {
setTimeout(function() {
var shouldRestart = !app.config.webhook || req.body.head_commit.message.indexOf(app.config.webhook) > -1;
console.log('[GITHUB] WebHook Received for "%s" (WebHook: %s, Restart? %s)', req.body && req.body.head_commit.message, app.config.webhook && app.config.webhook, shouldRestart);
if (!shouldRestart) {
console.log('[GITHUB] Not restarting');
return;
}
if (app.server_https && app.server_https.close) {
console.log('[GITHUB] Closing HTTPS');
app.server_https.close();
}
if (app.server && app.server.close) {
console.log('[GITHUB] Closing HTTP');
app.server.close();
}
setTimeout(function() {
var spawn = require('child_process').spawn;
var shell = process.env.SHELL;
var args = ['-c', 'git pull'];
var path = require('path');
var projectPath = '/path/to/your/project/folder'; //or path.join(__dirname, '....
var opts = { cwd: projectPath };
console.log('[GITHUB] Spawning...', opts);
var spawnProcess = spawn(shell, args, opts);
spawnProcess.stdout.on('data', function(data) {
// could log these
});
spawnProcess.stderr.on('data', function(data) {
// could log these
});
spawnProcess.on('close', function(exitCode) {
console.log('[GITHUB] Spawn finished', exitCode);
console.log('[GITHUB] Exiting...');
console.log('-------------------------------------------------------');
process.exit(0);
});
}, 1000);
}, 500);
res.send(200, 'OK');
}
, 바로이 기능을 가리키는 경로를 사용 : 당신은 설정 할 수
app.post('/some_path_you_setup_in_github_web_hooks', handleGitHub);
을 https://github.com/your_username/your_project/settings/hooks
에 푸시 훅