Skip to content

Commit 5b5861c

Browse files
authored
Let ghtar always use latest version by default & mongodb bugfix (crazywhalecc#1125)
2 parents abfdae2 + 7a71a40 commit 5b5861c

5 files changed

Lines changed: 64 additions & 26 deletions

File tree

config/source.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,6 @@
11941194
"path": "php-src/ext/swoole",
11951195
"type": "ghtar",
11961196
"repo": "swoole/swoole-src",
1197-
"match": "v6\\.+",
11981197
"prefer-stable": true,
11991198
"license": {
12001199
"type": "file",

src/SPC/builder/extension/mongodb.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,22 @@
55
namespace SPC\builder\extension;
66

77
use SPC\builder\Extension;
8+
use SPC\store\FileSystem;
89
use SPC\util\CustomExt;
910

1011
#[CustomExt('mongodb')]
1112
class mongodb extends Extension
1213
{
14+
public function patchBeforeBuildconf(): bool
15+
{
16+
FileSystem::replaceFileRegex(
17+
SOURCE_PATH . '/php-src/ext/mongodb/config.m4',
18+
'/^(\s+)(src\/libmongoc\/)/m',
19+
'$1${ac_config_dir}/$2'
20+
);
21+
return true;
22+
}
23+
1324
public function getUnixConfigureArg(bool $shared = false): string
1425
{
1526
$arg = ' --enable-mongodb' . ($shared ? '=shared' : '') . ' ';

src/SPC/store/Downloader.php

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -98,32 +98,51 @@ public static function getLatestGithubTarball(string $name, array $source, strin
9898
{
9999
logger()->debug("finding {$name} source from github {$type} tarball");
100100
$source['query'] ??= '';
101-
$data = json_decode(self::curlExec(
102-
url: "https://api.github.com/repos/{$source['repo']}/{$type}{$source['query']}",
103-
hooks: [[CurlHook::class, 'setupGithubToken']],
104-
retries: self::getRetryAttempts()
105-
), true, 512, JSON_THROW_ON_ERROR);
106101

107-
$url = null;
108-
foreach ($data as $rel) {
109-
if (($rel['prerelease'] ?? false) === true && ($source['prefer-stable'] ?? false)) {
110-
continue;
111-
}
112-
if (($rel['draft'] ?? false) === true && (($source['prefer-stable'] ?? false) || !$rel['tarball_url'])) {
113-
continue;
102+
// Use /releases/latest when possible: it returns the semantically latest stable
103+
// release regardless of publish order, avoiding issues with concurrent release branches.
104+
if ($type === 'releases' && empty($source['query']) && !($source['match'] ?? null)) {
105+
$data = json_decode(self::curlExec(
106+
url: "https://api.github.com/repos/{$source['repo']}/releases/latest",
107+
hooks: [[CurlHook::class, 'setupGithubToken']],
108+
retries: self::getRetryAttempts()
109+
), true, 512, JSON_THROW_ON_ERROR);
110+
if (!is_array($data) || empty($data['tarball_url'])) {
111+
throw new DownloaderException("failed to find {$name} source");
114112
}
115-
if (!($source['match'] ?? null)) {
116-
$url = $rel['tarball_url'] ?? null;
117-
break;
113+
$url = $data['tarball_url'];
114+
$version = $data['tag_name'] ?? $data['name'] ?? null;
115+
} else {
116+
$data = json_decode(self::curlExec(
117+
url: "https://api.github.com/repos/{$source['repo']}/{$type}{$source['query']}",
118+
hooks: [[CurlHook::class, 'setupGithubToken']],
119+
retries: self::getRetryAttempts()
120+
), true, 512, JSON_THROW_ON_ERROR);
121+
122+
$url = null;
123+
$version = null;
124+
foreach ($data as $rel) {
125+
if (($rel['prerelease'] ?? false) === true && ($source['prefer-stable'] ?? false)) {
126+
continue;
127+
}
128+
if (($rel['draft'] ?? false) === true && (($source['prefer-stable'] ?? false) || !$rel['tarball_url'])) {
129+
continue;
130+
}
131+
if (!($source['match'] ?? null)) {
132+
$url = $rel['tarball_url'] ?? null;
133+
$version = $rel['tag_name'] ?? $rel['name'] ?? null;
134+
break;
135+
}
136+
if (preg_match('|' . $source['match'] . '|', $rel['tarball_url'])) {
137+
$url = $rel['tarball_url'];
138+
$version = $rel['tag_name'] ?? $rel['name'] ?? null;
139+
break;
140+
}
118141
}
119-
if (preg_match('|' . $source['match'] . '|', $rel['tarball_url'])) {
120-
$url = $rel['tarball_url'];
121-
break;
142+
if (!$url) {
143+
throw new DownloaderException("failed to find {$name} source");
122144
}
123145
}
124-
if (!$url) {
125-
throw new DownloaderException("failed to find {$name} source");
126-
}
127146
$headers = self::curlExec(
128147
url: $url,
129148
method: 'HEAD',
@@ -134,7 +153,7 @@ public static function getLatestGithubTarball(string $name, array $source, strin
134153
if ($matches) {
135154
$filename = $matches['filename'];
136155
} else {
137-
$filename = "{$name}-" . ($type === 'releases' ? $data['tag_name'] : $data['name']) . '.tar.gz';
156+
$filename = "{$name}-" . ($version ?? 'latest') . '.tar.gz';
138157
}
139158

140159
return [$url, $filename];

src/globals/test-extensions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// test php version (8.1 ~ 8.4 available, multiple for matrix)
1515
$test_php_version = [
1616
// '8.1',
17-
// '8.2',
17+
'8.2',
1818
// '8.3',
1919
// '8.4',
2020
'8.5',
@@ -50,7 +50,7 @@
5050

5151
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
5252
$extensions = match (PHP_OS_FAMILY) {
53-
'Linux', 'Darwin' => 'gd,imagick',
53+
'Linux', 'Darwin' => 'swoole,mongodb',
5454
'Windows' => 'bcmath,brotli,bz2,ctype,curl,dom,exif,fileinfo,filter,ftp,gd,iconv,intl,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pdo,pdo_mysql,pdo_pgsql,pgsql,session,simdjson,simplexml,sodium,sqlite3,tokenizer,xml,xmlreader,xmlwriter,zip,zlib',
5555
};
5656

@@ -66,7 +66,7 @@
6666

6767
// If you want to test extra libs for extensions, add them below (comma separated, example `libwebp,libavif`). Unnecessary, when $with_suggested_libs is true.
6868
$with_libs = match (PHP_OS_FAMILY) {
69-
'Linux', 'Darwin' => 'libde265',
69+
'Linux', 'Darwin' => '',
7070
'Windows' => '',
7171
};
7272

tests/mock/SPC_store.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
function f_exec(string $command, mixed &$output, mixed &$result_code): bool
1313
{
1414
$result_code = 0;
15+
if (str_contains($command, 'https://api.github.com/repos/AOMediaCodec/libavif/releases/latest')) {
16+
$output = explode("\n", json_encode([
17+
'tag_name' => 'v1.1.1',
18+
'tarball_url' => 'https://api.github.com/repos/AOMediaCodec/libavif/tarball/v1.1.1',
19+
'prerelease' => false,
20+
'draft' => false,
21+
]));
22+
return true;
23+
}
1524
if (str_contains($command, 'https://api.github.com/repos/AOMediaCodec/libavif/releases')) {
1625
$output = explode("\n", gzdecode(file_get_contents(__DIR__ . '/../assets/github_api_AOMediaCodec_libavif_releases.json.gz')));
1726
return true;

0 commit comments

Comments
 (0)