-
Notifications
You must be signed in to change notification settings - Fork 242
/
build_publish.php
69 lines (56 loc) · 2.31 KB
/
build_publish.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
$client = new Client([
'base_uri' => 'https://api.github.com',
'headers' => [
'Authorization' => 'Bearer '.getenv('GITHUB_TOKEN'),
'Accept' => 'application/vnd.github+json',
'X-GitHub-Api-Version' => '2022-11-28'
]
]);
$latest = $client->get('repos/Fndroid/clash_for_windows_pkg/releases/latest');
$latest = json_decode($latest->getBody()->getContents(), true);
try {
$own_repo = $client->get('repos/lantongxue/clash_for_windows_pkg/releases/tags/'.$latest['tag_name']);
$own_repo = json_decode($own_repo->getBody()->getContents(), true);
if($own_repo['tag_name'] === $latest['tag_name']) {
echo $latest['tag_name'].' this version was packaged and published';exit;
}
} catch (ClientException $exception) {
echo $exception->getResponse()->getBody()->getContents();
}
$release = $client->post('repos/lantongxue/clash_for_windows_pkg/releases', [
'json' => [
'tag_name' => $latest['tag_name'],
'name' => $latest['name'],
'body' => $latest['body'],
'draft' => false,
'prerelease' => false,
'make_latest' => 'true',
]
]);
$release = json_decode($release->getBody()->getContents(), true);
foreach($latest['assets'] as $asset) {
if(stripos($asset['name'], '-x64-linux.tar.gz') === false) {
continue;
}
$base_name = str_replace('.tar.gz', '', $asset['name']);
system('wget '.$asset['browser_download_url']);
system('tar -zxvf '.$asset['name'].' -C clash_for_windows/opt/clash_for_windows'.' "Clash for Windows-'.$latest['tag_name'].'-x64-linux/"'. ' --strip-components 1');
$control = str_replace('{{$Version}}', $latest['tag_name'], file_get_contents('clash_for_windows/DEBIAN/control'));
file_put_contents('clash_for_windows/DEBIAN/control', $control);
$deb_name = $base_name.'.deb';
system('dpkg-deb -b clash_for_windows/'.' '.$deb_name);
$client->post('https://uploads.github.com/repos/lantongxue/clash_for_windows_pkg/releases/'.$release['id'].'/assets', [
'headers' => [
'Content-Type' => 'application/octet-stream',
],
'query' => [
'name' => $deb_name,
],
'body' => fopen($deb_name, 'r'),
]);
}
echo 'ok'.PHP_EOL;