feat: install에서 composer update도 수행. update 기준 변경

- lock file을 git에 추가하였으므로, 이에 따름
This commit is contained in:
2022-03-13 18:56:29 +09:00
parent 42f31ce46e
commit db846c9bc2
3 changed files with 163 additions and 43 deletions
+1 -2
View File
@@ -57,12 +57,11 @@ test.*
/pya /pya
/twe /twe
/vendor
phpinfo.php phpinfo.php
vendor/ezyang/htmlpurifier/library/HTMLPurifier/DefinitionCache/*
*.sqlite3 *.sqlite3
ingame/js/* ingame/js/*
ingame/css/* ingame/css/*
gateway/js/* gateway/js/*
gateway/css/* gateway/css/*
vendor/phpunit/phpunit/.phpunit.result.cache
+82 -19
View File
@@ -3,27 +3,20 @@ namespace sammo;
set_time_limit(600); set_time_limit(600);
function tryNpmInstall() function tryComposerInstall()
{ {
$npmResultPath = 'npm_recent.json.log'; $resultPath = 'composer_result.json.log';
$packageJsonPath = 'package.json'; $lockPath = 'composer.lock';
$packageJsonLockPath = 'package-lock.json'; $runCode = "php composer.phar install";
$packageJsonHash = hash_file('sha512', $packageJsonPath);
$timestamp = time(); $timestamp = time();
if (file_exists($npmResultPath) && file_exists($packageJsonLockPath)) { if (file_exists($resultPath) && file_exists($lockPath)) {
do { do {
$result = json_decode(file_get_contents($npmResultPath)); $result = json_decode(file_get_contents($resultPath));
$oldJsonHash = $result->packageJsonHash; $oldJsonHash = $result->lockHash;
$oldTimestamp = $result->updateTimestamp; $lockHash = hash_file('sha512', $lockPath);
//1. package.json 파일이 다르면 업데이트. if ($lockHash != $oldJsonHash) {
if ($packageJsonHash != $oldJsonHash) {
break;
}
//2. package-lock.json 업데이트가 2주를 초과했다면 업데이트.
if($oldTimestamp + 60*60*24*14 < $timestamp){
break; break;
} }
@@ -32,7 +25,7 @@ function tryNpmInstall()
} while (0); } while (0);
} }
exec("npm install", $output, $result_code); exec($runCode, $output, $result_code);
if ($result_code != 0) { if ($result_code != 0) {
Json::die([ Json::die([
'result' => false, 'result' => false,
@@ -40,12 +33,76 @@ function tryNpmInstall()
]); ]);
} }
file_put_contents($npmResultPath, json_encode([ if (!file_exists($lockPath)){
'packageJsonHash'=>$packageJsonHash, Json::die([
'result' => false,
'reason' => "no lockfile: {$lockPath}"
]);
}
$lockHash = hash_file('sha512', $lockPath);
file_put_contents($resultPath, json_encode([
'lockHash'=>$lockHash,
'updateTimestamp'=>$timestamp, 'updateTimestamp'=>$timestamp,
])); ]));
return true; return true;
} }
function tryNpmInstall()
{
$resultPath = 'npm_recent.json.log';
$lockPath = 'package-lock.json';
$runCode = "npm ci";
$runAltCode = "npm install";
$timestamp = time();
if (file_exists($resultPath) && file_exists($lockPath)) {
do {
$result = json_decode(file_get_contents($resultPath));
$oldJsonHash = $result->lockHash;
$lockHash = hash_file('sha512', $lockPath);
if ($lockHash != $oldJsonHash) {
break;
}
//그것도 아니라면 업데이트하지 않겠다.
return false;
} while (0);
}
if(file_exists($lockPath)){
exec($runCode, $output, $result_code);
}
else{
exec($runAltCode, $output, $result_code);
}
if ($result_code != 0) {
Json::die([
'result' => false,
'reason' => $output
]);
}
if (!file_exists($lockPath)){
Json::die([
'result' => false,
'reason' => "no lockfile: {$lockPath}"
]);
}
$lockHash = hash_file('sha512', $lockPath);
file_put_contents($resultPath, json_encode([
'lockHash'=>$lockHash,
'updateTimestamp'=>$timestamp,
]));
return true;
}
function genJS() function genJS()
{ {
$command = "./node_modules/.bin/webpack build"; $command = "./node_modules/.bin/webpack build";
@@ -58,6 +115,12 @@ function genJS()
]); ]);
} }
} }
if(tryComposerInstall()){
header('location:install.php');
die();
}
if(tryNpmInstall()){ if(tryNpmInstall()){
genJS(); genJS();
} }
+80 -22
View File
@@ -66,27 +66,20 @@ function genJS($server)
} }
} }
function tryNpmInstall() function tryComposerInstall()
{ {
$npmResultPath = './npm_recent.json.log'; $resultPath = 'composer_result.json.log';
$packageJsonPath = './package.json'; $lockPath = 'composer.lock';
$packageJsonLockPath = './package-lock.json'; $runCode = "php composer.phar install";
$packageJsonHash = hash_file('sha512', $packageJsonPath);
$timestamp = time(); $timestamp = time();
if (file_exists($npmResultPath) && file_exists($packageJsonLockPath)) { if (file_exists($resultPath) && file_exists($lockPath)) {
do { do {
$result = json_decode(file_get_contents($npmResultPath)); $result = json_decode(file_get_contents($resultPath));
$oldJsonHash = $result->packageJsonHash; $oldJsonHash = $result->lockHash;
$oldTimestamp = $result->updateTimestamp; $lockHash = hash_file('sha512', $lockPath);
//1. package.json 파일이 다르면 업데이트. if ($lockHash != $oldJsonHash) {
if ($packageJsonHash != $oldJsonHash) {
break;
}
//2. package-lock.json 업데이트가 2주를 초과했다면 업데이트.
if ($oldTimestamp + 60 * 60 * 24 * 14 < $timestamp) {
break; break;
} }
@@ -95,7 +88,7 @@ function tryNpmInstall()
} while (0); } while (0);
} }
exec("npm install", $output, $result_code); exec($runCode, $output, $result_code);
if ($result_code != 0) { if ($result_code != 0) {
Json::die([ Json::die([
'result' => false, 'result' => false,
@@ -103,16 +96,80 @@ function tryNpmInstall()
]); ]);
} }
file_put_contents($npmResultPath, json_encode([ if (!file_exists($lockPath)){
'packageJsonHash' => $packageJsonHash, Json::die([
'updateTimestamp' => $timestamp, 'result' => false,
'reason' => "no lockfile: {$lockPath}"
]);
}
$lockHash = hash_file('sha512', $lockPath);
file_put_contents($resultPath, json_encode([
'lockHash'=>$lockHash,
'updateTimestamp'=>$timestamp,
])); ]));
return true; return true;
} }
//묻고 따지지 않고 일단 npm install은 시도한다.
function tryNpmInstall()
{
$resultPath = 'npm_recent.json.log';
$lockPath = 'package-lock.json';
$runCode = "npm ci";
$runAltCode = "npm install";
$timestamp = time();
if (file_exists($resultPath) && file_exists($lockPath)) {
do {
$result = json_decode(file_get_contents($resultPath));
$oldJsonHash = $result->lockHash;
$lockHash = hash_file('sha512', $lockPath);
if ($lockHash != $oldJsonHash) {
break;
}
//그것도 아니라면 업데이트하지 않겠다.
return false;
} while (0);
}
if(file_exists($lockPath)){
exec($runCode, $output, $result_code);
}
else{
exec($runAltCode, $output, $result_code);
}
if ($result_code != 0) {
Json::die([
'result' => false,
'reason' => $output
]);
}
if (!file_exists($lockPath)){
Json::die([
'result' => false,
'reason' => "no lockfile: {$lockPath}"
]);
}
$lockHash = hash_file('sha512', $lockPath);
file_put_contents($resultPath, json_encode([
'lockHash'=>$lockHash,
'updateTimestamp'=>$timestamp,
]));
return true;
}
//묻고 따지지 않고 일단 composer install, npm install은 시도한다.
//hwe 업데이트인 경우에만 한번 더 부른다. //hwe 업데이트인 경우에만 한번 더 부른다.
tryComposerInstall();
if (tryNpmInstall()) { if (tryNpmInstall()) {
genJS(Util::array_last_key(ServConfig::getServerList())); genJS(Util::array_last_key(ServConfig::getServerList()));
} }
@@ -268,7 +325,8 @@ if ($server == $baseServerName) {
])); ]));
} }
//git 업데이트했는데, package.json이 바뀌면 곤란하니까 //git 업데이트했는데, package 바뀌면 곤란하니까
tryComposerInstall();
tryNpmInstall(); tryNpmInstall();
genJS($server); genJS($server);