2022-08-26 15:36:01 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$user = getenv('GITEA_USER');
|
|
|
|
$pass = getenv('GITEA_PASS');
|
|
|
|
|
|
|
|
$gitea_url = 'https://git.bit5.ru';
|
|
|
|
|
|
|
|
$auth_token = gitea_login($gitea_url, $user, $pass);
|
|
|
|
if(!$auth_token)
|
|
|
|
throw new Exception("Could not login to gitea");
|
|
|
|
|
2022-08-29 14:18:09 +03:00
|
|
|
gitea_check_repo($auth_token, $gitea_url, 'bit/skeletik',
|
2022-08-29 10:58:15 +03:00
|
|
|
array(
|
|
|
|
'check_forks' => true,
|
|
|
|
'check_composer' => true,
|
|
|
|
'check_upm' => false
|
|
|
|
)
|
|
|
|
);
|
2022-08-29 14:18:09 +03:00
|
|
|
gitea_check_repo($auth_token, $gitea_url, 'bit/skeletor',
|
2022-08-29 10:58:15 +03:00
|
|
|
array(
|
|
|
|
'check_forks' => true,
|
|
|
|
'check_composer' => true,
|
|
|
|
'check_upm' => true
|
|
|
|
)
|
|
|
|
);
|
2022-08-29 14:18:09 +03:00
|
|
|
gitea_check_repo($auth_token, $gitea_url, 'bit/skeletor-rnd',
|
2022-08-29 10:58:15 +03:00
|
|
|
array(
|
|
|
|
'check_forks' => true,
|
|
|
|
'check_composer' => true,
|
|
|
|
'check_upm' => true
|
|
|
|
)
|
|
|
|
);
|
2022-08-29 14:18:09 +03:00
|
|
|
gitea_check_repo($auth_token, $gitea_url, 'game/gymmania',
|
|
|
|
array(
|
|
|
|
'check_forks' => false,
|
|
|
|
'check_composer' => true,
|
|
|
|
'check_upm' => false
|
|
|
|
)
|
|
|
|
);
|
2022-08-26 15:36:01 +03:00
|
|
|
//////////////////////////////////
|
|
|
|
|
|
|
|
function gitea_login($gitea_url, $user, $pass)
|
|
|
|
{
|
|
|
|
$token_field = "test_".time();
|
|
|
|
$ch = curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_URL, "https://git.bit5.ru/api/v1/users/$user/tokens");
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
|
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array("name" => $token_field)));
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
|
|
|
curl_setopt($ch, CURLOPT_USERPWD, $user . ":" . $pass);
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
|
|
$json = curl_exec($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
|
|
|
|
$res = json_decode($json, true);
|
|
|
|
if(!isset($res['sha1']))
|
|
|
|
throw new Exception("Could not login to gitea");
|
|
|
|
|
|
|
|
return $res['sha1'];
|
|
|
|
}
|
|
|
|
|
|
|
|
function gitea_api_call($auth_token, $gitea_url, $api_path)
|
|
|
|
{
|
|
|
|
$api_url = "$gitea_url/api/v1/$api_path";
|
|
|
|
$ch = curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $api_url);
|
|
|
|
curl_setopt($ch, CURLOPT_HEADER, true);
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER,
|
|
|
|
array(
|
|
|
|
'Accept: application/json',
|
|
|
|
"Authorization: token $auth_token"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
|
|
$response = curl_exec($ch);
|
|
|
|
|
|
|
|
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
|
|
|
$header = substr($response, 0, $header_size);
|
|
|
|
$json = substr($response, $header_size);
|
|
|
|
|
|
|
|
$info = curl_getinfo($ch);
|
|
|
|
|
|
|
|
curl_close($ch);
|
|
|
|
|
|
|
|
if($info['http_code'] != 200)
|
|
|
|
return $info['http_code'];
|
|
|
|
|
|
|
|
return json_decode($json, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function gitea_get_tags($auth_token, $gitea_url, $repo)
|
|
|
|
{
|
|
|
|
$res = gitea_api_call($auth_token, $gitea_url, "repos/$repo/tags");
|
|
|
|
if($res === 404)
|
|
|
|
return array();
|
|
|
|
else if(is_numeric($res))
|
|
|
|
throw new Exception("Bad response: $res");
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
function gitea_get_source($auth_token, $gitea_url, $repo, $path)
|
|
|
|
{
|
|
|
|
$res = gitea_api_call($auth_token, $gitea_url, "repos/$repo/contents/$path");
|
|
|
|
|
|
|
|
if(is_numeric($res))
|
|
|
|
throw new Exception("Bad response: $res");
|
|
|
|
|
|
|
|
if(!isset($res['content']))
|
|
|
|
throw new Exception("Could not get file at path '$path'");
|
|
|
|
|
|
|
|
return base64_decode($res['content']);
|
|
|
|
}
|
|
|
|
|
|
|
|
function gitea_get_forks($auth_token, $gitea_url, $repo)
|
|
|
|
{
|
|
|
|
$res = gitea_api_call($auth_token, $gitea_url, "repos/$repo/forks");
|
|
|
|
if(is_numeric($res))
|
|
|
|
throw new Exception("Bad response: $res");
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
function gitea_get_commits($auth_token, $gitea_url, $repo)
|
|
|
|
{
|
|
|
|
$res = gitea_api_call($auth_token, $gitea_url, "repos/$repo/commits");
|
|
|
|
if(is_numeric($res))
|
|
|
|
throw new Exception("Bad response: $res");
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
function gitea_get_commit($auth_token, $gitea_url, $repo, $sha)
|
|
|
|
{
|
|
|
|
$res = gitea_api_call($auth_token, $gitea_url, "repos/$repo/git/commits/$sha");
|
|
|
|
if($res === 404)
|
|
|
|
return null;
|
|
|
|
else if(is_numeric($res))
|
|
|
|
throw new Exception("Bad response: $res");
|
|
|
|
else
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _is_composer_git_repo(array $repos, $repo)
|
|
|
|
{
|
|
|
|
foreach($repos as $item)
|
|
|
|
{
|
|
|
|
if($item['type'] == 'git' && $item['url'] == $repo)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-29 14:18:09 +03:00
|
|
|
function gitea_check_repo(
|
2022-08-29 10:58:15 +03:00
|
|
|
$auth_token,
|
|
|
|
$gitea_url,
|
|
|
|
$base_repo,
|
|
|
|
array $opts
|
|
|
|
)
|
2022-08-26 15:36:01 +03:00
|
|
|
{
|
2022-08-29 14:18:09 +03:00
|
|
|
echo "************************* Checking repo '$base_repo' *************************\n";
|
2022-08-26 15:36:01 +03:00
|
|
|
|
|
|
|
$commits = gitea_get_commits($auth_token, $gitea_url, $base_repo);
|
|
|
|
|
2022-08-29 10:58:15 +03:00
|
|
|
if($opts['check_forks'])
|
2022-08-26 15:36:01 +03:00
|
|
|
{
|
2022-08-29 10:58:15 +03:00
|
|
|
$forks = gitea_get_forks($auth_token, $gitea_url, $base_repo);
|
2022-08-29 14:18:09 +03:00
|
|
|
$behind_forks = array();
|
2022-08-29 10:58:15 +03:00
|
|
|
echo "== Checking forks ==\n";
|
|
|
|
foreach($forks as $fork)
|
2022-08-26 15:36:01 +03:00
|
|
|
{
|
2022-08-29 10:58:15 +03:00
|
|
|
$repo_fork = $fork['full_name'];
|
|
|
|
foreach($commits as $commit)
|
2022-08-26 15:36:01 +03:00
|
|
|
{
|
2022-08-29 10:58:15 +03:00
|
|
|
$status = gitea_get_commit($auth_token, $gitea_url, $repo_fork, $commit['sha']);
|
|
|
|
if($status === null)
|
|
|
|
{
|
2022-08-29 14:18:09 +03:00
|
|
|
$behind_forks[] = $repo_fork;
|
2022-08-29 10:58:15 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
//early exit if commit exists
|
|
|
|
else if(isset($status['sha']))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2022-08-26 15:36:01 +03:00
|
|
|
}
|
|
|
|
}
|
2022-08-29 14:18:09 +03:00
|
|
|
echo "Behind forks: " . implode(", ", $behind_forks) . "\n";
|
2022-08-26 15:36:01 +03:00
|
|
|
}
|
|
|
|
|
2022-08-29 10:58:15 +03:00
|
|
|
if($opts['check_composer'])
|
2022-08-26 15:36:01 +03:00
|
|
|
{
|
2022-08-29 10:58:15 +03:00
|
|
|
echo "== Checking Composer manifest ==\n";
|
|
|
|
$composer_json = gitea_get_source($auth_token, $gitea_url, $base_repo, "composer/composer.json");
|
|
|
|
$composer_arr = json_decode($composer_json, true);
|
2022-08-26 15:36:01 +03:00
|
|
|
|
2022-08-29 10:58:15 +03:00
|
|
|
foreach($composer_arr['require'] as $repo => $version)
|
2022-08-26 15:36:01 +03:00
|
|
|
{
|
2022-08-29 10:58:15 +03:00
|
|
|
if(strpos($repo, "bit/") !== 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(!_is_composer_git_repo($composer_arr['repositories'], "$gitea_url/$repo"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
$tags = gitea_get_tags($auth_token, $gitea_url, $repo);
|
|
|
|
if(isset($tags[0]))
|
|
|
|
{
|
|
|
|
$last_tag_info = $tags[0];
|
|
|
|
if(ltrim($last_tag_info["name"], 'v') != ltrim($version, 'v'))
|
2022-08-29 14:18:09 +03:00
|
|
|
echo "Package '$repo': current $version, latest {$last_tag_info["name"]}\n";
|
2022-08-29 10:58:15 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
echo "Could not fetch tags for $repo\n";
|
2022-08-26 15:36:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-29 10:58:15 +03:00
|
|
|
if($opts['check_upm'])
|
2022-08-26 15:36:01 +03:00
|
|
|
{
|
|
|
|
echo "== Checking UPM manifest ==\n";
|
|
|
|
$upm_json = gitea_get_source($auth_token, $gitea_url, $base_repo, "unity/Packages/manifest.json");
|
|
|
|
$upm_arr = json_decode($upm_json, true);
|
|
|
|
|
|
|
|
foreach($upm_arr['dependencies'] as $name => $version)
|
|
|
|
{
|
|
|
|
if(strpos($name, "com.bitgames.") !== 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
$name = str_replace("com.bitgames.ecs", "com.bitgames.leoecs", $name);
|
|
|
|
$name = str_replace("com.bitgames.", "", $name);
|
|
|
|
$name = str_replace(".", "-", $name);
|
|
|
|
$repo = 'bit-upm/' . $name;
|
|
|
|
|
|
|
|
$tags = gitea_get_tags($auth_token, $gitea_url, $repo);
|
|
|
|
if(isset($tags[0]))
|
|
|
|
{
|
|
|
|
$last_tag_info = $tags[0];
|
|
|
|
if(ltrim($last_tag_info["name"], 'v') != ltrim($version, 'v'))
|
2022-08-29 14:18:09 +03:00
|
|
|
echo "Package '$repo': current $version, latest {$last_tag_info["name"]}\n";
|
2022-08-26 15:36:01 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
echo "Could not fetch tags for $repo\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|