start modularisation
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
# https://docs.gitea.com/usage/webhooks
|
||||
// https://docs.gitea.com/usage/webhooks
|
||||
|
||||
// check for POST request
|
||||
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
|
||||
@@ -33,7 +33,38 @@ if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
}
|
||||
|
||||
// success, do something
|
||||
$repo_name = $decoded['repository']['name'];
|
||||
echo "launching hook script ";
|
||||
echo shell_exec('bash ../webhook/webhook.sh ' . $repo_name . ' >> ../webhook/webhook.log 2>&1');
|
||||
?>
|
||||
$current_date = date('d-m-y_H-i-s', time());
|
||||
$log_directory = '../webhook/logs';
|
||||
|
||||
// create the log folder if needed
|
||||
if (!file_exists($log_directory)) {
|
||||
mkdir($log_directory, 0777, true);
|
||||
}
|
||||
|
||||
// clean the log folder if needed
|
||||
if (count(scandir($log_directory)) > 10) {
|
||||
$files = scandir($log_directory);
|
||||
$log_files = array_diff($files, array('.', '..'));
|
||||
usort($files, function($a, $b) use ($log_directory) {
|
||||
return filemtime("$log_directory/$a") - filemtime("$log_directory/$b");
|
||||
});
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
unlink("$log_directory/{$files[$i]}");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($decoded['repository'])) {
|
||||
// git hook
|
||||
echo shell_exec('bash ../webhook/webhook.sh ' . 'git' . ' >> ' . $log_directory . '/webhook_' . $current_date . '.log 2>&1');
|
||||
} else {
|
||||
// directus hook
|
||||
$debounce_delay = 1 * 60;
|
||||
file_put_contents("debounce_hook", time());
|
||||
sleep($debounce_delay);
|
||||
|
||||
if (time() >= intval(file_get_contents('debounce_hook')) + $debounce_delay) {
|
||||
|
||||
echo shell_exec('bash ../webhook/webhook.sh ' . 'directus' . ' >> ' . $log_directory . '/webhook_' . $current_date . '.log 2>&1');
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -1,17 +1,19 @@
|
||||
#!/bin/bash
|
||||
repo_name=$1
|
||||
cms_dir=$(ls -d /var/www/repositories/cms*/)
|
||||
|
||||
tmux send-keys -t directus C-c
|
||||
tmux send-keys -t front C-c
|
||||
hook_origin=$1
|
||||
repo_name=$(ls /var/www/repositories/ | grep -v '^cms')
|
||||
|
||||
cd /var/www/repositories/$repo_name
|
||||
git pull origin prod
|
||||
|
||||
echo "Trigger : ${hook_origin}"
|
||||
|
||||
if [[ "$hook_origin" == "git" ]]; then
|
||||
git pull origin prod
|
||||
fi
|
||||
|
||||
jq '.scripts |= with_entries(.value |= gsub("\\bnuxt \\b"; "./node_modules/nuxt/bin/nuxt.mjs "))' package.json > temp.json && mv temp.json package.json
|
||||
|
||||
NUXT_TELEMETRY_DISABLED=1 ; npm install -y
|
||||
npm run build
|
||||
node --max-old-space-size=250 `which npm` install -y
|
||||
node --max-old-space-size=250 `which npm` run generate --prerender
|
||||
|
||||
tmux send-keys -t front "cd /var/www/repositories/${repo_name} && node .output/server/index.mjs" C-m
|
||||
tmux send-keys -t directus "cd ${cms_dir} && npx directus start" C-m
|
||||
rm -r /var/www/html/public
|
||||
cp -r "/var/www/repositories/${repo_name}/.output/public" /var/www/html
|
Reference in New Issue
Block a user